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 MImplementations§
Source§impl<'m, M: PhysMapper> AddressSpace<'m, M>
impl<'m, M: PhysMapper> AddressSpace<'m, M>
Sourcepub unsafe fn from_current(mapper: &'m M) -> Self
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.
Sourcepub const fn from_root(mapper: &'m M, root: PhysicalPage<Size4K>) -> Self
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:
Sourcepub unsafe fn activate(&self)
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.
Sourcepub(crate) fn pt_mut(&self, page: PhysicalPage<Size4K>) -> &mut PageTable
pub(crate) fn pt_mut(&self, page: PhysicalPage<Size4K>) -> &mut PageTable
Borrow a PageTable (PT) in this frame.
Convenience wrapper for [PhysMapper::pt_mut.
Sourcepub fn query(&self, va: VirtualAddress) -> Option<PhysicalAddress>
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.
Sourcepub fn map_one<A: FrameAlloc, S: MapSize>(
&self,
alloc: &mut A,
va: VirtualAddress,
pa: PhysicalAddress,
nonleaf_flags: VirtualMemoryPageBits,
leaf_flags: VirtualMemoryPageBits,
) -> Result<(), AddressSpaceMapOneError>
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.
Sourcepub 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>
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.
Sourcepub fn unmap_region(&self, virt_start: VirtualAddress, len: u64)
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.)
Sourcepub fn collapse_empty_tables<F: FrameAlloc>(&self, free: &mut F)
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.
Sourcefn walk(&self, va: VirtualAddress) -> WalkResult<'_>
fn walk(&self, va: VirtualAddress) -> WalkResult<'_>
Internal walker: resolves VA to the point it terminates.
Sourcepub(crate) fn pml4_mut(&self) -> &mut PageMapLevel4
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.
Sourcepub(crate) fn pdpt_mut(
&self,
page: PhysicalPage<Size4K>,
) -> &mut PageDirectoryPointerTable
pub(crate) fn pdpt_mut( &self, page: PhysicalPage<Size4K>, ) -> &mut PageDirectoryPointerTable
Borrow a PageDirectoryPointerTable (PDPT) in this frame
Convenience wrapper for [PhysMapper::pdpt_mut].
Sourcepub(crate) fn pd_mut(&self, page: PhysicalPage<Size4K>) -> &mut PageDirectory
pub(crate) fn pd_mut(&self, page: PhysicalPage<Size4K>) -> &mut PageDirectory
Borrow a PageDirectory (PD) in this frame
Convenience wrapper for [PhysMapper::pd_mut].
Sourcepub(crate) fn zero_pdpt(&self, page: PhysicalPage<Size4K>)
pub(crate) fn zero_pdpt(&self, page: PhysicalPage<Size4K>)
Zeroes the PageDirectoryPointerTable (PDPT) in this frame
Convenience wrapper for [PhysMapper::zero_pdpt].
Sourcepub(crate) fn zero_pd(&self, page: PhysicalPage<Size4K>)
pub(crate) fn zero_pd(&self, page: PhysicalPage<Size4K>)
Zeroes the PageDirectory (PD) in this frame
Convenience wrapper for [PhysMapper::zero_pd].
Sourcepub(crate) fn zero_pt(&self, page: PhysicalPage<Size4K>)
pub(crate) fn zero_pt(&self, page: PhysicalPage<Size4K>)
Zeroes the PageTable (PD) in this frame
Convenience wrapper for [PhysMapper::zero_pt].