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: u64Gives the first address after the current guest heap.
stack_top: u64Gives the fixed exclusive stack top used to build the initial process stack.
Implementations§
Source§impl GuestMemory
impl GuestMemory
Sourcepub fn new() -> Self
pub fn new() -> Self
Starts with no mappings so ELF loading can define all initial permissions.
Sourcepub fn from_program(program: &ProgramImage) -> Result<Self, Box<dyn Error>>
pub fn from_program(program: &ProgramImage) -> Result<Self, Box<dyn Error>>
Maps one program image and creates its fixed high guest stack.
Sourcepub fn as_abi_mut(&mut self) -> *mut GuestMemoryAbi
pub fn as_abi_mut(&mut self) -> *mut GuestMemoryAbi
Refreshes raw pointers only when mappings changed, which keeps normal dispatch inexpensive.
Sourcepub fn map_program(
&mut self,
program: &ProgramImage,
) -> Result<(), Box<dyn Error>>
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.
Sourcepub fn map_program_at(
&mut self,
program: &ProgramImage,
bias: u64,
) -> Result<(), Box<dyn Error>>
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.
Sourcepub fn map_zeroed(
&mut self,
base: u64,
size: u64,
perms: PagePerms,
) -> Result<(), Box<dyn Error>>
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.
Sourcepub fn map_bytes(
&mut self,
base: u64,
bytes: &[u8],
perms: PagePerms,
) -> Result<(), Box<dyn Error>>
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.
Sourcepub fn replace_mapping(
&mut self,
base: u64,
size: u64,
perms: PagePerms,
bytes: &[u8],
) -> Result<(), Box<dyn Error>>
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.
Sourcepub fn protect(&mut self, base: u64, size: u64, perms: PagePerms) -> bool
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.
Sourcepub fn unmap(&mut self, base: u64, size: u64) -> Result<(), Box<dyn Error>>
pub fn unmap(&mut self, base: u64, size: u64) -> Result<(), Box<dyn Error>>
Removes all pages in an aligned, half-open range.
Sourcepub fn find_free_range(&self, start: u64, size: u64) -> Option<u64>
pub fn find_free_range(&self, start: u64, size: u64) -> Option<u64>
Finds the first page-aligned free range at or after start.
Sourcepub fn range_is_free(&self, base: u64, size: u64) -> bool
pub fn range_is_free(&self, base: u64, size: u64) -> bool
Tests whether an aligned, nonempty range has no mapped page.
Sourcepub fn load_le(&self, addr: u64, size: usize) -> Option<u64>
pub fn load_le(&self, addr: u64, size: usize) -> Option<u64>
Loads at most eight little-endian bytes when the full range is readable.
Sourcepub fn load_bytes(&self, addr: u64, size: usize) -> Option<Vec<u8>>
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.
Sourcepub fn fetch_u16(&self, addr: u64) -> Option<u16>
pub fn fetch_u16(&self, addr: u64) -> Option<u16>
Fetches one little-endian 16-bit instruction parcel with execute permission.
Sourcepub fn fetch_u32(&self, addr: u64) -> Option<u32>
pub fn fetch_u32(&self, addr: u64) -> Option<u32>
Fetches one little-endian 32-bit instruction word with execute permission.
Sourcepub fn executable_end(&self, addr: u64) -> Option<u64>
pub fn executable_end(&self, addr: u64) -> Option<u64>
Finds the exclusive end of consecutive executable pages that contain addr.
Sourcepub fn store_le(&mut self, addr: u64, size: usize, value: u64) -> bool
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.
Sourcepub fn store_bytes(&mut self, addr: u64, bytes: &[u8]) -> bool
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.
Sourcepub fn can_execute(&self, addr: u64) -> bool
pub fn can_execute(&self, addr: u64) -> bool
Tests execute permission for the page that contains addr.