]> git.ameliathe1st.gay Git - voyage-au-centre-des-fichiers.git/commitdiff
Added a doc.txt file to specify the kernel documentation, and added a corresponding...
authorAmelia Coutard <eliottulio.coutard@gmail.com>
Tue, 28 Feb 2023 22:24:56 +0000 (23:24 +0100)
committerAmelia Coutard <eliottulio.coutard@gmail.com>
Tue, 28 Feb 2023 22:24:56 +0000 (23:24 +0100)
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.

doc.txt [new file with mode: 0644]
kernel/src/kernel.cpp

diff --git a/doc.txt b/doc.txt
new file mode 100644 (file)
index 0000000..6e9714c
--- /dev/null
+++ b/doc.txt
@@ -0,0 +1,10 @@
+(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
index e5c5b8b426c4c425c5df4ae34f1a36f197897b08..478783dc1fc595b8182077a7405bb948b487cd48 100644 (file)
@@ -201,6 +201,9 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr<const multiboot2::info_s
                }
                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;