From 918207709205f2abaf60472dd674edb93343e11d Mon Sep 17 00:00:00 2001 From: hpa Date: Wed, 25 Feb 2004 06:56:06 +0000 Subject: [PATCH] Further cleanups --- menu/heap.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/menu/heap.c b/menu/heap.c index 72ebab6..2c90a45 100644 --- a/menu/heap.c +++ b/menu/heap.c @@ -21,17 +21,17 @@ static unsigned int heap_curr = (unsigned int)_end; static inline unsigned int currsp(void) { - unsigned int stkptr; + unsigned int esp; - asm("movl %%esp,%0 " : "=rm" (stkptr) ); - return stkptr; + asm("movl %%esp,%0 " : "=rm" (esp)); + return esp; } static inline void _checkheap(void) { if (currsp() < heap_curr) // Heap corrupted { - csprint("Heap Corrupted, bailing out\n"); + csprint("\r\nHeap overflow, aborting!\r\n"); asm volatile("int $0x21" : : "a" (0x4C7f)); /* Exit with error */ return; } @@ -41,14 +41,16 @@ void * malloc(unsigned int num) // Allocate so much space { unsigned int ans, heap_max; - _checkheap(); - heap_max = currsp() - STACKSIZE; + _checkheap(); + heap_max = currsp() - STACKSIZE; + + ans = (heap_curr+3) & ~3; // Align to 4-byte boundary - if ( heap_curr+num > heap_max ) - return NULL; - ans = heap_curr; - heap_curr += num; - return (void *) ans; + if ( ans+num > heap_max ) + return NULL; + + heap_curr = ans+num; + return (void *) ans; } /* We don't actually ever use these; if enabled, @@ -57,8 +59,8 @@ void * malloc(unsigned int num) // Allocate so much space int checkalloc(unsigned int num) { - _checkheap(); - return (heap_curr + num < heap_max); + _checkheap(); + return (heap_curr + num < heap_max); } -- 2.7.4