From b5eea0cc6060f2aba293adfc2297a900931f91c1 Mon Sep 17 00:00:00 2001 From: mintsuki Date: Sun, 31 Oct 2021 21:25:13 +0100 Subject: [PATCH] pmm: Sanitise away usable entry parts below 0x1000 --- stage23/mm/pmm.s2.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/stage23/mm/pmm.s2.c b/stage23/mm/pmm.s2.c index 3f567bf3..ac31e4c0 100644 --- a/stage23/mm/pmm.s2.c +++ b/stage23/mm/pmm.s2.c @@ -167,12 +167,22 @@ static void sanitise_entries(struct e820_entry_t *m, size_t *_count, bool align_ } } - // Remove 0 length usable entries + // Remove 0 length usable entries and usable entries below 0x1000 for (size_t i = 0; i < count; i++) { if (m[i].type != MEMMAP_USABLE) continue; + if (m[i].base < 0x1000) { + if (m[i].base + m[i].length <= 0x1000) { + goto del_mm1; + } + + m[i].length -= 0x1000 - m[i].base; + m[i].base = 0x1000; + } + if (m[i].length == 0) { +del_mm1: // Eradicate from memmap for (size_t j = i + 1; j < count; j++) { m[j - 1] = m[j];