pub struct RecursivePageTable<'a> { /* private fields */ }
Expand description
A recursive page table is a last level page table with an entry mapped to the table itself.
This recursive mapping allows accessing all page tables in the hierarchy:
- To access the level 4 page table, we “loop“ (i.e. follow the recursively mapped entry) four times.
- To access a level 3 page table, we “loop” three times and then use the level 4 index.
- To access a level 2 page table, we “loop” two times, then use the level 4 index, then the level 3 index.
- To access a level 1 page table, we “loop” once, then use the level 4 index, then the level 3 index, then the level 2 index.
This struct implements the Mapper
trait.
The page table flags PRESENT
and WRITABLE
are always set for higher level page table
entries, even if not specified, because the design of the recursive page table requires it.
Implementations§
Source§impl<'a> RecursivePageTable<'a>
impl<'a> RecursivePageTable<'a>
Sourcepub fn new(table: &'a mut PageTable) -> Result<Self, InvalidPageTable>
pub fn new(table: &'a mut PageTable) -> Result<Self, InvalidPageTable>
Creates a new RecursivePageTable from the passed level 4 PageTable.
The page table must be recursively mapped, that means:
- The page table must have one recursive entry, i.e. an entry that points to the table
itself.
- The reference must use that “loop”, i.e. be of the form
0o_xxx_xxx_xxx_xxx_0000
wherexxx
is the recursive entry.
- The reference must use that “loop”, i.e. be of the form
- The page table must be active, i.e. the CR3 register must contain its physical address.
Otherwise Err(())
is returned.
§Safety
Note that creating a PageTable
with recursive index 511 is unsound
because allocating the last byte of the address space can lead to pointer
overflows and undefined behavior. For more details, see the discussions
on Zulip
and [in the unsafe-code-guidelines
repo]https://github.com/rust-lang/unsafe-code-guidelines/issues/420).
Sourcepub unsafe fn new_unchecked(
table: &'a mut PageTable,
recursive_index: PageTableIndex,
) -> Self
pub unsafe fn new_unchecked( table: &'a mut PageTable, recursive_index: PageTableIndex, ) -> Self
Creates a new RecursivePageTable without performing any checks.
§Safety
The given page table must be a level 4 page table that is active in the
CPU (i.e. loaded in the CR3 register). The recursive_index
parameter
must be the index of the recursively mapped entry of that page table.
Sourcepub fn level_4_table(&self) -> &PageTable
pub fn level_4_table(&self) -> &PageTable
Returns an immutable reference to the wrapped level 4 PageTable
instance.
Sourcepub fn level_4_table_mut(&mut self) -> &mut PageTable
pub fn level_4_table_mut(&mut self) -> &mut PageTable
Returns a mutable reference to the wrapped level 4 PageTable
instance.