Skip to main content

map

Function map 

Source
pub unsafe fn map<Op: TableOps>(op: &Op, mapping: Mapping)
Expand description

Assumption: all are page-aligned

ยงSafety

This function modifies pages backing a virtual memory range which is inherently unsafe w.r.t. the Rust memory model.

When using this function, please note:

  • No locking is performed before touching page table data structures, as such do not use concurrently with any other page table operations
  • TLB invalidation is not performed, if previously-mapped ranges are being remapped, TLB invalidation may need to be performed afterwards. Maps a contiguous virtual address range to physical memory.

This function walks the 4-level page table hierarchy (PML4 โ†’ PDPT โ†’ PD โ†’ PT), allocating intermediate tables as needed via alloc_pte_if_needed, and finally writing the leaf page table entries with the requested permissions via map_page.

The iterator chain processes each level:

  1. PML4 (47:39) - allocate PDPT if needed
  2. PDPT (38:30) - allocate PD if needed
  3. PD (29:21) - allocate PT if needed
  4. PT (20:12) - write final PTE with physical address and flags