Struct memory::PageTable

source ·
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

source

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.

source

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).

source

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.

source

pub fn physical_address(&self) -> PhysicalAddress

Returns the physical address of this page table’s top-level p4 frame

Methods from Deref<Target = Mapper>§

source

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.

source

pub fn translate( &self, virtual_address: VirtualAddress ) -> Option<PhysicalAddress>

Translates a VirtualAddress to a PhysicalAddress by walking the page tables.

source

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.

source

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.

source

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().

Trait Implementations§

source§

impl Debug for PageTable

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Deref for PageTable

§

type Target = Mapper

The resulting type after dereferencing.
source§

fn deref(&self) -> &Mapper

Dereferences the value.
source§

impl DerefMut for PageTable

source§

fn deref_mut(&mut self) -> &mut Mapper

Mutably dereferences the value.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.