summaryrefslogtreecommitdiff
path: root/menu
diff options
context:
space:
mode:
authorhpa <hpa>2004-02-25 06:56:06 +0000
committerhpa <hpa>2004-02-25 06:56:06 +0000
commit918207709205f2abaf60472dd674edb93343e11d (patch)
treed06c03747df718edb4408ad92c33d8ace8f805a6 /menu
parentd8d2b90a8c6a6ce62bcb7714a04067a0d883a306 (diff)
downloadsyslinux-918207709205f2abaf60472dd674edb93343e11d.tar.gz
Further cleanupssyslinux-2.09-pre13
Diffstat (limited to 'menu')
-rw-r--r--menu/heap.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/menu/heap.c b/menu/heap.c
index 72ebab6a..2c90a459 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);
}