From: John Hodge Date: Wed, 1 Aug 2012 13:33:32 +0000 (+0800) Subject: Usermode - heap debugging and memmove speedup X-Git-Tag: rel0.15~706^2~80 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=c275e76e346b3996829cf1d66ddd488daab35a30;p=tpg%2Facess2.git Usermode - heap debugging and memmove speedup --- diff --git a/Usermode/Libraries/libc.so_src/heap.c b/Usermode/Libraries/libc.so_src/heap.c index 7541abc1..779b0048 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; } @@ -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_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 ); + } +} + diff --git a/Usermode/Libraries/libc.so_src/string.c b/Usermode/Libraries/libc.so_src/string.c index e9e15741..3cadee90 100644 --- a/Usermode/Libraries/libc.so_src/string.c +++ b/Usermode/Libraries/libc.so_src/string.c @@ -273,10 +273,11 @@ EXPORT void *memmove(void *dest, const void *src, size_t count) char *sp = (char *)src; char *dp = (char *)dest; // Check if the areas overlap - if( (intptr_t)dest > (intptr_t)src && (intptr_t)dest < (intptr_t)src+count ) - for(;count--;) dp[count] = sp[count]; + if( (intptr_t)src < (intptr_t)dest && (intptr_t)dest < (intptr_t)src+count ) + for(;count--;) + dp[count] = sp[count]; else - for(;count--;) *dp++ = *sp++; + memcpy(dest, src, count); return dest; }