Code: Select all
typedef struct {
size_t size;
void *next;
uint8_t isfree;
} block_meta_t;
So, my malloc() function is simple as well:
Code: Select all
block_meta_t **malloc_last = NULL, **malloc_first = NULL; // Most recently malloc'd block and first malloc'd block
void *malloc(size_t sz) {
if (sz) {
sz = __2pow_rndup(sz); // Round up to the nearest power of two
block_meta_t *previous = *malloc_last, *ptr = extend_heap(sz);
if (!ptr)
goto returning_null;
if (malloc_last)
*malloc_last = previous->next = ptr;
else
*malloc_first = *malloc_last = ptr;
ptr->size = sz;
ptr->next = NULL;
ptr->isfree = 0;
return ptr+1;
}
returning_null:
return NULL;
}
So yeah... I'm really not sure exactly what's happening. Since I'm using Pure64, the memory is already mapped (but I'm not sure how much exactly), but I don't think that's the issue, seeing as that would just give me a page fault (I do have ISRs enabled and working).
If you need my extend_heap() function, I'll be happy to provide it. Thanks!
Thank you in advance!