From 98f08a8badccc216b0ef339c162a579a81a12417 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 24 Feb 2021 20:57:47 +0100 Subject: [PATCH] Kernel: Panic early if the kernel gets too big for its memory slot Let's help our future selves find this problem sooner next time it happens. Hopefully we'll come up with a nicer loader before then, but who knows. :^) --- Kernel/init.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Kernel/init.cpp b/Kernel/init.cpp index 65cb35b8524..800493a877b 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -88,6 +88,8 @@ extern "C" u8* end_of_safemem_text; extern "C" u8* start_of_safemem_atomic_text; extern "C" u8* end_of_safemem_atomic_text; +extern "C" FlatPtr end_of_kernel_image; + multiboot_module_entry_t multiboot_copy_boot_modules_array[16]; size_t multiboot_copy_boot_modules_count; @@ -120,6 +122,11 @@ static Processor s_bsp_processor; // global but let's keep it "private" extern "C" UNMAP_AFTER_INIT [[noreturn]] void init() { + if ((FlatPtr)&end_of_kernel_image >= 0xc1000000u) { + // The kernel has grown too large again! + asm volatile("cli;hlt"); + } + setup_serial_debug(); // We need to copy the command line before kmalloc is initialized,