Struct GuestMemoryHybrid

Source
pub struct GuestMemoryHybrid<B = ()> { /* private fields */ }
Expand description

GuestMemory implementation that manage hybrid types of guest memory regions.

Represents the entire physical memory of the guest by tracking all its memory regions. Each region is an instance of GuestRegionHybrid.

Implementations§

Source§

impl<B: NewBitmap> GuestMemoryHybrid<B>

Source

pub fn new() -> Self

Creates an empty GuestMemoryHybrid instance.

Source§

impl<B: Bitmap> GuestMemoryHybrid<B>

Source

pub fn from_regions(regions: Vec<GuestRegionHybrid<B>>) -> Result<Self, Error>

Creates a new GuestMemoryHybrid from a vector of regions.

§Arguments
  • regions - The vector of regions. The regions shouldn’t overlap and they should be sorted by the starting address.
Source

pub fn from_arc_regions( regions: Vec<Arc<GuestRegionHybrid<B>>>, ) -> Result<Self, Error>

Creates a new GuestMemoryHybrid from a vector of Arc regions.

Similar to the constructor from_regions() as it returns a GuestMemoryHybrid. The need for this constructor is to provide a way for consumer of this API to create a new GuestMemoryHybrid based on existing regions coming from an existing GuestMemoryHybrid instance.

§Arguments
  • regions - The vector of Arc regions. The regions shouldn’t overlap and they should be sorted by the starting address.
Source

pub fn insert_region( &self, region: Arc<GuestRegionHybrid<B>>, ) -> Result<GuestMemoryHybrid<B>, Error>

Insert a region into the GuestMemoryHybrid object and return a new GuestMemoryHybrid.

§Arguments
  • region: the memory region to insert into the guest memory object.
Source

pub fn remove_region( &self, base: GuestAddress, size: GuestUsize, ) -> Result<(GuestMemoryHybrid<B>, Arc<GuestRegionHybrid<B>>), Error>

Remove a region into the GuestMemoryHybrid object and return a new GuestMemoryHybrid on success, together with the removed region.

§Arguments
  • base: base address of the region to be removed
  • size: size of the region to be removed

Trait Implementations§

Source§

impl<B: Clone> Clone for GuestMemoryHybrid<B>

Source§

fn clone(&self) -> GuestMemoryHybrid<B>

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<B: Debug> Debug for GuestMemoryHybrid<B>

Source§

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

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

impl<B: Default> Default for GuestMemoryHybrid<B>

Source§

fn default() -> GuestMemoryHybrid<B>

Returns the “default value” for a type. Read more
Source§

impl<B: Bitmap + 'static> GuestMemory for GuestMemoryHybrid<B>

Source§

type R = GuestRegionHybrid<B>

Type of objects hosted by the address space.
Source§

type I = GuestMemoryHybrid<B>

Lifetime generic associated iterators. Usually this is just Self.
Source§

fn num_regions(&self) -> usize

Returns the number of regions in the collection.
Source§

fn find_region(&self, addr: GuestAddress) -> Option<&GuestRegionHybrid<B>>

Returns the region containing the specified address or None.
Source§

fn iter(&self) -> Iter<'_, B>

Gets an iterator over the entries in the collection. Read more
Source§

fn with_regions<F, E>(&self, cb: F) -> Result<(), E>
where F: Fn(usize, &Self::R) -> Result<(), E>,

👎Deprecated since 0.6.0: Use .iter() instead
Perform the specified action on each region. Read more
Source§

fn with_regions_mut<F, E>(&self, cb: F) -> Result<(), E>
where F: FnMut(usize, &Self::R) -> Result<(), E>,

👎Deprecated since 0.6.0: Use .iter() instead
Perform the specified action on each region mutably. Read more
Source§

fn map_and_fold<F, G, T>(&self, init: T, mapf: F, foldf: G) -> T
where F: Fn((usize, &Self::R)) -> T, G: Fn(T, T) -> T,

👎Deprecated since 0.6.0: Use .iter() instead
Applies two functions, specified as callbacks, on the inner memory regions. Read more
Source§

fn last_addr(&self) -> GuestAddress

Returns the maximum (inclusive) address managed by the GuestMemory. Read more
Source§

fn to_region_addr( &self, addr: GuestAddress, ) -> Option<(&Self::R, MemoryRegionAddress)>

Tries to convert an absolute address to a relative address within the corresponding region. Read more
Source§

fn address_in_range(&self, addr: GuestAddress) -> bool

Returns true if the given address is present within the memory of the guest.
Source§

fn check_address(&self, addr: GuestAddress) -> Option<GuestAddress>

Returns the given address if it is present within the memory of the guest.
Source§

fn check_range(&self, base: GuestAddress, len: usize) -> bool

Check whether the range [base, base + len) is valid.
Source§

fn checked_offset( &self, base: GuestAddress, offset: usize, ) -> Option<GuestAddress>

