Skip to main content

walk_va_spaces

Function walk_va_spaces 

Source
pub unsafe fn walk_va_spaces<Op: TableReadOps>(
    op: &Op,
    roots: &[Op::TableAddr],
    address: u64,
    len: u64,
) -> Vec<(SpaceId, Vec<SpaceAwareMapping>)>
Expand description

Walk multiple page-table roots together, emitting either a normal leaf mapping (ThisSpace) or a reference to an alias that was already seen via an earlier root (AnotherSpace).

The caller passes roots in their preferred order of primacy. The first root to visit a particular intermediate PA becomes the “owner” of that sub-table — subsequent roots that alias it receive AnotherSpace entries referencing the owner.

The returned Vec is ordered the same way roots was passed — so by construction the result is topologically sorted: every AnotherSpace reference points to a space that appears earlier in the list. This lets a rebuilder process roots in iteration order without a separate sort pass, and guarantees that the space_aware_map invariant is met.

§Safety

Same invariants as virt_to_phys. Callers must ensure the page tables are not being mutated concurrently. 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

Multi-space page-table walking on amd64: walks each root independently and emits all leaves as ThisSpace. Aliased intermediate-table detection is not implemented here because no current embedder exercises that pattern on amd64.

TODO: align with the i686 implementation and detect aliased intermediate tables to avoid semantic divergence across arches. Tracking: follow-up issue.