Skip to main content

SliceGuestMemory

Struct SliceGuestMemory 

Source
pub struct SliceGuestMemory { /* private fields */ }
Expand description

In-process GuestMemory implementation backed by a single contiguous Vec<u8> keyed at a fixed base guest address.

Useful for unit tests that need a real GuestMemory without standing up the HVF backend. Production hypervisor backends provide their own implementation that routes to mmap-backed regions.

Implementations§

Source§

impl SliceGuestMemory

Source

pub fn new(base: GuestAddress, size: usize) -> Self

Build a [base, base + size) region zero-filled at construction.

Source

pub fn from_bytes(base: GuestAddress, bytes: Vec<u8>) -> Self

Build a region pre-populated with bytes starting at base.

Source

pub fn base(&self) -> GuestAddress

Inclusive base address.

Source

pub fn size(&self) -> usize

Region size in bytes.

Trait Implementations§

Source§

impl Debug for SliceGuestMemory

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl GuestMemory for SliceGuestMemory

Source§

fn read(&self, addr: GuestAddress, buf: &mut [u8]) -> Result<()>

Read buf.len() bytes from addr into buf. Read more
Source§

fn write(&self, addr: GuestAddress, buf: &[u8]) -> Result<()>

Write buf.len() bytes from buf into guest memory at addr. Read more
Source§

fn read_u16_le(&self, addr: GuestAddress) -> Result<u16>

Read a little-endian u16 from addr. Read more
Source§

fn read_u32_le(&self, addr: GuestAddress) -> Result<u32>

Read a little-endian u32 from addr. Read more
Source§

fn read_u64_le(&self, addr: GuestAddress) -> Result<u64>

Read a little-endian u64 from addr. Read more
Source§

fn write_u16_le(&self, addr: GuestAddress, value: u16) -> Result<()>

Write a little-endian u16 to addr. Read more
Source§

fn write_u32_le(&self, addr: GuestAddress, value: u32) -> Result<()>

Write a little-endian u32 to addr. Read more
Source§

fn write_u64_le(&self, addr: GuestAddress, value: u64) -> Result<()>

Write a little-endian u64 to addr. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.