#[repr(C, align(32))]pub struct MemoryRegion {
pub host_addr: Cell<u64>,
pub vm_addr: u64,
pub vm_addr_end: u64,
pub len: u64,
pub vm_gap_shift: u8,
pub state: Cell<MemoryState>,
}
Expand description
Memory region for bounds checking and address translation
Fields§
§host_addr: Cell<u64>
start host address
vm_addr: u64
start virtual address
vm_addr_end: u64
end virtual address
len: u64
Length in bytes
vm_gap_shift: u8
Size of regular gaps as bit shift (63 means this region is continuous)
state: Cell<MemoryState>
Whether the region is readonly, writable or must be copied before writing
Implementations§
Source§impl MemoryRegion
impl MemoryRegion
Sourcepub fn new_for_testing(
slice: &[u8],
vm_addr: u64,
vm_gap_size: u64,
state: MemoryState,
) -> Self
pub fn new_for_testing( slice: &[u8], vm_addr: u64, vm_gap_size: u64, state: MemoryState, ) -> Self
Only to be used in tests and benches
Sourcepub fn new_readonly(slice: &[u8], vm_addr: u64) -> Self
pub fn new_readonly(slice: &[u8], vm_addr: u64) -> Self
Creates a new readonly MemoryRegion from a slice
Sourcepub fn new_writable(slice: &mut [u8], vm_addr: u64) -> Self
pub fn new_writable(slice: &mut [u8], vm_addr: u64) -> Self
Creates a new writable MemoryRegion from a mutable slice
Sourcepub fn new_cow(slice: &[u8], vm_addr: u64, cow_id: u64) -> Self
pub fn new_cow(slice: &[u8], vm_addr: u64, cow_id: u64) -> Self
Creates a new copy on write MemoryRegion.
The region is made writable
Sourcepub fn new_writable_gapped(
slice: &mut [u8],
vm_addr: u64,
vm_gap_size: u64,
) -> Self
pub fn new_writable_gapped( slice: &mut [u8], vm_addr: u64, vm_gap_size: u64, ) -> Self
Creates a new writable gapped MemoryRegion from a mutable slice
Sourcepub fn vm_to_host(&self, vm_addr: u64, len: u64) -> ProgramResult
pub fn vm_to_host(&self, vm_addr: u64, len: u64) -> ProgramResult
Convert a virtual machine address into a host address
Trait Implementations§
Source§impl Debug for MemoryRegion
impl Debug for MemoryRegion
Source§impl Default for MemoryRegion
impl Default for MemoryRegion
Source§fn default() -> MemoryRegion
fn default() -> MemoryRegion
Returns the “default value” for a type. Read more
Source§impl Ord for MemoryRegion
impl Ord for MemoryRegion
Source§impl PartialEq for MemoryRegion
impl PartialEq for MemoryRegion
Source§impl PartialOrd for MemoryRegion
impl PartialOrd for MemoryRegion
impl Eq for MemoryRegion
impl StructuralPartialEq for MemoryRegion
Auto Trait Implementations§
impl !Freeze for MemoryRegion
impl !RefUnwindSafe for MemoryRegion
impl Send for MemoryRegion
impl !Sync for MemoryRegion
impl Unpin for MemoryRegion
impl UnwindSafe for MemoryRegion
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more