From 06315dd809a30dfefe0698b96b24746d6553db42 Mon Sep 17 00:00:00 2001 From: mintsuki Date: Thu, 15 Apr 2021 03:44:25 +0200 Subject: [PATCH] pmm: Protect page 0 of physical memory --- stage23/mm/pmm.s2.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/stage23/mm/pmm.s2.c b/stage23/mm/pmm.s2.c index 2d968221..36b78a7e 100644 --- a/stage23/mm/pmm.s2.c +++ b/stage23/mm/pmm.s2.c @@ -216,7 +216,18 @@ void init_memmap(void) { panic("Memory map exhausted."); } - memmap[memmap_entries++] = e820_map[i]; + memmap[memmap_entries] = e820_map[i]; + + if (memmap[memmap_entries].base < 0x1000) { + if (memmap[memmap_entries].base + memmap[memmap_entries].length <= 0x1000) { + continue; + } + + memmap[memmap_entries].length -= 0x1000 - memmap[memmap_entries].base; + memmap[memmap_entries].base = 0x1000; + } + + memmap_entries++; } // Allocate bootloader itself @@ -226,8 +237,6 @@ void init_memmap(void) { sanitise_entries(false); allocations_disallowed = false; - - print_memmap(memmap, memmap_entries); } #endif @@ -286,6 +295,15 @@ void init_memmap(void) { memmap[memmap_entries].base = entry->PhysicalStart; memmap[memmap_entries].length = entry->NumberOfPages * 4096; + if (memmap[memmap_entries].base < 0x1000) { + if (memmap[memmap_entries].base + memmap[memmap_entries].length <= 0x1000) { + continue; + } + + memmap[memmap_entries].length -= 0x1000 - memmap[memmap_entries].base; + memmap[memmap_entries].base = 0x1000; + } + memmap_entries++; }