pub struct ExclusiveSharedMemory { /* private fields */ }
Expand description
These three structures represent various phases of the lifecycle of a memory buffer that is shared with the guest. An ExclusiveSharedMemory is used for certain operations that unrestrictedly write to the shared memory, including setting it up and taking snapshots.
Implementations§
Sourcepub fn new(min_size_bytes: usize) -> Result<Self>
pub fn new(min_size_bytes: usize) -> Result<Self>
Create a new region of shared memory with the given minimum size in bytes. The region will be surrounded by guard pages.
Return Err
if shared memory could not be allocated.
Sourcepub fn as_slice<'a>(&'a self) -> &'a [u8] ⓘ
pub fn as_slice<'a>(&'a self) -> &'a [u8] ⓘ
Internal helper method to get the backing memory as a slice.
§Safety
See the discussion on as_mut_slice, with the third point replaced by:
-
The memory referenced by the returned slice must not be mutated for the duration of lifetime ’a, except inside an UnsafeCell.
Host accesses from Safe Rust necessarily follow this rule, because the returned slice’s lifetime is the same as that of a borrow of self, preventing mutations via other methods.
Sourcepub fn copy_from_slice(&mut self, src: &[u8], offset: usize) -> Result<()>
pub fn copy_from_slice(&mut self, src: &[u8], offset: usize) -> Result<()>
Copies all bytes from src
to self
starting at offset
Sourcepub fn build(self) -> (HostSharedMemory, GuestSharedMemory)
pub fn build(self) -> (HostSharedMemory, GuestSharedMemory)
Convert the ExclusiveSharedMemory, which may be freely modified, into a GuestSharedMemory, which may be somewhat freely modified (mostly by the guest), and a HostSharedMemory, which may only make certain kinds of accesses that do not race in the presence of malicious code inside the guest mutating the GuestSharedMemory.
Trait Implementations§
Source§fn region(&self) -> &HostMapping
fn region(&self) -> &HostMapping
Source§fn with_exclusivity<T, F: FnOnce(&mut ExclusiveSharedMemory) -> T>(
&mut self,
f: F,
) -> Result<T>
fn with_exclusivity<T, F: FnOnce(&mut ExclusiveSharedMemory) -> T>( &mut self, f: F, ) -> Result<T>
Source§fn base_addr(&self) -> usize
fn base_addr(&self) -> usize
unsafe
because doing anything with this
pointer itself requires unsafe
.Source§fn base_ptr(&self) -> *mut u8
fn base_ptr(&self) -> *mut u8
unsafe
because doing anything with
this pointer itself requires unsafe
.Source§fn mem_size(&self) -> usize
fn mem_size(&self) -> usize
self
.
The returned size does not include the size of the surrounding
guard pages.