Utilize linear_phys_to_virt where applicable.

This commit is contained in:
4lDO2
2020-12-25 17:52:07 +01:00
parent 16a31b0cd1
commit df145ea0a9
3 changed files with 8 additions and 5 deletions

View File

@@ -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>),

View File

@@ -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

View File

@@ -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)
})