From e52dd571d91ad59cf5e0197da51fc309b1183e8e Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Mon, 16 Dec 2024 13:36:03 -0500 Subject: [PATCH] bootloader: Make releasing the heap the platform loader's responsibility. Otherwise, platform loaders couldn't make heap allocations inside platform_start_kernel(), which some loaders (e.g. EFI) do. Implement calling heap_release() for the BIOS loaders at least. This gets us back the ~1.5MB of bootloader heap memory there. --- headers/private/kernel/boot/heap.h | 15 ++++++++++----- src/system/boot/loader/heap.cpp | 2 +- src/system/boot/loader/main.cpp | 6 +++--- src/system/boot/platform/bios_ia32/long.cpp | 2 ++ src/system/boot/platform/bios_ia32/start.cpp | 1 + 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/headers/private/kernel/boot/heap.h b/headers/private/kernel/boot/heap.h index 9f972c3eb1..ce49865e54 100644 --- a/headers/private/kernel/boot/heap.h +++ b/headers/private/kernel/boot/heap.h @@ -1,23 +1,28 @@ /* -** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved. -** Distributed under the terms of the MIT License. -*/ + * Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ #ifndef KERNEL_BOOT_HEAP_H #define KERNEL_BOOT_HEAP_H + #include #include + #ifdef __cplusplus extern "C" { #endif -extern void heap_release(struct stage2_args *args); -extern void heap_print_statistics(); + extern status_t heap_init(struct stage2_args *args); +extern void heap_print_statistics(); +extern void heap_release(); + #ifdef __cplusplus } #endif + #endif /* KERNEL_BOOT_HEAP_H */ diff --git a/src/system/boot/loader/heap.cpp b/src/system/boot/loader/heap.cpp index c7ec5002cd..7efd5e3f5e 100644 --- a/src/system/boot/loader/heap.cpp +++ b/src/system/boot/loader/heap.cpp @@ -383,7 +383,7 @@ FreeChunk::SetToAllocated(void* allocated) void -heap_release(stage2_args* args) +heap_release() { heap_print_statistics(); diff --git a/src/system/boot/loader/main.cpp b/src/system/boot/loader/main.cpp index 98e84670dd..230dd59a1b 100644 --- a/src/system/boot/loader/main.cpp +++ b/src/system/boot/loader/main.cpp @@ -161,13 +161,13 @@ main(stage2_args *args) gKernelArgs.boot_volume_size = gBootVolume.ContentSize(); platform_cleanup_devices(); - // TODO: cleanup, heap_release() etc. - heap_print_statistics(); + // Further cleanup (e.g. heap_release) is the platform's responsibility. + platform_start_kernel(); } } out: - heap_release(args); + heap_release(); return 0; } diff --git a/src/system/boot/platform/bios_ia32/long.cpp b/src/system/boot/platform/bios_ia32/long.cpp index 1c48f7ba0c..4cee5d2d81 100644 --- a/src/system/boot/platform/bios_ia32/long.cpp +++ b/src/system/boot/platform/bios_ia32/long.cpp @@ -354,6 +354,8 @@ long_start_kernel() long_gdt_init(); debug_cleanup(); long_mmu_init(); + heap_release(); + convert_kernel_args(); // Save the kernel entry point address. diff --git a/src/system/boot/platform/bios_ia32/start.cpp b/src/system/boot/platform/bios_ia32/start.cpp index 152f7a4b0f..7477853bd0 100644 --- a/src/system/boot/platform/bios_ia32/start.cpp +++ b/src/system/boot/platform/bios_ia32/start.cpp @@ -139,6 +139,7 @@ platform_start_kernel(void) smp_init_other_cpus(); debug_cleanup(); mmu_init_for_kernel(); + heap_release(); // We're about to enter the kernel -- disable console output. stdout = NULL;