summaryrefslogtreecommitdiff
path: root/libddekit
diff options
context:
space:
mode:
authorZheng Da <zhengda1936@gmail.com>2009-11-17 10:41:42 +0100
committerZheng Da <zhengda1936@gmail.com>2009-11-17 10:41:42 +0100
commit2307c7487acde8295b462895b6625cd7f02b1abd (patch)
tree148b9f1057beaf8822940b55491be3355adc7ccd /libddekit
parent4ab9cd3868caba54bda4c5e1b8b3f79880c1dcd6 (diff)
We simply use malloc and free.
Maybe I can just use macros to replace ddekit_simple_malloc ddekit_simple_free.
Diffstat (limited to 'libddekit')
-rw-r--r--libddekit/malloc.c82
1 files changed, 17 insertions, 65 deletions
diff --git a/libddekit/malloc.c b/libddekit/malloc.c
index 5f0ae0fc..c3735bdb 100644
--- a/libddekit/malloc.c
+++ b/libddekit/malloc.c
@@ -1,36 +1,22 @@
-/*
- * \brief Simple allocator implementation
- * \author Christian Helmuth
- * \date 2006-10-30
- *
- * This simple allocator provides malloc() and free() using dm_mem dataspaces
- * as backing store. The actual list-based allocator implementation is from
- * l4util resp. Fiasco.
- *
- * For large allocations and slab-based OS-specific allocators
- * ddekit_large_malloc and ddekit_slab_*() should be used. The blocks
- * allocated via this allocator CANNOT be used for DMA or other device
- * operations, i.e., there exists no virt->phys mapping.
- *
- * FIXME check thread-safety and add locks where appropriate
- */
-
-#include <l4/dde/ddekit/memory.h>
-#include <l4/dde/ddekit/printf.h>
-#include <l4/dde/ddekit/panic.h>
+/*
+ Copyright (C) 2009 Free Software Foundation, Inc.
+ Written by Zheng Da.
-#include <l4/sys/consts.h>
-#include <l4/util/list_alloc.h>
-#include <l4/dm_mem/dm_mem.h>
-#include <l4/lock/lock.h>
+ This file is part of the GNU Hurd.
-/* configuration */
-#define ALLOC_SIZE (4 * L4_PAGESIZE)
+ The GNU Hurd is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
-/* malloc pool is a list allocator */
-static l4la_free_t *malloc_pool;
-static l4lock_t malloc_lock = L4LOCK_UNLOCKED;
+ The GNU Hurd is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+ You should have received a copy of the GNU General Public License
+ along with the GNU Hurd; see the file COPYING. If not, write to
+ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/**
* Allocate memory block via simple allocator
@@ -45,37 +31,7 @@ static l4lock_t malloc_lock = L4LOCK_UNLOCKED;
*/
void *ddekit_simple_malloc(unsigned size)
{
- l4lock_lock(&malloc_lock);
- /* we store chunk size in the first word of the chunk */
- size += sizeof(unsigned);
-
- /* try to allocate */
- unsigned *p = l4la_alloc(&malloc_pool, size, 0);
-
- /* fill pool if allocation fails */
- if (!p) {
- /* size of allocated dataspace is at least ALLOC_SIZE */
- unsigned ds_size = l4_round_page(size);
- ds_size = (ds_size > ALLOC_SIZE) ? ds_size : ALLOC_SIZE;
-
- void *res = l4dm_mem_allocate_named(ds_size, L4RM_MAP, "ddekit malloc");
- if (!res)
- p = NULL;
- else
- {
- l4la_free(&malloc_pool, res, ds_size);
- p = l4la_alloc(&malloc_pool, size, 0);
- }
- }
-
- /* store chunk size */
- if (p) {
- *p = size;
- p++;
- }
-
- l4lock_unlock(&malloc_lock);
- return p;
+ return malloc (size);
}
@@ -86,9 +42,5 @@ void *ddekit_simple_malloc(unsigned size)
*/
void ddekit_simple_free(void *p)
{
- l4lock_lock(&malloc_lock);
- unsigned *chunk = (unsigned *)p - 1;
- if (p)
- l4la_free(&malloc_pool, chunk, *chunk);
- l4lock_unlock(&malloc_lock);
+ free (p);
}