From: Amelia Coutard <eliottulio.coutard@gmail.com> Date: Tue, 28 Feb 2023 22:24:56 +0000 (+0100) Subject: Added a doc.txt file to specify the kernel documentation, and added a corresponding... X-Git-Url: https://git.ameliathe1st.gay/?a=commitdiff_plain;h=780c69c17e3668400bfdaaa84925de681e0d1ba7;p=voyage-au-centre-des-fichiers.git Added a doc.txt file to specify the kernel documentation, and added a corresponding assert in the code 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. --- diff --git a/doc.txt b/doc.txt new file mode 100644 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 diff --git a/kernel/src/kernel.cpp b/kernel/src/kernel.cpp index e5c5b8b..478783d 100644 --- a/kernel/src/kernel.cpp +++ b/kernel/src/kernel.cpp @@ -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;