Skip to main content

Mmu

Struct Mmu 

Source
pub struct Mmu { /* private fields */ }
Expand description

A sparse, page-granular guest address space.

Unmapped pages are simply absent, so a 64-bit address space costs only what the guest actually touches.

Implementations§

Source§

impl Mmu

Source

pub fn new() -> Self

Source

pub fn resident_pages(&self) -> usize

Number of pages currently backed by memory. Mostly a test and telemetry hook — it is the honest measure of an MMU’s footprint.

Source

pub fn check_uninit(&self) -> bool

Source

pub fn set_check_uninit(&mut self, enabled: bool)

Makes a read of a byte without perm::INIT fault.

Source

pub fn watchpoints_armed(&self) -> bool

Source

pub fn set_watchpoints_armed(&mut self, armed: bool)

Makes perm::READ_WATCH and perm::WRITE_WATCH bytes fault.

Source

pub fn tlb_ptr(&mut self) -> *mut u8

The table compiled code indexes, as a raw pointer.

Valid for as long as this MMU is neither moved nor mutated; a caller takes it immediately before entering compiled code.

Source

pub fn flush_tlb(&mut self)

Drops every cached translation. Called for any change to which pages exist or where they live.

Source

pub fn cache_translation(&mut self, addr: u64) -> bool

Caches the page holding addr so compiled code can reach it directly, reporting whether it now can.

Only the page’s residence is cached. Permissions are left to the caller — compiled code reads them from the page itself — so this says nothing about whether any particular access is allowed.

Source

pub fn map( &mut self, addr: u64, len: u64, permissions: Perm, ) -> Result<(), MemFault>

Maps len bytes at addr with permissions, zero-filling the range.

Follows MAP_FIXED semantics: an already-mapped range is replaced rather than refused. perm::MAP is added implicitly — a mapped byte is mapped regardless of what the caller asked for.

Source

pub fn unmap(&mut self, addr: u64, len: u64) -> Result<(), MemFault>

Unmaps len bytes at addr, discarding contents and permissions.

A page whose every byte becomes unmapped is dropped outright, so map/unmap churn does not leak pages.

Source

pub fn protect( &mut self, addr: u64, len: u64, permissions: Perm, ) -> Result<(), MemFault>

Changes the permissions of an already-mapped range, preserving contents.

perm::INIT is preserved rather than taken from permissions: initializedness is a property of the bytes, and mprotect does not scribble on them. Unmapped bytes in the range fault, matching mprotect.

Source

pub fn permissions(&self, addr: u64) -> Perm

Returns the permissions of a single byte, or perm::NONE if unmapped.

Source

pub fn read(&self, addr: u64, out: &mut [u8]) -> Result<(), MemFault>

Reads out.len() bytes into out, requiring perm::READ.

Source

pub fn read_code(&self, addr: u64, out: &mut [u8]) -> Result<(), MemFault>

Reads instruction bytes, requiring perm::EXEC.

The decoder calls this rather than read so that jumping into a non-executable page faults at the fetch, the way it does on hardware, instead of silently decoding data as code.

Source

pub fn write(&mut self, addr: u64, bytes: &[u8]) -> Result<(), MemFault>

Writes bytes at addr, requiring perm::WRITE and marking the written bytes initialized.

Source

pub fn write_unchecked(&mut self, addr: u64, bytes: &[u8], permissions: Perm)

Writes bytes ignoring permissions, mapping any absent pages.

This is the loader and harness entry point — seeding a guest image or a fixture is not a guest access and must not be refused by the permissions it is itself installing. Never reachable from emulated code.

Source

pub fn snapshot(&self) -> MmuSnapshot

Captures the full contents of the address space.

Deliberately a deep copy: correctness first, and a copy-on-write or dirty-page scheme is a drop-in replacement behind this same pair of methods once snapshot cost shows up in a profile.

Source

pub fn restore(&mut self, snapshot: &MmuSnapshot)

Restores a snapshot, discarding every change made since it was taken.

Trait Implementations§

Source§

impl Clone for Mmu

Cloning an MMU produces one with an empty TranslationCache.

A cached entry names a host address inside this MMU’s pages, which the clone does not own. Copying one across would hand compiled code running on the clone a pointer into the original’s memory.

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Mmu

Source§

fn default() -> Mmu

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Mmu

§

impl RefUnwindSafe for Mmu

§

impl Send for Mmu

§

impl Sync for Mmu

§

impl Unpin for Mmu

§

impl UnsafeUnpin for Mmu

§

impl UnwindSafe for Mmu

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.