Skip to main content

PageTableBuilder

Struct PageTableBuilder 

Source
pub struct PageTableBuilder {
    mem: SyntheticPhysMem,
    next_page: u64,
    cr3: u64,
}
Expand description

Builder for x86_64 4-level page tables.

Fields§

§mem: SyntheticPhysMem§next_page: u64§cr3: u64

Implementations§

Source§

impl PageTableBuilder

Source

pub const CR3: u64 = 0x0000_0000

Physical address of the PML4 table (CR3).

Source

const ADDR_MASK: u64 = 0x000F_FFFF_FFFF_F000

Source

pub fn new() -> Self

Create a new builder with a 16 MB synthetic memory image.

Source

fn alloc_page(&mut self) -> u64

Source

pub fn map_4k(self, vaddr: u64, paddr: u64, page_flags: u64) -> Self

Map a 4K virtual address to a physical address with given flags.

Source

pub fn map_2m(self, vaddr: u64, paddr: u64, page_flags: u64) -> Self

Map a 2MB large page (sets PS bit at PD level).

Source

pub fn map_1g(self, vaddr: u64, paddr: u64, page_flags: u64) -> Self

Map a 1GB huge page (sets PS bit at PDPT level).

Source

fn ensure_pt_entry(&mut self, vaddr: u64) -> u64

Ensure PML4→PDPT→PD→PT hierarchy exists for a 4K vaddr, returning the PT entry address.

Source

pub fn map_demand_zero(self, vaddr: u64) -> Self

Map a demand-zero PTE: upper levels present, PT entry = 0.

Source

pub fn map_transition(self, vaddr: u64, pfn: u64) -> Self

Map a transition PTE: PRESENT=0, bit 11 (TRANSITION)=1, PFN in bits [12..48].

Source

pub fn map_pagefile( self, vaddr: u64, pagefile_num: u8, page_offset: u64, ) -> Self

Map a pagefile PTE: PRESENT=0, pagefile_num in bits [1..5], page_offset in bits [12..48].

Source

pub fn map_prototype(self, vaddr: u64) -> Self

Map a prototype PTE: PRESENT=0, bit 10 (PROTOTYPE)=1.

Source

pub fn map_prototype_raw(self, vaddr: u64, raw_pte: u64) -> Self

Map a prototype PTE with a specific raw PTE value. Bit 10 must be set.

Source

pub fn write_phys(self, addr: u64, data: &[u8]) -> Self

Write data bytes at a physical address in the synthetic memory.

Source

pub fn write_phys_u64(self, addr: u64, value: u64) -> Self

Write a u64 value at a physical address.

Source

pub fn build(self) -> (u64, SyntheticPhysMem)

Consume the builder and return the CR3 value + synthetic memory.

Trait Implementations§

Source§

impl Default for PageTableBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.