MemoryAccessor

Trait MemoryAccessor 

Source
pub trait MemoryAccessor {
    // Required methods
    fn read_memory<'a>(
        &self,
        addr: UserAddress,
        bytes: &'a mut [MaybeUninit<u8>],
    ) -> Result<&'a mut [u8], Errno>;
    fn read_memory_partial_until_null_byte<'a>(
        &self,
        addr: UserAddress,
        bytes: &'a mut [MaybeUninit<u8>],
    ) -> Result<&'a mut [u8], Errno>;
    fn read_memory_partial<'a>(
        &self,
        addr: UserAddress,
        bytes: &'a mut [MaybeUninit<u8>],
    ) -> Result<&'a mut [u8], Errno>;
    fn write_memory(
        &self,
        addr: UserAddress,
        bytes: &[u8],
    ) -> Result<usize, Errno>;
    fn write_memory_partial(
        &self,
        addr: UserAddress,
        bytes: &[u8],
    ) -> Result<usize, Errno>;
    fn zero(&self, addr: UserAddress, length: usize) -> Result<usize, Errno>;
}

Required Methods§

Source

fn read_memory<'a>( &self, addr: UserAddress, bytes: &'a mut [MaybeUninit<u8>], ) -> Result<&'a mut [u8], Errno>

Reads exactly bytes.len() bytes of memory from addr into bytes.

In case of success, the number of bytes read will always be bytes.len().

Consider using MemoryAccessorExt::read_memory_to_* methods if you do not require control over the allocation.

Source

fn read_memory_partial_until_null_byte<'a>( &self, addr: UserAddress, bytes: &'a mut [MaybeUninit<u8>], ) -> Result<&'a mut [u8], Errno>

Reads bytes starting at addr, continuing until either a null byte is read, bytes.len() bytes have been read or no more bytes can be read from the target.

This is used, for example, to read null-terminated strings where the exact length is not known, only the maximum length is.

Returns the bytes that have been read to on success.

Source

fn read_memory_partial<'a>( &self, addr: UserAddress, bytes: &'a mut [MaybeUninit<u8>], ) -> Result<&'a mut [u8], Errno>

Reads bytes starting at addr, continuing until either bytes.len() bytes have been read or no more bytes can be read from the target.

This is used, for example, to read null-terminated strings where the exact length is not known, only the maximum length is.

Consider using MemoryAccessorExt::read_memory_partial_to_* methods if you do not require control over the allocation.

Source

fn write_memory(&self, addr: UserAddress, bytes: &[u8]) -> Result<usize, Errno>

Writes the provided bytes to addr.

In case of success, the number of bytes written will always be bytes.len().

§Parameters
  • addr: The address to write to.
  • bytes: The bytes to write from.
Source

fn write_memory_partial( &self, addr: UserAddress, bytes: &[u8], ) -> Result<usize, Errno>

Writes bytes starting at addr, continuing until either bytes.len() bytes have been written or no more bytes can be written.

§Parameters
  • addr: The address to write to.
  • bytes: The bytes to write from.
Source

fn zero(&self, addr: UserAddress, length: usize) -> Result<usize, Errno>

Writes zeros starting at addr and continuing for length bytes.

Returns the number of bytes that were zeroed.

Trait Implementations§

Source§

impl MemoryAccessorExt for dyn MemoryAccessor + '_

Source§

fn read_memory_to_slice( &self, addr: UserAddress, bytes: &mut [u8], ) -> Result<(), Errno>

Reads exactly bytes.len() bytes of memory from addr into bytes. Read more
Source§

fn read_memory_to_vec( &self, addr: UserAddress, len: usize, ) -> Result<Vec<u8>, Errno>

Read exactly len bytes of memory, returning them as a a Vec.
Source§

fn read_memory_partial_to_vec( &self, addr: UserAddress, max_len: usize, ) -> Result<Vec<u8>, Errno>

Read up to max_len bytes from addr, returning them as a Vec.
Source§

fn read_memory_to_array<const N: usize>( &self, addr: UserAddress, ) -> Result<[u8; N], Errno>

Read exactly N bytes from addr, returning them as an array.
Source§

fn read_buffer(&self, buffer: &UserBuffer) -> Result<Vec<u8>, Errno>

Read the contents of buffer, returning them as a Vec.
Source§

fn read_object<T: FromBytes>(&self, user: UserRef<T>) -> Result<T, Errno>

Read an instance of T from user.
Source§

fn read_multi_arch_ptr<T64, T32>( &self, user: MultiArchUserRef<MultiArchUserRef<T64, T32>, MultiArchUserRef<T64, T32>>, ) -> Result<MultiArchUserRef<T64, T32>, Errno>

