Usermode - heap debugging and memmove speedup
authorJohn Hodge <[email protected]>
Wed, 1 Aug 2012 13:33:32 +0000 (21:33 +0800)
committerJohn Hodge <[email protected]>
Wed, 1 Aug 2012 13:33:32 +0000 (21:33 +0800)
Usermode/Libraries/libc.so_src/heap.c
Usermode/Libraries/libc.so_src/string.c

index 7541abc..779b004 100644 (file)
@@ -45,6 +45,7 @@ EXPORT void   *sbrk(int increment);
 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
@@ -91,6 +92,7 @@ EXPORT void *malloc(size_t bytes)
                else if(curBlock->magic != MAGIC)\r
                {\r
                        //Corrupt Heap\r
+                       Heap_Dump();\r
                        _SysDebug("malloc: Corrupt Heap\n");\r
                        return NULL;\r
                }\r
@@ -442,3 +444,25 @@ LOCAL uint brk(uintptr_t newpos)
        \r
        return ret;     // Return old curpos\r
 }\r
+\r
+void Heap_Dump(void)\r
+{\r
+       heap_head *cur = _heap_start;\r
+       while( cur < _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
index e9e1574..3cadee9 100644 (file)
@@ -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;
 }
 

UCC git Repository :: git.ucc.asn.au