diff --git a/src/arch/x86_64/paging/mapper.rs b/src/arch/x86_64/paging/mapper.rs index a89ea678d61a365a4140cc94b44f0c4c94eb8751..ab0c5c7f64c1dd7977bb3b8a4598db78d11a5024 100644 --- a/src/arch/x86_64/paging/mapper.rs +++ b/src/arch/x86_64/paging/mapper.rs @@ -1,5 +1,5 @@ use crate::memory::{allocate_frames, deallocate_frames, Frame}; -use super::{Page, PAGE_SIZE, PageFlags, PhysicalAddress, VirtualAddress}; +use super::{linear_phys_to_virt, Page, PAGE_SIZE, PageFlags, PhysicalAddress, VirtualAddress}; use super::RmmA; use super::table::{Table, Level4}; @@ -37,7 +37,8 @@ impl<'table> Mapper<'table> { /// must also be valid, and the frame must not outlive the lifetime. pub unsafe fn from_p4_unchecked(frame: &mut Frame) -> Self { let phys = frame.start_address(); - let virt = VirtualAddress::new(phys.data() + crate::KERNEL_OFFSET); + let virt = linear_phys_to_virt(phys) + .expect("expected page table frame to fit within linear mapping"); Self { p4: &mut *(virt.data() as *mut Table<Level4>), diff --git a/src/arch/x86_64/paging/mod.rs b/src/arch/x86_64/paging/mod.rs index eff4acfbe1c568bfb3318824f8256cefdf9fd37d..02dac6de7cbfeb250be844aca5054bc17f3568e3 100644 --- a/src/arch/x86_64/paging/mod.rs +++ b/src/arch/x86_64/paging/mod.rs @@ -310,7 +310,8 @@ impl InactivePageTable { // case it is outside the pre-mapped physical address range, or if such a range is too // large to fit the whole physical address space in the virtual address space. { - let table = VirtualAddress::new(frame.start_address().data() + crate::KERNEL_OFFSET); + let table = linear_phys_to_virt(frame.start_address()) + .expect("cannot initialize InactivePageTable (currently) without the frame being linearly mapped"); // now we are able to zero the table // SAFETY: The caller must ensure exclusive access to the pointed-to virtual address of diff --git a/src/arch/x86_64/paging/table.rs b/src/arch/x86_64/paging/table.rs index ff92822553387c7cf10c1768588f2558d724cd5e..e6467bf071d09c02e3a302e43b717561d0214839 100644 --- a/src/arch/x86_64/paging/table.rs +++ b/src/arch/x86_64/paging/table.rs @@ -5,7 +5,7 @@ use core::marker::PhantomData; use core::ops::{Index, IndexMut}; use crate::memory::allocate_frames; -use crate::paging::VirtualAddress; +use crate::paging::{linear_phys_to_virt, VirtualAddress}; use super::{ENTRY_COUNT, PageFlags}; use super::entry::{Entry, EntryFlags}; @@ -112,7 +112,8 @@ impl<L> Table<L> where L: HierarchicalLevel { return None; } let next_table_physaddr = next_table_frame.start_address(); - let next_table_virtaddr = VirtualAddress::new(next_table_physaddr.data() + crate::KERNEL_OFFSET); + let next_table_virtaddr = linear_phys_to_virt(next_table_physaddr) + .expect("expected page table frame to fit within linear mapping"); Some(next_table_virtaddr) })