X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FLibraries%2Flibc.so_src%2Fheap.c;h=bdf64de35fdc635674f8b91f55409dd401e17d3c;hb=479d0634670b58da044bc58149662adba0ad1d0b;hp=7541abc12f5df9a8ea1592807eda910b0b076683;hpb=0ca124ec02d184c9bd3736354b2ae7c51330ed1d;p=tpg%2Facess2.git diff --git a/Usermode/Libraries/libc.so_src/heap.c b/Usermode/Libraries/libc.so_src/heap.c index 7541abc1..bdf64de3 100644 --- a/Usermode/Libraries/libc.so_src/heap.c +++ b/Usermode/Libraries/libc.so_src/heap.c @@ -45,6 +45,7 @@ EXPORT void *sbrk(int increment); LOCAL void *extendHeap(int bytes); static void *FindHeapBase(); LOCAL uint brk(uintptr_t newpos); +LOCAL void Heap_Dump(void); //Code @@ -91,6 +92,7 @@ EXPORT void *malloc(size_t bytes) else if(curBlock->magic != MAGIC) { //Corrupt Heap + Heap_Dump(); _SysDebug("malloc: Corrupt Heap\n"); return NULL; } @@ -183,7 +185,7 @@ EXPORT void free(void *mem) DEBUGS("free(%p) : 0x%x bytes", mem, head->size); //Unify Right - if((intptr_t)head + head->size < (intptr_t)_heap_end) + if((uintptr_t)head + head->size < (uintptr_t)_heap_end) { heap_head *nextHead = (heap_head*)((intptr_t)head + head->size); if(nextHead->magic == MAGIC_FREE) { //Is the next block free @@ -192,7 +194,7 @@ EXPORT void free(void *mem) } } //Unify Left - if((intptr_t)head - sizeof(heap_foot) > (intptr_t)_heap_start) + if((uintptr_t)head - sizeof(heap_foot) > (uintptr_t)_heap_start) { heap_head *prevHead; heap_foot *prevFoot = (heap_foot *)((intptr_t)head - sizeof(heap_foot)); @@ -442,3 +444,25 @@ LOCAL uint brk(uintptr_t newpos) return ret; // Return old curpos } + +void Heap_Dump(void) +{ + heap_head *cur = _heap_start; + while( cur < (heap_head*)_heap_end ) + { + switch( cur->magic ) + { + case MAGIC: + _SysDebug("Used block %p[0x%x] - ptr=%p", cur, cur->size, cur->data); + break; + case MAGIC_FREE: + _SysDebug("Free block %p[0x%x] - ptr=%p", cur, cur->size, cur->data); + break; + default: + _SysDebug("Block %p bad magic (0x%x)", cur, cur->magic); + return ; + } + cur = (void*)( (char*)cur + cur->size ); + } +} +