pub struct PageTable { /* private fields */ }
Expand description
A top-level root (P4) page table.
Auto-derefs into a Mapper
for easy invocation of memory mapping functions.
Implementations§
source§impl PageTable
impl PageTable
sourcepub fn new_table(
current_page_table: &mut PageTable,
new_p4_frame: AllocatedFrames,
page: Option<AllocatedPages>
) -> Result<PageTable, &'static str>
pub fn new_table( current_page_table: &mut PageTable, new_p4_frame: AllocatedFrames, page: Option<AllocatedPages> ) -> Result<PageTable, &'static str>
Initializes a new top-level P4 PageTable
whose root is located in the given new_p4_frame
.
It requires using the given current_active_table
to set up its initial mapping contents.
A single allocated page can optionally be provided for use as part of a new TemporaryPage
for the recursive mapping.
Returns the new PageTable
that exists in physical memory at the given new_p4_frame
.
Note that this new page table has no current mappings beyond the recursive P4 mapping,
so you will need to create or copy over any relevant mappings
before using (switching) to this new page table in order to ensure the system keeps running.
sourcepub fn with<F, R>(
&mut self,
other_table: &mut PageTable,
f: F
) -> Result<R, &'static str>where
F: FnOnce(&mut Mapper, &Mapper) -> Result<R, &'static str>,
pub fn with<F, R>( &mut self, other_table: &mut PageTable, f: F ) -> Result<R, &'static str>where F: FnOnce(&mut Mapper, &Mapper) -> Result<R, &'static str>,
Temporarily maps the given other PageTable
to the temporary recursive
index (508th entry)
Accepts a closure f
that is passed a mutable reference to the other
table’s mapper, and an immutable reference to the current table’s
mapper.
Note
This does not perform any task switching or changing of the current page table register (e.g., cr3).
sourcepub fn switch(&mut self, new_table: &PageTable)
pub fn switch(&mut self, new_table: &PageTable)
Switches from the currently-active page table (this PageTable
, i.e., self
) to the given new_table
.
After this function, the given new_table
will be the currently-active PageTable
.
sourcepub fn physical_address(&self) -> PhysicalAddress
pub fn physical_address(&self) -> PhysicalAddress
Returns the physical address of this page table’s top-level p4 frame
Methods from Deref<Target = Mapper>§
sourcepub fn dump_pte(&self, virtual_address: VirtualAddress)
pub fn dump_pte(&self, virtual_address: VirtualAddress)
Dumps all page table entries at all four page table levels for the given VirtualAddress
,
and also shows their PteFlags
.
The page table details are written to the log as an info
message.
sourcepub fn translate(
&self,
virtual_address: VirtualAddress
) -> Option<PhysicalAddress>
pub fn translate( &self, virtual_address: VirtualAddress ) -> Option<PhysicalAddress>
Translates a VirtualAddress
to a PhysicalAddress
by walking the page tables.
sourcepub fn translate_page(&self, page: Page) -> Option<Frame>
pub fn translate_page(&self, page: Page) -> Option<Frame>
Translates a virtual memory Page
to a physical memory Frame
by walking the page tables.
Note that this only supports translating a 4K page into a 4K frame, but it still correctly handles the cases where huge pages are used in the page tables.
sourcepub fn map_allocated_pages_to<P, FL>(
&mut self,
pages: AllocatedPages,
frames: AllocatedFrames<P>,
flags: FL
) -> Result<MappedPages, &'static str>where
P: PageSize,
FL: Into<PteFlagsArch>,
pub fn map_allocated_pages_to<P, FL>( &mut self, pages: AllocatedPages, frames: AllocatedFrames<P>, flags: FL ) -> Result<MappedPages, &'static str>where P: PageSize, FL: Into<PteFlagsArch>,
Maps the given virtual AllocatedPages
to the given physical AllocatedFrames
.
Consumes the given AllocatedPages
and returns a MappedPages
object which contains those AllocatedPages
.
sourcepub fn map_allocated_pages<FL: Into<PteFlagsArch>>(
&mut self,
pages: AllocatedPages,
flags: FL
) -> Result<MappedPages, &'static str>
pub fn map_allocated_pages<FL: Into<PteFlagsArch>>( &mut self, pages: AllocatedPages, flags: FL ) -> Result<MappedPages, &'static str>
Maps the given 4K-sized AllocatedPages
to randomly chosen (allocated) physical frames.
Consumes the given AllocatedPages
and returns a MappedPages
object which contains those AllocatedPages
.
Note on huge pages
This function only supports 4K-sized pages, not huge pages.
To use huge pages, you must provide the huge frames and call Self::map_allocated_pages_to()
.