From 54e0c1876821170ae6447fa4f8dcd00c4c6e0354 Mon Sep 17 00:00:00 2001 From: David Decotigny Date: Tue, 14 Jan 2020 23:31:03 -0800 Subject: [PATCH 1/2] memtop_umalloc: fix "out of memory" detection when expanding bottom arena This caused ipxe to reject images even when enough memory was available. Signed-off-by: David Decotigny --- src/arch/x86/interface/pcbios/memtop_umalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arch/x86/interface/pcbios/memtop_umalloc.c b/src/arch/x86/interface/pcbios/memtop_umalloc.c index f1ab73e297..d7b82189a7 100644 --- a/src/arch/x86/interface/pcbios/memtop_umalloc.c +++ b/src/arch/x86/interface/pcbios/memtop_umalloc.c @@ -190,7 +190,7 @@ static userptr_t memtop_urealloc ( userptr_t ptr, size_t new_size ) { /* Expand/shrink block if possible */ if ( ptr == bottom ) { /* Update block */ - if ( new_size > ( heap_size - extmem.size ) ) { + if ( new_size > ( heap_size + extmem.size ) ) { DBG ( "EXTMEM out of space\n" ); return UNULL; } From f8e046dea8c5ea6389d696728fe7e5c13b76a56f Mon Sep 17 00:00:00 2001 From: David Decotigny Date: Tue, 14 Jan 2020 23:42:05 -0800 Subject: [PATCH 2/2] memtop_umalloc: take alignment into account when checking boundaries Signed-off-by: David Decotigny --- src/arch/x86/interface/pcbios/memtop_umalloc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/arch/x86/interface/pcbios/memtop_umalloc.c b/src/arch/x86/interface/pcbios/memtop_umalloc.c index d7b82189a7..1d3f40a1cf 100644 --- a/src/arch/x86/interface/pcbios/memtop_umalloc.c +++ b/src/arch/x86/interface/pcbios/memtop_umalloc.c @@ -190,14 +190,14 @@ static userptr_t memtop_urealloc ( userptr_t ptr, size_t new_size ) { /* Expand/shrink block if possible */ if ( ptr == bottom ) { /* Update block */ - if ( new_size > ( heap_size + extmem.size ) ) { - DBG ( "EXTMEM out of space\n" ); - return UNULL; - } new = userptr_add ( ptr, - ( new_size - extmem.size ) ); align = ( user_to_phys ( new, 0 ) & ( EM_ALIGN - 1 ) ); new_size += align; new = userptr_add ( new, -align ); + if ( new_size > ( heap_size + extmem.size ) ) { + DBG ( "EXTMEM out of space\n" ); + return UNULL; + } DBG ( "EXTMEM expanding [%lx,%lx) to [%lx,%lx)\n", user_to_phys ( ptr, 0 ), user_to_phys ( ptr, extmem.size ),