LOCAL void *extendHeap(int bytes);\r
static void *FindHeapBase();\r
LOCAL uint brk(uintptr_t newpos);\r
+LOCAL void Heap_Dump(void);\r
\r
//Code\r
\r
else if(curBlock->magic != MAGIC)\r
{\r
//Corrupt Heap\r
+ Heap_Dump();\r
_SysDebug("malloc: Corrupt Heap\n");\r
return NULL;\r
}\r
DEBUGS("free(%p) : 0x%x bytes", mem, head->size);\r
\r
//Unify Right\r
- if((intptr_t)head + head->size < (intptr_t)_heap_end)\r
+ if((uintptr_t)head + head->size < (uintptr_t)_heap_end)\r
{\r
heap_head *nextHead = (heap_head*)((intptr_t)head + head->size);\r
if(nextHead->magic == MAGIC_FREE) { //Is the next block free\r
}\r
}\r
//Unify Left\r
- if((intptr_t)head - sizeof(heap_foot) > (intptr_t)_heap_start)\r
+ if((uintptr_t)head - sizeof(heap_foot) > (uintptr_t)_heap_start)\r
{\r
heap_head *prevHead;\r
heap_foot *prevFoot = (heap_foot *)((intptr_t)head - sizeof(heap_foot));\r
\r
return ret; // Return old curpos\r
}\r
+\r
+void Heap_Dump(void)\r
+{\r
+ heap_head *cur = _heap_start;\r
+ while( cur < (heap_head*)_heap_end )\r
+ {\r
+ switch( cur->magic )\r
+ {\r
+ case MAGIC:\r
+ _SysDebug("Used block %p[0x%x] - ptr=%p", cur, cur->size, cur->data);\r
+ break;\r
+ case MAGIC_FREE:\r
+ _SysDebug("Free block %p[0x%x] - ptr=%p", cur, cur->size, cur->data);\r
+ break;\r
+ default:\r
+ _SysDebug("Block %p bad magic (0x%x)", cur, cur->magic);\r
+ return ;\r
+ }\r
+ cur = (void*)( (char*)cur + cur->size );\r
+ }\r
+}\r
+\r