From: John Hodge Date: Mon, 31 May 2010 02:51:14 +0000 (+0800) Subject: Fixed heap bug X-Git-Tag: rel0.06~158 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=2eb3982679688ad61f5555d2a427d8317c5d8b17;p=tpg%2Facess2.git Fixed heap bug --- diff --git a/Kernel/arch/x86_64/mm_virt.c b/Kernel/arch/x86_64/mm_virt.c index b4b26ec1..31bc0d81 100644 --- a/Kernel/arch/x86_64/mm_virt.c +++ b/Kernel/arch/x86_64/mm_virt.c @@ -118,6 +118,10 @@ void MM_PageFault(tVAddr Addr, Uint ErrorCode, tRegs *Regs) // Error_Backtrace(Regs->RIP, Regs->RBP); MM_DumpTables(0, -1); + + __asm__ __volatile__ ("cli"); + for( ;; ) + HALT(); } /** @@ -283,12 +287,16 @@ tPAddr MM_Allocate(tVAddr VAddr) ENTER("xVAddr", VAddr); + // NOTE: This is hack, but I like my dumps to be neat + #if 1 if( !MM_Map(VAddr, 0) ) // Make sure things are allocated { Warning("MM_Allocate: Unable to map, tables did not initialise"); LEAVE('i', 0); return 0; } + MM_Unmap(VAddr); + #endif ret = MM_AllocPhys(); LOG("ret = %x", ret); diff --git a/Kernel/heap.c b/Kernel/heap.c index 8ceefac1..75854b39 100644 --- a/Kernel/heap.c +++ b/Kernel/heap.c @@ -10,8 +10,6 @@ #define DEBUG_TRACE 0 // === CONSTANTS === -#define HEAP_BASE 0xE0800000 -#define HEAP_MAX 0xF0000000 // 120MiB, Plenty #define HEAP_INIT_SIZE 0x8000 // 32 KiB #define BLOCK_SIZE (sizeof(void*)) // 8 Machine Words #define COMPACT_HEAP 0 // Use 4 byte header? @@ -53,18 +51,18 @@ void *Heap_Extend(int Bytes) tHeapFoot *foot; // Bounds Check - if( (Uint)gHeapEnd == MM_KHEAP_MAX ) + if( (tVAddr)gHeapEnd == MM_KHEAP_MAX ) return NULL; // Bounds Check - if( (Uint)gHeapEnd + ((Bytes+0xFFF)&~0xFFF) > MM_KHEAP_MAX ) { - Bytes = MM_KHEAP_MAX - (Uint)gHeapEnd; + if( (tVAddr)gHeapEnd + ((Bytes+0xFFF)&~0xFFF) > MM_KHEAP_MAX ) { + Bytes = MM_KHEAP_MAX - (tVAddr)gHeapEnd; return NULL; } // Heap expands in pages for(i=0;i<(Bytes+0xFFF)>>12;i++) - MM_Allocate( (Uint)gHeapEnd+(i<<12) ); + MM_Allocate( (tVAddr)gHeapEnd+(i<<12) ); // Increas heap end gHeapEnd += i << 12; @@ -76,7 +74,6 @@ void *Heap_Extend(int Bytes) foot->Head = head; foot->Magic = MAGIC_FOOT; - //Log(" Heap_Extend: head = %p", head); return Heap_Merge(head); // Merge with previous block } @@ -97,7 +94,7 @@ void *Heap_Merge(tHeapHead *Head) // Merge Left (Down) foot = (void*)( (Uint)Head - sizeof(tHeapFoot) ); - if( ((Uint)foot < (Uint)gHeapEnd && (Uint)foot > HEAP_BASE) + if( ((Uint)foot < (Uint)gHeapEnd && (Uint)foot > (Uint)gHeapStart) && foot->Head->Magic == MAGIC_FREE) { foot->Head->Size += Head->Size; // Increase size thisFoot->Head = foot->Head; // Change backlink