pub trait SharedMemory {
// Required methods
fn region(&self) -> &HostMapping;
fn with_exclusivity<T, F: FnOnce(&mut ExclusiveSharedMemory) -> T>(
&mut self,
f: F,
) -> Result<T>;
// Provided methods
fn base_addr(&self) -> usize { ... }
fn base_ptr(&self) -> *mut u8 { ... }
fn mem_size(&self) -> usize { ... }
fn raw_ptr(&self) -> *mut u8 { ... }
fn raw_mem_size(&self) -> usize { ... }
}
Expand description
A trait that abstracts over the particular kind of SharedMemory, used when invoking operations from Rust that absolutely must have exclusive control over the shared memory for correctness + performance, like snapshotting.
Required Methods§
Sourcefn region(&self) -> &HostMapping
fn region(&self) -> &HostMapping
Return a readonly reference to the host mapping backing this SharedMemory
Sourcefn 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>
Run some code with exclusive access to the SharedMemory underlying this. If the SharedMemory is not an ExclusiveSharedMemory, any concurrent accesses to the relevant HostSharedMemory/GuestSharedMemory may make this fail, or be made to fail by this, and should be avoided.
Provided Methods§
Sourcefn base_addr(&self) -> usize
fn base_addr(&self) -> usize
Return the base address of the host mapping of this
region. Following the general Rust philosophy, this does not
need to be marked as unsafe
because doing anything with this
pointer itself requires unsafe
.
Sourcefn base_ptr(&self) -> *mut u8
fn base_ptr(&self) -> *mut u8
Return the base address of the host mapping of this region as
a pointer. Following the general Rust philosophy, this does
not need to be marked as unsafe
because doing anything with
this pointer itself requires unsafe
.
Sourcefn mem_size(&self) -> usize
fn mem_size(&self) -> usize
Return the length of usable memory contained in self
.
The returned size does not include the size of the surrounding
guard pages.
Sourcefn raw_ptr(&self) -> *mut u8
fn raw_ptr(&self) -> *mut u8
Return the raw base address of the host mapping, including the guard pages.
Sourcefn raw_mem_size(&self) -> usize
fn raw_mem_size(&self) -> usize
Return the raw size of the host mapping, including the guard pages.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.