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(). Change the pointer type to volatile
and now pass it to the setup() function. Also clean 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@se-eng.com>
Reviewed-on: http://review.coreboot.org/705
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <patrick@georgi-clan.de>
static int minimal_free = 0;
#endif
static int minimal_free = 0;
#endif
+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;
#ifdef CONFIG_DEBUG_MALLOC
heap_initialized = 1;
static void *alloc(int len)
{
hdrtype_t header;
static void *alloc(int len)
{
hdrtype_t header;
+ hdrtype_t volatile *ptr = (hdrtype_t volatile *) hstart;
/* Align the size. */
len = (len + 3) & ~3;
/* Align the size. */
len = (len + 3) & ~3;
return (void *)NULL;
/* Make sure the region is setup correctly. */
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 {
/* Find some free space. */
do {
- header = *((hdrtype_t *) ptr);
int size = SIZE(header);
if (!HAS_MAGIC(header) || size == 0) {
int size = SIZE(header);
if (!HAS_MAGIC(header) || size == 0) {
if (header & FLAG_FREE) {
if (len <= size) {
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,
int nsize = size - (HDRSIZE + len);
/* If there is still room in this block,
if (nsize > 0) {
/* Mark the block as used. */
if (nsize > 0) {
/* Mark the block as used. */
- *((hdrtype_t *) ptr) = USED_BLOCK(len);
+ *ptr = USED_BLOCK(len);
/* Create a new free block. */
/* Create a new free block. */
- *((hdrtype_t *) nptr) =
- FREE_BLOCK(nsize);
+ *nptr = FREE_BLOCK(nsize);
} else {
/* Mark the block as used. */
} else {
/* Mark the block as used. */
- *((hdrtype_t *) ptr) = USED_BLOCK(size);
+ *ptr = USED_BLOCK(size);
}
return (void *)(ptr + HDRSIZE);
}
return (void *)(ptr + HDRSIZE);
+ } while (ptr < (hdrtype_t *) hend);
/* Nothing available. */
return (void *)NULL;
/* Nothing available. */
return (void *)NULL;