if( (tVAddr)gHeapEnd == MM_KHEAP_MAX )
return NULL;
+ if( Bytes == 0 ) {
+ Log_Warning("Heap", "Heap_Extend called with Bytes=%i", Bytes);
+ return NULL;
+ }
+
// Bounds Check
if( (tVAddr)gHeapEnd + ((Bytes+0xFFF)&~0xFFF) > MM_KHEAP_MAX ) {
Bytes = MM_KHEAP_MAX - (tVAddr)gHeapEnd;
head->Magic = MAGIC_USED;
head->File = File;
head->Line = Line;
+ head->ValidSize = __Bytes;
Mutex_Release(&glHeap); // Release spinlock
#if DEBUG_TRACE
Log("[Heap ] Malloc'd %p (%i bytes), returning to %p", head->Data, head->Size, __builtin_return_address(0));
best->Magic = MAGIC_USED; // Mark block as used
best->File = File;
best->Line = Line;
+ head->ValidSize = __Bytes;
Mutex_Release(&glHeap); // Release spinlock
#if DEBUG_TRACE
Log("[Heap ] Malloc'd %p (%i bytes), returning to %p", best->Data, best->Size, __builtin_return_address(0));
}
if(head->Magic != MAGIC_USED) {
Log_Warning("Heap", "free - Magic value is invalid (%p, 0x%x)", head, head->Magic);
- Log_Notice("Heap", "Allocated %s:%i", head->File, head->Line);
+ Log_Notice("Heap", "Allocated by %s:%i", head->File, head->Line);
return;
}
foot = (void*)( (Uint)head + head->Size - sizeof(tHeapFoot) );
if(foot->Head != head) {
Log_Warning("Heap", "free - Footer backlink is incorrect (%p, 0x%x)", head, foot->Head);
- Log_Notice("Heap", "Allocated %s:%i", head->File, head->Line);
+ Log_Notice("Heap", "Allocated by %s:%i", head->File, head->Line);
return;
}
if(foot->Magic != MAGIC_FOOT) {
Log_Warning("Heap", "free - Footer magic is invalid (%p, %p = 0x%x)", head, &foot->Magic, foot->Magic);
- Log_Notice("Heap", "Allocated %s:%i", head->File, head->Line);
+ Log_Notice("Heap", "Allocated by %s:%i", head->File, head->Line);
return;
}
return ;
#if !VERBOSE_DUMP
- Log_Log("Heap", "%p (0x%llx): 0x%08lx (%i) %4C",
+ Log_Log("Heap", "%p (0x%llx): 0x%08lx %i %4C",
head, MM_GetPhysAddr((Uint)head), head->Size, head->ValidSize, &head->Magic);
Log_Log("Heap", "%p %4C", foot->Head, &foot->Magic);
if(head->File) {
// Print the block info?
#if 1
- Log_Debug("Heap", "%p - 0x%x (%i) Owned by %s:%i",
- head, head->Size, head->ValidSize, head->File, head->Line);
+ if( head->Magic == MAGIC_FREE )
+ Log_Debug("Heap", "%p (0x%llx) - 0x%x free",
+ head->Data, MM_GetPhysAddr((tVAddr)&head->Data), head->Size);
+ else
+ Log_Debug("Heap", "%p (0x%llx) - 0x%x (%i) Owned by %s:%i",
+ head->Data, MM_GetPhysAddr((tVAddr)&head->Data), head->Size, head->ValidSize, head->File, head->Line);
#endif
}