Returns the address plus the offset if it is present within the memory of the guest.
Source§

fn try_access<F>( &self, count: usize, addr: GuestAddress, f: F, ) -> Result<usize, Error>

Invokes callback f to handle data in the address range [addr, addr + count). Read more
Source§

fn get_host_address(&self, addr: GuestAddress) -> Result<*mut u8, Error>

Get the host virtual address corresponding to the guest address. Read more
Source§

fn get_slice( &self, addr: GuestAddress, count: usize, ) -> Result<VolatileSlice<'_, <<Self::R as GuestMemoryRegion>::B as WithBitmapSlice<'_>>::S>, Error>

Returns a VolatileSlice of count bytes starting at addr.
Source§

impl<'a, B: 'a> GuestMemoryIterator<'a, GuestRegionHybrid<B>> for GuestMemoryHybrid<B>

Source§

type Iter = Iter<'a, B>

Type of the iter method’s return value.

Auto Trait Implementations§

§

impl<B> Freeze for GuestMemoryHybrid<B>

§

impl<B> RefUnwindSafe for GuestMemoryHybrid<B>
where B: RefUnwindSafe,

§

impl<B = ()> !Send for GuestMemoryHybrid<B>

§

impl<B = ()> !Sync for GuestMemoryHybrid<B>

§

impl<B> Unpin for GuestMemoryHybrid<B>

§

impl<B> UnwindSafe for GuestMemoryHybrid<B>
where B: RefUnwindSafe,

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> Bytes<GuestAddress> for T
where T: GuestMemory + ?Sized,

Source§

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

§Examples
  • Write a slice at guestaddress 0x1000. (uses the backend-mmap feature)
gm.write_slice(&[1, 2, 3, 4, 5], start_addr)
    .expect("Could not write slice to guest memory");
Source§

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

§Examples
  • Read a slice of length 16 at guestaddress 0x1000. (uses the backend-mmap feature)
let start_addr = GuestAddress(0x1000);
let mut gm = GuestMemoryMmap::<()>::from_ranges(&vec![(start_addr, 0x400)])
    .expect("Could not create guest memory");
let buf = &mut [0u8; 16];

gm.read_slice(buf, start_addr)
    .expect("Could not read slice from guest memory");
Source§

fn read_from<F>( &self, addr: GuestAddress, src: &mut F, count: usize, ) -> Result<usize, Error>
where F: Read,

§Examples
  • Read bytes from /dev/urandom (uses the backend-mmap feature)
let mut file = File::open(Path::new("/dev/urandom")).expect("Could not open /dev/urandom");

gm.read_from(addr, &mut file, 128)
    .expect("Could not read from /dev/urandom into guest memory");

let read_addr = addr.checked_add(8).expect("Could not compute read address");
let rand_val: u32 = gm
    .read_obj(read_addr)
    .expect("Could not read u32 val from /dev/urandom");
Source§

fn write_to<F>( &self, addr: GuestAddress, dst: &mut F, count: usize, ) -> Result<usize, Error>
where F: Write,

§Examples
  • Write 128 bytes to /dev/null (uses the backend-mmap feature)
let mut file = OpenOptions::new()
    .write(true)
    .open("/dev/null")
    .expect("Could not open /dev/null");

gm.write_to(start_addr, &mut file, 128)
    .expect("Could not write 128 bytes to the provided address");
Source§

fn write_all_to<F>( &self, addr: GuestAddress, dst: &mut F, count: usize, ) -> Result<(), Error>
where F: Write,

§Examples
  • Write 128 bytes to /dev/null (uses the backend-mmap feature)
let mut file = OpenOptions::new()
    .write(true)
    .open("/dev/null")
    .expect("Could not open /dev/null");

gm.write_all_to(start_addr, &mut file, 128)
    .expect("Could not write 128 bytes to the provided address");
Source§

type E = Error

Associated error codes
Source§

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

Writes a slice into the container at addr. Read more
Source§

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

Reads data from the container at addr into a slice. Read more
Source§

fn read_exact_from<F>( &self, addr: GuestAddress, src: &mut F, count: usize, ) -> Result<(), Error>
where F: Read,

Reads exactly count bytes from an object and writes them into the container at addr. Read more
Source§

fn store<O>( &self, val: O, addr: GuestAddress, order: Ordering, ) -> Result<(), Error>
where O: AtomicAccess,

Atomically store a value at the specified address.
Source§

fn load<O>(&self, addr: GuestAddress, order: Ordering) -> Result<O, Error>
where O: AtomicAccess,

Atomically load a value from the specified address.
Source§

fn write_obj<T>(&self, val: T, addr: A) -> Result<(), Self::E>
where T: ByteValued,

Writes an object into the container at addr. Read more
Source§

fn read_obj<T>(&self, addr: A) -> Result<T, Self::E>
where T: ByteValued,

Reads an object from the container at addr. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.