From fcf2f7f439c13c3df8e827c42bd4de5c9b6685ff Mon Sep 17 00:00:00 2001 From: Julien CLEMENT Date: Wed, 8 Dec 2021 02:23:46 +0100 Subject: [PATCH] fix(paging): load back original P4 instead of temporary page frame in InactivePageTable::under Signed-off-by: Julien CLEMENT --- src/linker.ld | 1 + src/memory/paging/mod.rs | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/linker.ld b/src/linker.ld index 8c4fed2..8df41e8 100644 --- a/src/linker.ld +++ b/src/linker.ld @@ -10,6 +10,7 @@ SECTIONS { . = ALIGN(4K); } + . = ALIGN(4K); .text : { *(.text .text.*) diff --git a/src/memory/paging/mod.rs b/src/memory/paging/mod.rs index c5825ce..769242b 100644 --- a/src/memory/paging/mod.rs +++ b/src/memory/paging/mod.rs @@ -27,13 +27,13 @@ pub fn kernel_remap(allocator: &mut A, boot_info: &BootInformation) // section is not loaded to memory continue; } + println!("mapping section at addr: {:#x}, size: {:#x}", + section.addr, section.size); assert!(section.start_address() % PAGE_SIZE == 0, "sections need to be page aligned"); - println!("mapping section at addr: {:#x}, size: {:#x}", - section.addr, section.size); - let flags = Flags::WRITABLE; + let flags = Flags::WRITABLE | Flags::PRESENT; let start_frame = Frame::::containing_address(PhysAddr::new(section.start_address() as u64)); let end_frame = Frame::containing_address(PhysAddr::new(section.end_address() as u64 - 1)); @@ -74,7 +74,7 @@ impl InactivePageTable { f(active_table); - p4_table[511].set_frame(self.p4_frame, Flags::PRESENT | Flags::WRITABLE); + p4_table[511].set_frame(backup, Flags::PRESENT | Flags::WRITABLE); x86_64::instructions::tlb::flush_all(); temporary_page.unmap(active_table);