From 108ced98b17f5eff77de99f57cea65a3c8ddd2cb Mon Sep 17 00:00:00 2001 From: Amelia Coutard Date: Wed, 1 Mar 2023 14:57:54 +0100 Subject: [PATCH] Fixed elf page-alignment necessity. Now only requires no page overlap --- kernel/src/kernel.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/kernel/src/kernel.cpp b/kernel/src/kernel.cpp index c5d8591..8c1569c 100644 --- a/kernel/src/kernel.cpp +++ b/kernel/src/kernel.cpp @@ -200,13 +200,12 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr(PT_alloc.ptr.get_phys_addr())); } os::paging::PT& PT = *get_base_address(PDT.contents[indices.pde]); - if (PT.contents[indices.pe].P == 0) { - PT.contents[indices.pe] = {.P = 1, .R_W = (program_header.flags & 2) >> 1, .U_S = 1, .PWT = 0, .PCD = 0, .PAT = 0, .G = 0, .base_address = 0, .NX = 0}; - const auto page_alloc = os::paging::page_allocator.allocate(1); - set_page_base_address(PT.contents[indices.pe], os::phys_ptr(page_alloc.ptr.get_phys_addr())); - } + os::assert(PT.contents[indices.pe].P == 0, "Process segments' memory overlaps the same pages."); + PT.contents[indices.pe] = {.P = 1, .R_W = (program_header.flags & 2) >> 1, .U_S = 1, .PWT = 0, .PCD = 0, .PAT = 0, .G = 0, .base_address = 0, .NX = 0}; + const auto page_alloc = os::paging::page_allocator.allocate(1); + set_page_base_address(PT.contents[indices.pe], os::phys_ptr(page_alloc.ptr.get_phys_addr())); } // Initialise memory for segment: @@ -267,11 +265,10 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr(PT_alloc.ptr.get_phys_addr())); } os::paging::PT& PT = *get_base_address(PDT.contents[indices.pde]); - if (PT.contents[indices.pe].P == 0) { - PT.contents[indices.pe] = {.P = 1, .R_W = 1, .U_S = 1, .PWT = 0, .PCD = 0, .PAT = 0, .G = 0, .base_address = 0, .NX = 0}; - const auto page_alloc = os::paging::page_allocator.allocate(1); - set_page_base_address(PT.contents[indices.pe], os::phys_ptr(page_alloc.ptr.get_phys_addr())); - } + os::assert(PT.contents[indices.pe].P == 0, "Process segments' memory overlaps the same pages."); + PT.contents[indices.pe] = {.P = 1, .R_W = 1, .U_S = 1, .PWT = 0, .PCD = 0, .PAT = 0, .G = 0, .base_address = 0, .NX = 0}; + const auto page_alloc = os::paging::page_allocator.allocate(1); + set_page_base_address(PT.contents[indices.pe], os::phys_ptr(page_alloc.ptr.get_phys_addr())); } // Initialise stack to 0. -- 2.47.0