Skip to main content

SharedMemory

Trait SharedMemory 

Source
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 { ... }
    fn host_region_base(
        &self,
    ) -> <HostGuestMemoryRegion as MemoryRegionKind>::HostBaseType { ... }
    fn host_region_end(
        &self,
    ) -> <HostGuestMemoryRegion as MemoryRegionKind>::HostBaseType { ... }
    fn with_contents<T, F: FnOnce(&[u8]) -> T>(&mut self, f: F) -> Result<T> { ... }
    fn zero(&mut self) -> Result<()> { ... }
}
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§

Source

fn region(&self) -> &HostMapping

Return a readonly reference to the host mapping backing this SharedMemory

Source

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§

Source

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.

Source

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.

Source

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.

Source

fn raw_ptr(&self) -> *mut u8

Return the raw base address of the host mapping, including the guard pages.

Source

fn raw_mem_size(&self) -> usize

Return the raw size of the host mapping, including the guard pages.

Source

fn host_region_base( &self, ) -> <HostGuestMemoryRegion as MemoryRegionKind>::HostBaseType

Extract a base address that can be mapped into a VM for this SharedMemory.

On Linux this returns a raw usize pointer. On Windows it returns a HostRegionBase that carries the file-mapping handle metadata needed by WHP.

Source

fn host_region_end( &self, ) -> <HostGuestMemoryRegion as MemoryRegionKind>::HostBaseType

Return the end address of the host region (base + usable size).

Source

fn with_contents<T, F: FnOnce(&[u8]) -> T>(&mut self, f: F) -> Result<T>

Run some code that is allowed to access the contents of the SharedMemory as if it is a normal slice. By default, this is implemented via SharedMemory::with_exclusivity, which is the correct implementation for a memory that can be mutated, but a ReadonlySharedMemory, can support this.

Source

fn zero(&mut self) -> Result<()>

Zero a shared memory region

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.

Implementors§