Skip to main content

SharedMemory

Trait SharedMemory 

Source
pub trait SharedMemory {
    // Required methods
    fn admits(&self, at: u64, len: u64, access: Access) -> bool;
    fn read(&self, at: u64, target: &mut [u8]) -> Result<(), MemoryFault>;
    fn write(&self, at: u64, source: &[u8]) -> Result<(), MemoryFault>;
    fn load_u16(&self, at: u64) -> Result<u16, MemoryFault>;
    fn store_u16(&self, at: u64, value: u16) -> Result<(), MemoryFault>;
}
Expand description

The memory a driver and a device share, as one side reaches it.

Addresses are device addresses: the numbers a driver writes into a descriptor and into the three ring-address registers. Each side maps them its own way — an offset into a window the driver lent, a guest-physical address, an I/O virtual address resolved through the driver’s own mapping of its DMA memory — and that mapping, with whatever unsafe it needs, is the implementation’s. Nothing in this crate forms a reference into the memory or holds an address across a call.

§What an implementation promises

  • A range it does not admit is refused by every access, with nothing read and nothing written.
  • The other side may write any byte at any moment. read returns a snapshot; it need not be coherent across bytes, and it must not be undefined behaviour for it to race a write.
  • load_u16 and store_u16 are the queue’s publication points. A store has release ordering: every write this side made before it is visible to the other side once it has loaded the word. A load has acquire ordering. Words are little-endian whatever the host is.

Required Methods§

Source

fn admits(&self, at: u64, len: u64, access: Access) -> bool

Whether len bytes at at may be accessed as access asks. A range that wraps the address space is never admitted; an empty one is.

Source

fn read(&self, at: u64, target: &mut [u8]) -> Result<(), MemoryFault>

Snapshot target.len() bytes at at.

Source

fn write(&self, at: u64, source: &[u8]) -> Result<(), MemoryFault>

Store source at at.

Source

fn load_u16(&self, at: u64) -> Result<u16, MemoryFault>

Load the little-endian u16 at at, acquire.

Source

fn store_u16(&self, at: u64, value: u16) -> Result<(), MemoryFault>

Store a little-endian u16 at at, release.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T: SharedMemory + ?Sized> SharedMemory for &T

Source§

fn admits(&self, at: u64, len: u64, access: Access) -> bool

Source§

fn read(&self, at: u64, target: &mut [u8]) -> Result<(), MemoryFault>

Source§

fn write(&self, at: u64, source: &[u8]) -> Result<(), MemoryFault>

Source§

fn load_u16(&self, at: u64) -> Result<u16, MemoryFault>

Source§

fn store_u16(&self, at: u64, value: u16) -> Result<(), MemoryFault>

Implementors§