Skip to main content

TableReadOps

Trait TableReadOps 

Source
pub trait TableReadOps {
    type TableAddr: Copy;

    // Required methods
    fn entry_addr(addr: Self::TableAddr, entry_offset: u64) -> Self::TableAddr;
    unsafe fn read_entry(&self, addr: Self::TableAddr) -> PageTableEntry;
    fn to_phys(addr: Self::TableAddr) -> PhysAddr;
    fn from_phys(addr: PhysAddr) -> Self::TableAddr;
    fn root_table(&self) -> Self::TableAddr;
}
Expand description

The read-only operations used to actually access the page table structures, used to allow the same code to be used in the host and the guest for page table setup. This is distinct from TableWriteOps, since there are some implementations for which writing does not make sense, and only reading is required.

Required Associated Types§

Source

type TableAddr: Copy

The type of table addresses

Required Methods§

Source

fn entry_addr(addr: Self::TableAddr, entry_offset: u64) -> Self::TableAddr

Offset the table address by the given offset in bytes.

§Parameters
  • addr: The base address of the table.
  • entry_offset: The offset in bytes within the page table. This is not an entry index; callers must multiply the entry index by the size of a page table entry (typically 8 bytes) to obtain the correct byte offset.
§Returns

The address of the entry at the given byte offset from the base address.

Source

unsafe fn read_entry(&self, addr: Self::TableAddr) -> PageTableEntry

Read a u64 from the given address, used to read existing page table entries

§Safety

This reads from the given memory address, and so all the usual Rust things about raw pointers apply. This will also be used to update guest page tables, so especially in the guest, it is important to ensure that the page tables updates do not break invariants. The implementor of the trait should ensure that nothing else will be reading/writing the address at the same time as mapping code using the trait.

Source

fn to_phys(addr: Self::TableAddr) -> PhysAddr

Convert an abstract table address to a concrete physical address (u64) which can be e.g. written into a page table entry

Source

fn from_phys(addr: PhysAddr) -> Self::TableAddr

Convert a concrete physical address (u64) which may have been e.g. read from a page table entry back into an abstract table address

Source

fn root_table(&self) -> Self::TableAddr

Return the address of the root page table

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§