GuestRegionCollection

Struct GuestRegionCollection 

Source
pub struct GuestRegionCollection<R> { /* private fields */ }
Expand description

GuestMemoryBackend implementation based on a homogeneous collection of GuestMemoryRegion implementations.

Represents a sorted set of non-overlapping physical guest memory regions.

Implementations§

Source§

impl<R: GuestMemoryRegion> GuestRegionCollection<R>

Source

pub fn new() -> Self

Creates an empty GuestMemoryMmap instance.

Source

pub fn from_regions(regions: Vec<R>) -> Result<Self, GuestRegionCollectionError>

Creates a new GuestRegionCollection 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<R>>, ) -> Result<Self, GuestRegionCollectionError>

Creates a new GuestRegionCollection from a vector of Arc regions.

Similar to the constructor from_regions() as it returns a GuestRegionCollection. The need for this constructor is to provide a way for consumer of this API to create a new GuestRegionCollection based on existing regions coming from an existing GuestRegionCollection 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<R>, ) -> Result<GuestRegionCollection<R>, GuestRegionCollectionError>

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

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

pub fn remove_region( &self, base: GuestAddress, size: GuestUsize, ) -> Result<(GuestRegionCollection<R>, Arc<R>), GuestRegionCollectionError>

Remove a region from the GuestRegionCollection object and return a new GuestRegionCollection 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
Source§

impl<B: NewBitmap> GuestRegionCollection<GuestRegionMmap<B>>

Source

pub fn from_ranges( ranges: &[(GuestAddress, usize)], ) -> Result<Self, FromRangesError>

Available on crate feature backend-mmap only.

Creates a container and allocates anonymous memory for guest memory regions.

Valid memory regions are specified as a slice of (Address, Size) tuples sorted by Address.

Source

pub fn from_ranges_with_files<A, T>(ranges: T) -> Result<Self, FromRangesError>
where A: Borrow<(GuestAddress, usize, Option<FileOffset>)>, T: IntoIterator<Item = A>,

Available on crate feature backend-mmap only.

Creates a container and allocates anonymous memory for guest memory regions.

Valid memory regions are specified as a sequence of (Address, Size, Option<FileOffset>) tuples sorted by Address.

Trait Implementations§

Source§

impl<R> Clone for GuestRegionCollection<R>

Source§

fn clone(&self) -> Self

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

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

Performs copy-assignment from source. Read more
Source§

impl<R: Debug> Debug for GuestRegionCollection<R>

Source§

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

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

impl<R> Default for GuestRegionCollection<R>

Source§

fn default() -> Self

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

impl<R: GuestMemoryRegion> GuestMemoryBackend for GuestRegionCollection<R>

Source§

type R = R

Type of objects hosted by the address space.
Source§

fn num_regions(&self) -> usize

Returns the number of regions in the collection.
Source§

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

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

fn iter(&self) -> impl Iterator<Item = &Self::R>

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

fn last_addr(&self) -> GuestAddress

Returns the maximum (inclusive) address managed by the GuestMemoryBackend. 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>
where F: FnMut(usize, usize, MemoryRegionAddress, &Self::R) -> Result<usize>,

👎Deprecated since 0.17.0: supplemented by external iterator get_slices()
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>

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

fn get_slice( &self, addr: GuestAddress, count: usize, ) -> Result<VolatileSlice<'_, MS<'_, Self>>>

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

fn get_slices<'a>( &'a self, addr: GuestAddress, count: usize, ) -> GuestMemoryBackendSliceIterator<'a, Self>

Returns an iterator over VolatileSlices, together covering count bytes starting at 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> 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§

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_volatile_from<F>( &self, addr: GuestAddress, src: &mut F, count: usize, ) -> Result<usize, Error>
where F: ReadVolatile,

Reads up to count bytes from src and writes them into the container at addr. Unlike VolatileRead::read_volatile, this function retries on EINTR being returned from the underlying I/O read operation. Read more
Source§

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

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

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

Reads up to count bytes from the container at addr and writes them into dst. Unlike VolatileWrite::write_volatile, this function retries on EINTR being returned by the underlying I/O write operation. Read more
Source§

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

Reads exactly count bytes from the container at addr and writes them into an object. 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: ByteValued>(&self, val: T, addr: A) -> Result<(), Self::E>

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

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

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<M> GuestMemory for M

Source§

type PhysicalMemory = M

Underlying GuestMemoryBackend type.
Source§

type Bitmap = <<M as GuestMemoryBackend>::R as GuestMemoryRegion>::B

Dirty bitmap type for tracking writes to the IOVA address space.
Source§

fn check_range( &self, addr: GuestAddress, count: usize, _access: Permissions, ) -> bool

Return true if addr..(addr + count) is accessible with access.
Source§

fn get_slices<'a>( &'a self, addr: GuestAddress, count: usize, _access: Permissions, ) -> Result<impl GuestMemorySliceIterator<'a, <<M as GuestMemory>::Bitmap as WithBitmapSlice<'a>>::S>, Error>

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

fn physical_memory(&self) -> Option<&<M as GuestMemory>::PhysicalMemory>

If this virtual memory is just a plain GuestMemoryBackend object underneath without an IOMMU translation layer in between, return that GuestMemoryBackend object.
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.