diff options
author | Miles Bader <miles@lsi.nec.co.jp> | 2002-07-30 09:20:31 +0000 |
---|---|---|
committer | Miles Bader <miles@lsi.nec.co.jp> | 2002-07-30 09:20:31 +0000 |
commit | ae96781efd37c63dda16175258480d9ad5919418 (patch) | |
tree | dcf74c2a3ad0258475285aed53d47232a4352106 /libc/stdlib/malloc/malloc.h | |
parent | fa7102ea2e7ea4ca964ec554e8c424f7bc6179bb (diff) |
Add macros to abstract the malloc header format a bit.
Diffstat (limited to 'libc/stdlib/malloc/malloc.h')
-rw-r--r-- | libc/stdlib/malloc/malloc.h | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/libc/stdlib/malloc/malloc.h b/libc/stdlib/malloc/malloc.h index f01484368..f08f4bf1b 100644 --- a/libc/stdlib/malloc/malloc.h +++ b/libc/stdlib/malloc/malloc.h @@ -7,7 +7,7 @@ * This file is subject to the terms and conditions of the GNU Lesser * General Public License. See the file COPYING.LIB in the main * directory of this archive for more details. - * + * * Written by Miles Bader <miles@gnu.org> */ @@ -42,6 +42,27 @@ #endif +/* The size of a malloc allocation is stored in a size_t word + MALLOC_ALIGNMENT bytes prior to the start address of the allocation: + + +--------+---------+-------------------+ + | SIZE |(unused) | allocation ... | + +--------+---------+-------------------+ + ^ BASE ^ ADDR + ^ ADDR - MALLOC_ALIGN +*/ + +/* Return base-address of a malloc allocation, given the user address. */ +#define MALLOC_BASE(addr) ((void *)((char *)addr - MALLOC_ALIGNMENT)) +/* Return the size of a malloc allocation, given the user address. */ +#define MALLOC_SIZE(addr) (*(size_t *)MALLOC_BASE(addr)) + +/* Return the user address of a malloc allocation, given the base address. */ +#define MALLOC_ADDR(base) ((void *)((char *)base + MALLOC_ALIGNMENT)) +/* Sets the size of a malloc allocation, given the base address. */ +#define MALLOC_SET_SIZE(base, size) (*(size_t *)(base) = (size)) + + #ifdef __UCLIBC_HAS_THREADS__ # include <pthread.h> |