Skip to main content

GuestMemory

Struct GuestMemory 

Source
pub struct GuestMemory {
    pub brk: u64,
    pub stack_top: u64,
    /* private fields */
}
Expand description

Owns guest pages and maintains the pointer-based view used by compiled regions.

Fields§

§brk: u64

Gives the first address after the current guest heap.

§stack_top: u64

Gives the fixed exclusive stack top used to build the initial process stack.

Implementations§

Source§

impl GuestMemory

Source

pub fn new() -> Self

Starts with no mappings so ELF loading can define all initial permissions.

Source

pub fn from_program(program: &ProgramImage) -> Result<Self, Box<dyn Error>>

Maps one program image and creates its fixed high guest stack.

Source

pub fn as_abi_mut(&mut self) -> *mut GuestMemoryAbi

Refreshes raw pointers only when mappings changed, which keeps normal dispatch inexpensive.

Source

pub fn map_program( &mut self, program: &ProgramImage, ) -> Result<(), Box<dyn Error>>

Maps the main image at its linked addresses and sets the initial heap end.

Source

pub fn map_program_at( &mut self, program: &ProgramImage, bias: u64, ) -> Result<(), Box<dyn Error>>

Maps an image with an address bias so a position-independent loader can coexist with it.

Source

pub fn map_zeroed( &mut self, base: u64, size: u64, perms: PagePerms, ) -> Result<(), Box<dyn Error>>

Ensures that all pages in a byte range exist, start with zero, and include perms.

Source

pub fn map_bytes( &mut self, base: u64, bytes: &[u8], perms: PagePerms, ) -> Result<(), Box<dyn Error>>

Copies image bytes into mapped pages without requiring guest write permission.

Source

pub fn replace_mapping( &mut self, base: u64, size: u64, perms: PagePerms, bytes: &[u8], ) -> Result<(), Box<dyn Error>>

Replaces complete pages so fixed mappings cannot retain old bytes or permissions.

Source

pub fn protect(&mut self, base: u64, size: u64, perms: PagePerms) -> bool

Replaces permissions on each mapped page in an aligned range.

The function returns false for an invalid range or a missing page. It can change an earlier page before it finds a missing later page.

Source

pub fn unmap(&mut self, base: u64, size: u64) -> Result<(), Box<dyn Error>>

Removes all pages in an aligned, half-open range.

Source

pub fn find_free_range(&self, start: u64, size: u64) -> Option<u64>

Finds the first page-aligned free range at or after start.

Source

pub fn range_is_free(&self, base: u64, size: u64) -> bool

Tests whether an aligned, nonempty range has no mapped page.

Source

pub fn load_le(&self, addr: u64, size: usize) -> Option<u64>

Loads at most eight little-endian bytes when the full range is readable.

Source

pub fn load_bytes(&self, addr: u64, size: usize) -> Option<Vec<u8>>

Copies a readable guest range and returns None if any byte is unavailable.

Source

pub fn fetch_u16(&self, addr: u64) -> Option<u16>

Fetches one little-endian 16-bit instruction parcel with execute permission.

Source

pub fn fetch_u32(&self, addr: u64) -> Option<u32>

Fetches one little-endian 32-bit instruction word with execute permission.

Source

pub fn executable_end(&self, addr: u64) -> Option<u64>

Finds the exclusive end of consecutive executable pages that contain addr.

Source

pub fn store_le(&mut self, addr: u64, size: usize, value: u64) -> bool

Stores at most eight little-endian bytes and records each changed page.

The store is not atomic. It can change initial bytes before a later byte fails.

Source

pub fn store_bytes(&mut self, addr: u64, bytes: &[u8]) -> bool

Copies bytes to writable guest pages and records each changed page.

The store is not atomic. It can change an initial page span before a later span fails.

Source

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

Tests execute permission for the page that contains addr.

Source

pub fn mappings(&self) -> Vec<(u64, u64, PagePerms)>

Returns adjacent pages with equal permissions as half-open mapping ranges.

Trait Implementations§

Source§

impl Clone for GuestMemory

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 GuestMemory

Source§

fn default() -> Self

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

Auto Trait Implementations§

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.