Currently, the documentation specifies how virtual memory is used.
The added assert ensures that any loaded elf program's segments are within the specified bounds.
--- /dev/null
+(Virtual) memory map:
+
+0000'0000'0000'0000 ↔ 0000'0000'0000'1000 - unmapped: 4KiB ensure that nullptr causes a page fault if accessed.
+0000'0000'0000'1000 ↔ 0000'0010'0000'0000 - program segments (.text, .data, .bss, etc.): 64GiB - 4KiB
+0000'0010'0000'1000 ↔ 0000'7FFF'FFFF'0000 - heap: 128TiB - 64GiB - 64KiB
+0000'7FFF'FFFF'0000 ↔ 0000'8000'0000'0000 - stack: 64KiB
+-- Invalid addresses --
+FFFF'8000'0000'0000 ↔ FFFF'C000'0000'0000 - physical memory: 64TiB
+FFFF'C000'0000'0000 ↔ FFFF'FFFF'8000'0000 - unmapped: 64TiB - 2GiB
+FFFF'FFFF'8000'0000 ↔10000'0000'0000'0000 - kernel: 2GiB
}
os::print("Segment: loadable\n");
os::assert((std::uintptr_t(program_header.p_vaddr) & 0xFFF) == 0, "Program segment not 4KiB aligned.");
+ os::assert(0x1000 <= std::uint64_t(program_header.p_vaddr)
+ && std::uint64_t(program_header.p_vaddr + program_header.p_memsz) < 0x10'0000'0000,
+ "Program segments must be contained between 0x1000 and 0x10'0000'0000 (i.e. 64GiB).");
// Allocate memory for segment:
std::size_t nb_pages = (program_header.p_memsz + 0x1000) / 0x1000;