[coreboot] New patch to review for coreboot: 37a6cac Make libpaylod alloc() memory pointers volatile
Marc Jones (marcj303@gmail.com)
gerrit at coreboot.org
Fri Mar 2 23:06:38 CET 2012
Marc Jones (marcj303 at gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/705
-gerrit
commit 37a6cacf4e04d0ee9e75f1b1c7ea307d750623c6
Author: Marc Jones <marc.jones at se-eng.com>
Date: Thu Mar 1 16:12:11 2012 -0700
Make libpaylod alloc() memory pointers volatile
gcc4.6.2 was optimizing the libpayload alloc() function and failing to
reload a pointer after the memory had been manipulated by a pointer in
the inlined function setup(). I changes the pointer type to volatile
and now pass it to the setup() function. I also cleaned up the
declaration so that it isn't cast a bunch times in the function.
Change-Id: I1637bd7bd5d9cf82ac88925cbfe76d319aa3cd82
Signed-off-by: Marc Jones <marc.jones at se-eng.com>
---
payloads/libpayload/libc/malloc.c | 25 +++++++++++--------------
1 files changed, 11 insertions(+), 14 deletions(-)
diff --git a/payloads/libpayload/libc/malloc.c b/payloads/libpayload/libc/malloc.c
index 6389fc9..9412cab 100644
--- a/payloads/libpayload/libc/malloc.c
+++ b/payloads/libpayload/libc/malloc.c
@@ -73,11 +73,9 @@ static int heap_initialized = 0;
static int minimal_free = 0;
#endif
-static void setup(void)
+static void setup(hdrtype_t volatile *start, int size)
{
- int size = (unsigned int)(&_eheap - &_heap) - HDRSIZE;
-
- *((hdrtype_t *) hstart) = FREE_BLOCK(size);
+ *start = FREE_BLOCK(size);
#ifdef CONFIG_DEBUG_MALLOC
heap_initialized = 1;
@@ -88,7 +86,7 @@ static void setup(void)
static void *alloc(int len)
{
hdrtype_t header;
- void *ptr = hstart;
+ hdrtype_t volatile *ptr = (hdrtype_t volatile *) hstart;
/* Align the size. */
len = (len + 3) & ~3;
@@ -97,12 +95,12 @@ static void *alloc(int len)
return (void *)NULL;
/* Make sure the region is setup correctly. */
- if (!HAS_MAGIC(*((hdrtype_t *) ptr)))
- setup();
+ if (!HAS_MAGIC(*ptr))
+ setup(ptr, len);
/* Find some free space. */
do {
- header = *((hdrtype_t *) ptr);
+ header = *ptr;
int size = SIZE(header);
if (!HAS_MAGIC(header) || size == 0) {
@@ -114,7 +112,7 @@ static void *alloc(int len)
if (header & FLAG_FREE) {
if (len <= size) {
- void *nptr = ptr + (HDRSIZE + len);
+ hdrtype_t volatile *nptr = ptr + (HDRSIZE + len);
int nsize = size - (HDRSIZE + len);
/* If there is still room in this block,
@@ -124,14 +122,13 @@ static void *alloc(int len)
if (nsize > 0) {
/* Mark the block as used. */
- *((hdrtype_t *) ptr) = USED_BLOCK(len);
+ *ptr = USED_BLOCK(len);
/* Create a new free block. */
- *((hdrtype_t *) nptr) =
- FREE_BLOCK(nsize);
+ *nptr = FREE_BLOCK(nsize);
} else {
/* Mark the block as used. */
- *((hdrtype_t *) ptr) = USED_BLOCK(size);
+ *ptr = USED_BLOCK(size);
}
return (void *)(ptr + HDRSIZE);
@@ -140,7 +137,7 @@ static void *alloc(int len)
ptr += HDRSIZE + size;
- } while (ptr < hend);
+ } while (ptr < (hdrtype_t *) hend);
/* Nothing available. */
return (void *)NULL;
More information about the coreboot
mailing list