2 * libc/stdlib/malloc/heap_alloc_at.c -- allocate at a specific address
4 * Copyright (C) 2002 NEC Corporation
5 * Copyright (C) 2002 Miles Bader <miles@gnu.org>
7 * This file is subject to the terms and conditions of the GNU Lesser
8 * General Public License. See the file COPYING.LIB in the main
9 * directory of this archive for more details.
11 * Written by Miles Bader <miles@gnu.org>
19 /* Allocate SIZE bytes at address MEM in HEAP. Return the actual size
20 allocated, or 0 if we failed. */
22 __heap_alloc_at (struct heap_free_area **heap, void *mem, size_t size)
24 struct heap_free_area *fa;
27 size = HEAP_ADJUST_SIZE (size);
29 HEAP_DEBUG (*heap, "before __heap_alloc_at");
31 /* Look for a free area that can contain SIZE bytes. */
32 for (fa = *heap; fa; fa = fa->next)
34 void *fa_mem = HEAP_FREE_AREA_START (fa);
37 if (fa_mem == mem && fa->size >= size)
38 /* FA has the right addr, and is big enough! */
39 alloced = __heap_free_area_alloc (heap, fa, size);
44 HEAP_DEBUG (*heap, "after __heap_alloc_at");