From 2307c7487acde8295b462895b6625cd7f02b1abd Mon Sep 17 00:00:00 2001 From: Zheng Da Date: Tue, 17 Nov 2009 10:41:42 +0100 Subject: We simply use malloc and free. Maybe I can just use macros to replace ddekit_simple_malloc ddekit_simple_free. --- libddekit/malloc.c | 82 +++++++++++------------------------------------------- 1 file changed, 17 insertions(+), 65 deletions(-) (limited to 'libddekit') 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 -#include -#include +/* + Copyright (C) 2009 Free Software Foundation, Inc. + Written by Zheng Da. -#include -#include -#include -#include + 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); } -- cgit v1.2.3