From: Michael Brown Date: Sun, 15 Feb 2009 07:50:23 +0000 (+0000) Subject: [umalloc] Avoid problems when _textdata_memsz is a multiple of 4kB X-Git-Tag: v0.9.7~43 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=46da51703a6f0d213a9b1cbcc4103bb842e2b945;p=thirdparty%2Fipxe.git [umalloc] Avoid problems when _textdata_memsz is a multiple of 4kB If it happens that _textdata_memsz ends up being an exact multiple of 4kB, then this will cause the .textdata section (after relocation) to start on a page boundary. This means that the hidden memory region (which is rounded down to the nearest page boundary) will start exactly at virtual address 0, i.e. UNULL. This means that init_eheap() will erroneously assume that it has failed to allocate a an external heap, since it typically ends up choosing the area that lies immediately below .textdata, which in this case will be the region with top==UNULL. A subsequent error is that memtop_urealloc() passes through the error return status -ENOMEM to the caller, which (rightly) assumes that the result represents a valid userptr_t address. Fixed by using alternative tests for heap non-existence, and by returning UNULL in case of an error from init_eheap(). --- diff --git a/src/arch/i386/interface/pcbios/memtop_umalloc.c b/src/arch/i386/interface/pcbios/memtop_umalloc.c index 2eb7f76db..744d8e305 100644 --- a/src/arch/i386/interface/pcbios/memtop_umalloc.c +++ b/src/arch/i386/interface/pcbios/memtop_umalloc.c @@ -92,7 +92,7 @@ static int init_eheap ( void ) { } } - if ( ! top ) { + if ( ! heap_size ) { DBG ( "No external heap available\n" ); return -ENOMEM; } @@ -139,9 +139,9 @@ static userptr_t memtop_urealloc ( userptr_t ptr, size_t new_size ) { int rc; /* Initialise external memory allocator if necessary */ - if ( ! top ) { + if ( bottom == top ) { if ( ( rc = init_eheap() ) != 0 ) - return rc; + return UNULL; } /* Get block properties into extmem */