X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fheap.c;h=a569578c99052eee1dffc1b44abf4b8eacbced97;hb=9e019a9a9be9abe8de2073e6e37554d6de35bdb2;hp=abf5f27ea83f451c4807fa4709e383031ccfaf32;hpb=a9f5c2be879ab67080122aaabe83a7ae897126bb;p=tpg%2Facess2.git diff --git a/Kernel/heap.c b/Kernel/heap.c index abf5f27e..a569578c 100644 --- a/Kernel/heap.c +++ b/Kernel/heap.c @@ -28,10 +28,10 @@ void Heap_Install(void); void *Heap_Extend(int Bytes); void *Heap_Merge(tHeapHead *Head); -void *Heap_Allocate(const char *File, int Line, size_t Bytes); -void *Heap_AllocateZero(const char *File, int Line, size_t Bytes); -void *Heap_Reallocate(const char *File, int Line, void *Ptr, size_t Bytes); -void Heap_Deallocate(void *Ptr); +//void *Heap_Allocate(const char *File, int Line, size_t Bytes); +//void *Heap_AllocateZero(const char *File, int Line, size_t Bytes); +//void *Heap_Reallocate(const char *File, int Line, void *Ptr, size_t Bytes); +//void Heap_Deallocate(void *Ptr); void Heap_Dump(void); void Heap_Stats(void); @@ -69,11 +69,17 @@ void *Heap_Extend(int Bytes) } // Heap expands in pages - for(i=0;i<(Bytes+0xFFF)>>12;i++) - MM_Allocate( (tVAddr)gHeapEnd+(i<<12) ); + for( i = 0; i < (Bytes+0xFFF) >> 12; i ++ ) + { + if( !MM_Allocate( (tVAddr)gHeapEnd+(i<<12) ) ) + { + Warning("OOM - Heap_Extend"); + return NULL; + } + } // Increas heap end - gHeapEnd += i << 12; + gHeapEnd = (Uint8*)gHeapEnd + (i << 12); // Create Block head->Size = (Bytes+0xFFF)&~0xFFF; @@ -143,6 +149,11 @@ void *Heap_Allocate(const char *File, int Line, size_t __Bytes) tHeapHead *best = NULL; Uint bestSize = 0; // Speed hack size_t Bytes; + + if( __Bytes == 0 ) { + //return NULL; // TODO: Return a known un-mapped range. + return INVLPTR; + } // Get required size #if POW2_SIZES @@ -277,6 +288,10 @@ void Heap_Deallocate(void *Ptr) Log_Log("Heap", "free: Returns to %p", __builtin_return_address(0)); #endif + // INVLPTR is returned from Heap_Allocate when the allocation + // size is zero. + if( Ptr == INVLPTR ) return; + // Alignment Check if( (Uint)Ptr & (sizeof(Uint)-1) ) { Log_Warning("Heap", "free - Passed a non-aligned address (%p)", Ptr); @@ -644,8 +659,8 @@ void Heap_Stats(void) // Print the block info? #if 1 - Log_Debug("Heap", "%p - 0x%x Owned by %s:%i", - head, head->Size, head->File, head->Line); + Log_Debug("Heap", "%p - 0x%x (%i) Owned by %s:%i", + head, head->Size, head->ValidSize, head->File, head->Line); #endif }