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
admitis refused by every access, with nothing read and nothing written. - The other side may write any byte at any moment.
readreturns a snapshot; it need not be coherent across bytes, and it must not be undefined behaviour for it to race a write. load_u16andstore_u16are 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§
Sourcefn admits(&self, at: u64, len: u64, access: Access) -> bool
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.
Sourcefn read(&self, at: u64, target: &mut [u8]) -> Result<(), MemoryFault>
fn read(&self, at: u64, target: &mut [u8]) -> Result<(), MemoryFault>
Snapshot target.len() bytes at at.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".