]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[uheap] Prevent allocation of blocks with zero physical addresses
authorMichael Brown <mcb30@ipxe.org>
Thu, 22 May 2025 15:05:37 +0000 (16:05 +0100)
committerMichael Brown <mcb30@ipxe.org>
Thu, 22 May 2025 15:16:14 +0000 (16:16 +0100)
If the external heap ends up at the top of the system memory map then
leave a gap after the heap to ensure that no block ends up being
allocated with either a start or end address of zero, since this is
frequently confusing to both code and humans.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/core/uheap.c

index 60efcf0503b5fd11d5331dd8b18263cc315f85e3..f5154a0d1dfe9b5dcc00d4a87204a16c9bc41b9a 100644 (file)
@@ -100,8 +100,8 @@ static void uheap_find ( void ) {
        DBGC ( &uheap, "UHEAP largest region is [%#08lx,%#08lx)\n",
               start, end );
 
-       /* Align start and end addresses */
-       after = ( end & ( UHEAP_ALIGN - 1 ) );
+       /* Align start and end addresses, and prevent overflow to zero */
+       after = ( end ? ( end & ( UHEAP_ALIGN - 1 ) ) : UHEAP_ALIGN );
        before = ( ( -start ) & ( UHEAP_ALIGN - 1 ) );
        strip = ( before + after );
        if ( strip > size )