core: Add workaround for QEMU-specific triple-faults without KVM

Without KVM, qemu inserts an invalid 12-GiB reserved entry at the end of the physical address space, making the kernel reserve way more space than necessary for the page bitmap (and overwriting the page directory pages).
This commit is contained in:
Gabriel 2025-02-15 15:16:50 +01:00
parent 13ec4bee87
commit 5d26b114a4

View File

@ -1,4 +1,5 @@
const easyboot = @cImport(@cInclude("easyboot.h")); const easyboot = @cImport(@cInclude("easyboot.h"));
const target = @import("builtin").target;
const MemoryMapIterator = struct { const MemoryMapIterator = struct {
tag: *easyboot.multiboot_tag_mmap_t, tag: *easyboot.multiboot_tag_mmap_t,
@ -15,6 +16,16 @@ const MemoryMapIterator = struct {
if (@intFromPtr(self.entry) >= self.end) self.entry = null; if (@intFromPtr(self.entry) >= self.end) self.entry = null;
if (target.cpu.arch == .x86_64) {
// Workaround for https://gitlab.com/qemu-project/qemu/-/commit/8504f129450b909c88e199ca44facd35d38ba4de
// This invalid 12GiB reserved entry is made up by QEMU (doesn't appear on any real hardware), so we can simply
// ignore it and move on to the next entry.
if (current_entry) |entry| {
if (entry.base_addr == 0x000000fd00000000 and entry.length == (0x000000ffffffffff - 0x000000fd00000000) + 1)
return self.next();
}
}
return current_entry; return current_entry;
} }