X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fheap.c;h=eefd13cf22e6c690e65fcd9702c05846018cdd92;hb=cbe0cc999c61fff862054bf428b7163e5458f2af;hp=fc99f56c212147a018eb809d2b9abe853bad0ded;hpb=952891ddb96a341c0e24ecb7dec6361c7bbeaece;p=tpg%2Facess2.git diff --git a/Kernel/heap.c b/Kernel/heap.c index fc99f56c..eefd13cf 100644 --- a/Kernel/heap.c +++ b/Kernel/heap.c @@ -49,7 +49,6 @@ void Heap_Install(void) } /** - * \fn void *Heap_Extend(int Bytes) * \brief Extend the size of the heap */ void *Heap_Extend(int Bytes) @@ -69,7 +68,7 @@ void *Heap_Extend(int Bytes) // Bounds Check if( (tVAddr)gHeapEnd + ((Bytes+0xFFF)&~0xFFF) > MM_KHEAP_MAX ) { - Bytes = MM_KHEAP_MAX - (tVAddr)gHeapEnd; +// Bytes = MM_KHEAP_MAX - (tVAddr)gHeapEnd; return NULL; } @@ -97,7 +96,6 @@ void *Heap_Extend(int Bytes) } /** - * \fn void *Heap_Merge(tHeapHead *Head) * \brief Merges two ajacent heap blocks */ void *Heap_Merge(tHeapHead *Head) @@ -142,10 +140,9 @@ void *Heap_Merge(tHeapHead *Head) } /** - * \brief Allocate memory from the heap * \param File Allocating source file * \param Line Source line - * \param Bytes Size of region to allocate + * \param __Bytes Size of region to allocate */ void *Heap_Allocate(const char *File, int Line, size_t __Bytes) { @@ -197,7 +194,8 @@ void *Heap_Allocate(const char *File, int Line, size_t __Bytes) if(head->Magic != MAGIC_FREE) { Mutex_Release(&glHeap); // Release spinlock #if WARNINGS - Log_Warning("Heap", "Magic of heap address %p is invalid (0x%x)", head, head->Magic); + Log_Warning("Heap", "Magic of heap address %p is invalid (%p = 0x%x)", + head, &head->Magic, head->Magic); Heap_Dump(); #endif return NULL; @@ -215,7 +213,8 @@ void *Heap_Allocate(const char *File, int Line, size_t __Bytes) head->AllocateTime = now(); Mutex_Release(&glHeap); // Release spinlock #if DEBUG_TRACE - Debug("[Heap ] Malloc'd %p (%i bytes), returning to %p", head->Data, head->Size, __builtin_return_address(0)); + Debug("[Heap ] Malloc'd %p (%i bytes), returning to %p", + head->Data, head->Size, __builtin_return_address(0)); #endif return head->Data; } @@ -284,7 +283,6 @@ void *Heap_Allocate(const char *File, int Line, size_t __Bytes) } /** - * \fn void Heap_Deallocate(void *Ptr) * \brief Free an allocated memory block */ void Heap_Deallocate(void *Ptr) @@ -309,8 +307,8 @@ void Heap_Deallocate(void *Ptr) // Sanity check if((Uint)Ptr < (Uint)gHeapStart || (Uint)Ptr > (Uint)gHeapEnd) { - Log_Warning("Heap", "free - Passed a non-heap address (%p < %p < %p)\n", - gHeapStart, Ptr, gHeapEnd); + Log_Warning("Heap", "free - Passed a non-heap address by %p (%p < %p < %p)\n", + __builtin_return_address(0), gHeapStart, Ptr, gHeapEnd); return; } @@ -519,8 +517,8 @@ void Heap_Dump(void) { foot = (void*)( (Uint)head + head->Size - sizeof(tHeapFoot) ); #if VERBOSE_DUMP - 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 (0x%P): 0x%08x (%i) %4C", + head, MM_GetPhysAddr((tVAddr)head), head->Size, head->ValidSize, &head->Magic); Log_Log("Heap", "%p %4C", foot->Head, &foot->Magic); if(head->File) { Log_Log("Heap", "%sowned by %s:%i", @@ -572,7 +570,7 @@ void Heap_Dump(void) Log_Log("Heap", "%p (%P): 0x%08lx %i %4C", head, MM_GetPhysAddr((Uint)head), head->Size, head->ValidSize, &head->Magic); if(foot) - Log_Log("Heap", "Backlink = %p %4C", foot->Head, &foot->Magic); + Log_Log("Heap", "Foot %p = {Head:%p,Magic:%4C}", foot, foot->Head, &foot->Magic); if(head->File) { Log_Log("Heap", "%sowned by %s:%i", (head->Magic==MAGIC_FREE?"was ":""), head->File, head->Line); @@ -686,7 +684,10 @@ void Heap_Stats(void) else frag = 0; Log_Log("Heap", "%i.%02i%% Heap Fragmentation", frag/100, frag%100); - avgAlloc = (totalBytes-freeBytes)/(nBlocks-nFree); + if(nBlocks <= nFree) + avgAlloc = 0; + else + avgAlloc = (totalBytes-freeBytes)/(nBlocks-nFree); if(avgAlloc != 0) overhead = (sizeof(tHeapFoot)+sizeof(tHeapHead))*10000/avgAlloc; else @@ -699,6 +700,7 @@ void Heap_Stats(void) // Scan and get distribution #if 1 + if(nBlocks > 0) { struct { Uint Size;