+\r
+int Heap_Validate(int bDump)\r
+{\r
+ int rv = 0;\r
+ heap_head *cur = _heap_start;\r
+ while( cur < (heap_head*)_heap_end && rv == 0 )\r
+ {\r
+ if( cur->magic == MAGIC ) {\r
+ if( bDump ) {\r
+ _SysDebug("Used block %p[0x%x] - ptr=%p,Owner=%p,Size=0x%x",\r
+ cur, cur->size, cur->data,\r
+ cur->Caller, cur->RealSize\r
+ );\r
+ }\r
+ }\r
+ else if( cur->magic == MAGIC_FREE ) {\r
+ if( bDump ) {\r
+ _SysDebug("Free block %p[0x%x]", cur, cur->size, cur->data);\r
+ }\r
+ }\r
+ else {\r
+ _SysDebug("Block %p bad magic (0x%x)", cur, cur->magic);\r
+ rv = 1;\r
+ break ;\r
+ }\r
+ heap_foot *foot = THIS_FOOT(cur);\r
+ if( foot->magic != MAGIC ) {\r
+ _SysDebug("- %p: Foot magic clobbered (0x%x!=0x%x)", cur, foot->magic, MAGIC);\r
+ rv = 1;\r
+ }\r
+ if( foot->header != cur ) {\r
+ _SysDebug("- %p: Head pointer clobbered (%p)", cur, foot->header);\r
+ rv = 1;\r
+ }\r
+ \r
+ if( rv && !bDump ) {\r
+ _SysDebug("%s block %p[0x%x] - ptr=%p,Owner=%p,Size=0x%x",\r
+ (cur->magic == MAGIC ? "Used":"Free"),\r
+ cur, cur->size, cur->data,\r
+ cur->Caller, cur->RealSize\r
+ );\r
+ } \r
+ \r
+ cur = NEXT_HEAD(cur);\r
+ }\r
+ if( rv && !bDump ) {\r
+ _SysDebug("- Caller: %p", __builtin_return_address(0));\r
+ exit(1);\r
+ }\r
+ return 0;\r
+}\r
+\r