Trait ostd::mm::VmIo

source ·
pub trait VmIo: Send + Sync {
    // Required methods
    fn read_bytes(&self, offset: usize, buf: &mut [u8]) -> Result<()>;
    fn write_bytes(&self, offset: usize, buf: &[u8]) -> Result<()>;

    // Provided methods
    fn read_val<T: Pod>(&self, offset: usize) -> Result<T> { ... }
    fn read_slice<T: Pod>(&self, offset: usize, slice: &mut [T]) -> Result<()> { ... }
    fn write_val<T: Pod>(&self, offset: usize, new_val: &T) -> Result<()> { ... }
    fn write_slice<T: Pod>(&self, offset: usize, slice: &[T]) -> Result<()> { ... }
    fn write_vals<'a, T: Pod + 'a, I: Iterator<Item = &'a T>>(
        &self,
        offset: usize,
        iter: I,
        align: usize,
    ) -> Result<usize> { ... }
}
Expand description

A trait that enables reading/writing data from/to a VM object, e.g., VmSpace, FrameVec, and Frame.

§Concurrency

The methods may be executed by multiple concurrent reader and writer threads. In this case, if the results of concurrent reads or writes desire predictability or atomicity, the users should add extra mechanism for such properties.

Required Methods§

source

fn read_bytes(&self, offset: usize, buf: &mut [u8]) -> Result<()>

Reads a specified number of bytes at a specified offset into a given buffer.

§No short reads

On success, the output buf must be filled with the requested data completely. If, for any reason, the requested data is only partially available, then the method shall return an error.

source

fn write_bytes(&self, offset: usize, buf: &[u8]) -> Result<()>

Writes a specified number of bytes from a given buffer at a specified offset.

§No short writes

On success, the input buf must be written to the VM object entirely. If, for any reason, the input data can only be written partially, then the method shall return an error.

Provided Methods§

source

fn read_val<T: Pod>(&self, offset: usize) -> Result<T>

Reads a value of a specified type at a specified offset.

source

fn read_slice<T: Pod>(&self, offset: usize, slice: &mut [T]) -> Result<()>

Reads a slice of a specified type at a specified offset.

§No short reads

Similar to read_bytes.

source

fn write_val<T: Pod>(&self, offset: usize, new_val: &T) -> Result<()>

Writes a value of a specified type at a specified offset.

source

fn write_slice<T: Pod>(&self, offset: usize, slice: &[T]) -> Result<()>

Writes a slice of a specified type at a specified offset.

§No short write

Similar to write_bytes.

source

fn write_vals<'a, T: Pod + 'a, I: Iterator<Item = &'a T>>( &self, offset: usize, iter: I, align: usize, ) -> Result<usize>

Writes a sequence of values given by an iterator (iter) from the specified offset (offset).

The write process stops until the VM object does not have enough remaining space or the iterator returns None. If any value is written, the function returns Ok(nr_written), where nr_written is the number of the written values.

The offset of every value written by this method is aligned to the align-byte boundary. Naturally, when align equals to 0 or 1, then the argument takes no effect: the values will be written in the most compact way.

§Example

Initializes an VM object with the same value can be done easily with write_values.

use core::iter::self;

let _nr_values = vm_obj.write_vals(0, iter::repeat(0_u32), 0).unwrap();
§Panics

This method panics if align is greater than two, but not a power of two, in release mode.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<T: VmIo> VmIo for &T

source§

fn read_bytes(&self, offset: usize, buf: &mut [u8]) -> Result<()>

source§

fn read_val<F: Pod>(&self, offset: usize) -> Result<F>

source§

fn read_slice<F: Pod>(&self, offset: usize, slice: &mut [F]) -> Result<()>

source§

fn write_bytes(&self, offset: usize, buf: &[u8]) -> Result<()>

source§

fn write_val<F: Pod>(&self, offset: usize, new_val: &F) -> Result<()>

source§

fn write_slice<F: Pod>(&self, offset: usize, slice: &[F]) -> Result<()>

source§

impl<T: VmIo> VmIo for &mut T

source§

fn read_bytes(&self, offset: usize, buf: &mut [u8]) -> Result<()>

source§

fn read_val<F: Pod>(&self, offset: usize) -> Result<F>

source§

fn read_slice<F: Pod>(&self, offset: usize, slice: &mut [F]) -> Result<()>

source§

fn write_bytes(&self, offset: usize, buf: &[u8]) -> Result<()>

source§

fn write_val<F: Pod>(&self, offset: usize, new_val: &F) -> Result<()>

source§

fn write_slice<F: Pod>(&self, offset: usize, slice: &[F]) -> Result<()>

source§

impl<T: VmIo> VmIo for Arc<T>

source§

fn read_bytes(&self, offset: usize, buf: &mut [u8]) -> Result<()>

source§

fn read_val<F: Pod>(&self, offset: usize) -> Result<F>

source§

fn read_slice<F: Pod>(&self, offset: usize, slice: &mut [F]) -> Result<()>

source§

fn write_bytes(&self, offset: usize, buf: &[u8]) -> Result<()>

source§

fn write_val<F: Pod>(&self, offset: usize, new_val: &F) -> Result<()>

source§

fn write_slice<F: Pod>(&self, offset: usize, slice: &[F]) -> Result<()>

source§

impl<T: VmIo> VmIo for Box<T>

source§

fn read_bytes(&self, offset: usize, buf: &mut [u8]) -> Result<()>

source§

fn read_val<F: Pod>(&self, offset: usize) -> Result<F>

source§

fn read_slice<F: Pod>(&self, offset: usize, slice: &mut [F]) -> Result<()>

source§

fn write_bytes(&self, offset: usize, buf: &[u8]) -> Result<()>

source§

fn write_val<F: Pod>(&self, offset: usize, new_val: &F) -> Result<()>

source§

fn write_slice<F: Pod>(&self, offset: usize, slice: &[F]) -> Result<()>

Implementors§