Source§

fn read_multi_arch_object<T, T64: FromBytes + TryInto<T>, T32: FromBytes + TryInto<T>>( &self, user: MappingMultiArchUserRef<T, T64, T32>, ) -> Result<T, Errno>

Read an instance of T64 from user where the object has a different representation in 32 and 64 bits.
Source§

fn read_multi_arch_objects_to_vec<T, T64: FromBytes + TryInto<T>, T32: FromBytes + TryInto<T>>( &self, user: MappingMultiArchUserRef<T, T64, T32>, len: usize, ) -> Result<Vec<T>, Errno>

Read exactly len objects from user, returning them as a Vec.
Source§

fn read_object_partial<T: FromBytes>( &self, user: UserRef<T>, partial_size: usize, ) -> Result<T, Errno>

Reads the first partial bytes of an object, leaving any remainder 0-filled. Read more
Source§

fn read_objects<'a, T: FromBytes>( &self, user: UserRef<T>, objects: &'a mut [MaybeUninit<T>], ) -> Result<&'a mut [T], Errno>

Read exactly objects.len() objects into objects from user.
Source§

fn read_objects_to_slice<T: FromBytes>( &self, user: UserRef<T>, objects: &mut [T], ) -> Result<(), Errno>

Read exactly objects.len() objects into objects from user.
Source§

fn read_objects_to_vec<T: FromBytes>( &self, user: UserRef<T>, len: usize, ) -> Result<Vec<T>, Errno>

Read exactly len objects from user, returning them as a Vec.
Source§

fn read_objects_to_smallvec<T: Clone + FromBytes, const N: usize>( &self, user: UserRef<T>, len: usize, ) -> Result<SmallVec<[T; N]>, Errno>

Read exactly len objects from user, returning them as a SmallVec.
Source§

fn read_objects_to_array<T: Copy + FromBytes, const N: usize>( &self, user: UserRef<T>, ) -> Result<[T; N], Errno>

Read exactly N objects from user, returning them as an array.
Source§

fn read_iovec<T: Copy + Eq + IntoBytes + FromBytes + Immutable + TryInto<usize>>( &self, iovec_addr: IOVecPtr, iovec_count: UserValue<T>, ) -> Result<UserBuffers, Errno>

Read exactly iovec_count UserBuffers from iovec_addr. Read more
Source§

fn read_c_string_to_vec( &self, string: UserCString, max_size: usize, ) -> Result<FsString, Errno>

Read up to max_size bytes from string, stopping at the first discovered null byte and returning the results as a Vec.
Source§

fn read_path(&self, path: UserCString) -> Result<FsString, Errno>

Read a path from path, returning it as a FsString. Read more
Source§

fn read_path_if_non_null(&self, path: UserCString) -> Result<FsString, Errno>

Read a path from path, returning it as a FsString, if the path is non-null. Read more
Source§

fn read_nul_delimited_c_string_list( &self, start: UserAddress, len: usize, ) -> Result<Vec<FsString>, Errno>

Read len bytes from start and parse the region as null-delimited CStrings, for example how argv is stored. Read more
Source§

fn read_c_string<'a>( &self, string: UserCString, buffer: &'a mut [MaybeUninit<u8>], ) -> Result<&'a FsStr, Errno>

Read up to buffer.len() bytes from string, stopping at the first discovered null byte and returning the result as a slice that ends before that null. Read more
Source§

fn read_c_string_if_non_null<'a>( &self, addr: UserCString, buffer: &'a mut [MaybeUninit<u8>], ) -> Result<&'a FsStr, Errno>

Returns a default initialized string if addr is null, otherwise behaves as read_c_string.
Source§

fn write_object<T: IntoBytes + Immutable>( &self, user: UserRef<T>, object: &T, ) -> Result<usize, Errno>

Source§

fn write_objects<T: IntoBytes + Immutable>( &self, user: UserRef<T>, objects: &[T], ) -> Result<usize, Errno>

Source§

fn write_multi_arch_ptr<Addr, T64, T32>( &self, user: Addr, object: MultiArchUserRef<T64, T32>, ) -> Result<usize, Errno>
where Addr: Into<UserAddress>,

Source§

fn write_multi_arch_object<T, T64: IntoBytes + Immutable + TryFrom<T>, T32: IntoBytes + Immutable + TryFrom<T>>( &self, user: MappingMultiArchUserRef<T, T64, T32>, object: T, ) -> Result<usize, Errno>

Implementors§