Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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().
  • Loading branch information
Michael Brown committed Feb 15, 2009
1 parent 816a32a commit 46da517
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/arch/i386/interface/pcbios/memtop_umalloc.c
Expand Up @@ -92,7 +92,7 @@ static int init_eheap ( void ) {
}
}

if ( ! top ) {
if ( ! heap_size ) {
DBG ( "No external heap available\n" );
return -ENOMEM;
}
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit 46da517

Please sign in to comment.