diff options
author | Nico Huber <nico.huber@secunet.com> | 2013-06-14 15:26:49 +0200 |
---|---|---|
committer | Nico Huber <nico.h@gmx.de> | 2013-09-06 11:28:47 +0200 |
commit | 2d4b4cafe62b43815806fa7145e647f9daca0d38 (patch) | |
tree | 93fec6654f92c34938dcf9cd6ff4cb0612a0c1c4 /payloads/libpayload/libc/malloc.c | |
parent | 0306b502804ead6f56ad9dee814d0bc5062870f7 (diff) |
libpayload: Make heap code independent of its header size
Signed-off-by: Patrick Georgi <patrick.georgi@secunet.com>
Change-Id: Ie69ceb343494b7dd309847b7d606cb47925f68b6
Reviewed-on: http://review.coreboot.org/3888
Tested-by: build bot (Jenkins)
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Diffstat (limited to 'payloads/libpayload/libc/malloc.c')
-rw-r--r-- | payloads/libpayload/libc/malloc.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/payloads/libpayload/libc/malloc.c b/payloads/libpayload/libc/malloc.c index 7756a3bc49..c03cc737fa 100644 --- a/payloads/libpayload/libc/malloc.c +++ b/payloads/libpayload/libc/malloc.c @@ -51,11 +51,12 @@ static void *hstart = (void *)&_heap; static void *hend = (void *)&_eheap; typedef unsigned int hdrtype_t; +#define HDRSIZE (sizeof(hdrtype_t)) -#define MAGIC (0x2a << 26) -#define FLAG_FREE (1 << 25) -#define SIZE_BITS 25 -#define MAX_SIZE ((1 << SIZE_BITS) - 1) +#define SIZE_BITS ((HDRSIZE << 3) - 7) +#define MAGIC (((hdrtype_t)0x2a) << (SIZE_BITS + 1)) +#define FLAG_FREE (((hdrtype_t)0x01) << (SIZE_BITS + 0)) +#define MAX_SIZE ((((hdrtype_t)0x01) << SIZE_BITS) - 1) #define SIZE(_h) ((_h) & MAX_SIZE) @@ -64,8 +65,6 @@ typedef unsigned int hdrtype_t; #define FREE_BLOCK(_s) _HEADER(_s, FLAG_FREE) #define USED_BLOCK(_s) _HEADER(_s, 0) -#define HDRSIZE (sizeof(hdrtype_t)) - #define IS_FREE(_h) (((_h) & (MAGIC | FLAG_FREE)) == (MAGIC | FLAG_FREE)) #define HAS_MAGIC(_h) (((_h) & MAGIC) == MAGIC) @@ -93,7 +92,7 @@ static void *alloc(int len) hdrtype_t volatile *ptr = (hdrtype_t volatile *) hstart; /* Align the size. */ - len = (len + 3) & ~3; + len = (len + HDRSIZE - 1) & ~(HDRSIZE - 1); if (!len || len > MAX_SIZE) return (void *)NULL; |