AddressSpace

Struct AddressSpace 

Source
pub struct AddressSpace<'m, M: PhysMapper> {
    root: PhysicalPage<Size4K>,
    mapper: &'m M,
}
Expand description

Handle to a single, concrete address space.

Fields§

§root: PhysicalPage<Size4K>§mapper: &'m M

Implementations§

Source§

impl<'m, M: PhysMapper> AddressSpace<'m, M>

Source

pub unsafe fn from_current(mapper: &'m M) -> Self

View the currently active address space by reading CR3.

§Safety
  • Must run at CPL0 with paging enabled.
  • Assumes CR3 points at a valid PML4 frame.
Source

pub const fn from_root(mapper: &'m M, root: PhysicalPage<Size4K>) -> Self

If you already know the root frame (e.g., from your own allocator), you can still use the explicit constructor:

Source

pub unsafe fn activate(&self)

Load CR3 with this address space’s root.

§Safety

You must ensure the CPU paging state (CR0/CR4/EFER) and code/data mappings are consistent with the target space. Consider reloading CR3 or issuing invlpg after changes to active mappings.

Source

pub const fn root_page(&self) -> RootPage

Physical page of the PML4.

Source

pub(crate) fn pt_mut(&self, page: PhysicalPage<Size4K>) -> &mut PageTable

Borrow a PageTable (PT) in this frame.

Convenience wrapper for [PhysMapper::pt_mut.

Source

pub fn query(&self, va: VirtualAddress) -> Option<PhysicalAddress>

Translate a VirtualAddress to PhysicalAddress if mapped.

Handles 1 GiB and 2 MiB leaves by adding the appropriate in-page offset.

Source

pub fn map_one<A: FrameAlloc, S: MapSize>( &self, alloc: &mut A, va: VirtualAddress, pa: PhysicalAddress, nonleaf_flags: VirtualMemoryPageBits, leaf_flags: VirtualMemoryPageBits, ) -> Result<(), AddressSpaceMapOneError>

Map one page at va → pa with size S and leaf_flags.

  • Non-leaf links are created with nonleaf_flags (e.g., present+writable).
  • Alignment is asserted (debug) via typed wrappers.
§Errors
  • An Out of Memory error occurred in one of the tables.
Source

pub fn unmap_one(&self, va: VirtualAddress) -> Result<(), &'static str>

Unmap a single 4 KiB page at va. Returns Err if missing.

§Errors
  • Invalid tables
Source

pub fn map_region<A: FrameAlloc>( &self, alloc: &mut A, virt_start: VirtualAddress, phys_start: PhysicalAddress, len: u64, nonleaf_flags: VirtualMemoryPageBits, leaf_flags: VirtualMemoryPageBits, ) -> Result<(), AddressSpaceMapRegionError>

Greedy region mapping: tiles [virt_start .. virt_start+len) onto [phys_start .. phys_start+len) using 1G / 2M / 4K pages as alignment permits.

  • Non-leaf links use nonleaf_flags (e.g. present|writable).
  • Leaves use leaf_flags (e.g. perms, NX, GLOBAL).
§Errors
  • Propagates OOMs from intermediate table allocation.
Source

pub fn unmap_region(&self, virt_start: VirtualAddress, len: u64)

Greedy unmap of a region: clears whole 1G/2M leaves when aligned, otherwise 4K PTEs. (Does not collapse tables; that’s a separate optimization pass.)

Source

pub fn collapse_empty_tables<F: FrameAlloc>(&self, free: &mut F)

Walks the whole tree and frees empty tables (PT/PD/PDPT). Does not merge leaves.

Source

fn walk(&self, va: VirtualAddress) -> WalkResult<'_>

Internal walker: resolves VA to the point it terminates.

Source

pub(crate) fn pml4_mut(&self) -> &mut PageMapLevel4

Borrow the PageMapLevel4 (PML4) as a typed table.

Convenience wrapper for [PhysMapper::pml4_mut] at the root_page.

Source

pub(crate) fn pdpt_mut( &self, page: PhysicalPage<Size4K>, ) -> &mut PageDirectoryPointerTable

Borrow a PageDirectoryPointerTable (PDPT) in this frame

Convenience wrapper for [PhysMapper::pdpt_mut].

Source

pub(crate) fn pd_mut(&self, page: PhysicalPage<Size4K>) -> &mut PageDirectory

Borrow a PageDirectory (PD) in this frame

Convenience wrapper for [PhysMapper::pd_mut].

Source

pub(crate) fn zero_pdpt(&self, page: PhysicalPage<Size4K>)

Zeroes the PageDirectoryPointerTable (PDPT) in this frame

Convenience wrapper for [PhysMapper::zero_pdpt].

Source

pub(crate) fn zero_pd(&self, page: PhysicalPage<Size4K>)

Zeroes the PageDirectory (PD) in this frame

Convenience wrapper for [PhysMapper::zero_pd].

Source

pub(crate) fn zero_pt(&self, page: PhysicalPage<Size4K>)

Zeroes the PageTable (PD) in this frame

Convenience wrapper for [PhysMapper::zero_pt].

Auto Trait Implementations§

§

impl<'m, M> Freeze for AddressSpace<'m, M>

§

impl<'m, M> RefUnwindSafe for AddressSpace<'m, M>
where M: RefUnwindSafe,

§

impl<'m, M> Send for AddressSpace<'m, M>
where M: Sync,

§

impl<'m, M> Sync for AddressSpace<'m, M>
where M: Sync,

§

impl<'m, M> Unpin for AddressSpace<'m, M>

§

impl<'m, M> UnwindSafe for AddressSpace<'m, M>
where M: RefUnwindSafe,

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.