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>
impl<R: GuestMemoryRegion> GuestRegionCollection<R>
Sourcepub fn from_regions(regions: Vec<R>) -> Result<Self, GuestRegionCollectionError>
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.
Sourcepub fn from_arc_regions(
regions: Vec<Arc<R>>,
) -> Result<Self, GuestRegionCollectionError>
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 ofArcregions. The regions shouldn’t overlap and they should be sorted by the starting address.
Sourcepub fn insert_region(
&self,
region: Arc<R>,
) -> Result<GuestRegionCollection<R>, GuestRegionCollectionError>
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.
Sourcepub fn remove_region(
&self,
base: GuestAddress,
size: GuestUsize,
) -> Result<(GuestRegionCollection<R>, Arc<R>), GuestRegionCollectionError>
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 removedsize: size of the region to be removed
Source§impl<B: NewBitmap> GuestRegionCollection<GuestRegionMmap<B>>
impl<B: NewBitmap> GuestRegionCollection<GuestRegionMmap<B>>
Sourcepub fn from_ranges(
ranges: &[(GuestAddress, usize)],
) -> Result<Self, FromRangesError>
Available on crate feature backend-mmap only.
pub fn from_ranges( ranges: &[(GuestAddress, usize)], ) -> Result<Self, FromRangesError>
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.
Sourcepub fn from_ranges_with_files<A, T>(ranges: T) -> Result<Self, FromRangesError>
Available on crate feature backend-mmap only.
pub fn from_ranges_with_files<A, T>(ranges: T) -> Result<Self, FromRangesError>
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>
impl<R> Clone for GuestRegionCollection<R>
Source§impl<R: Debug> Debug for GuestRegionCollection<R>
impl<R: Debug> Debug for GuestRegionCollection<R>
Source§impl<R> Default for GuestRegionCollection<R>
impl<R> Default for GuestRegionCollection<R>
Source§impl<R: GuestMemoryRegion> GuestMemoryBackend for GuestRegionCollection<R>
impl<R: GuestMemoryRegion> GuestMemoryBackend for GuestRegionCollection<R>
Source§fn num_regions(&self) -> usize
fn num_regions(&self) -> usize
Source§fn find_region(&self, addr: GuestAddress) -> Option<&R>
fn find_region(&self, addr: GuestAddress) -> Option<&R>
None.Source§fn iter(&self) -> impl Iterator<Item = &Self::R>
fn iter(&self) -> impl Iterator<Item = &Self::R>
Source§fn last_addr(&self) -> GuestAddress
fn last_addr(&self) -> GuestAddress
GuestMemoryBackend. Read moreSource§fn to_region_addr(
&self,
addr: GuestAddress,
) -> Option<(&Self::R, MemoryRegionAddress)>
fn to_region_addr( &self, addr: GuestAddress, ) -> Option<(&Self::R, MemoryRegionAddress)>
Source§fn address_in_range(&self, addr: GuestAddress) -> bool
fn address_in_range(&self, addr: GuestAddress) -> bool
true if the given address is present within the memory of the guest.Source§fn check_address(&self, addr: GuestAddress) -> Option<GuestAddress>
fn check_address(&self, addr: GuestAddress) -> Option<GuestAddress>
Source§fn check_range(&self, base: GuestAddress, len: usize) -> bool
fn check_range(&self, base: GuestAddress, len: usize) -> bool
Source§fn checked_offset(
&self,
base: GuestAddress,
offset: usize,
) -> Option<GuestAddress>
fn checked_offset( &self, base: GuestAddress, offset: usize, ) -> Option<GuestAddress>
Source§fn try_access<F>(&self, count: usize, addr: GuestAddress, f: F) -> Result<usize>
fn try_access<F>(&self, count: usize, addr: GuestAddress, f: F) -> Result<usize>
get_slices()Source§fn get_host_address(&self, addr: GuestAddress) -> Result<*mut u8>
fn get_host_address(&self, addr: GuestAddress) -> Result<*mut u8>
Source§fn get_slice(
&self,
addr: GuestAddress,
count: usize,
) -> Result<VolatileSlice<'_, MS<'_, Self>>>
fn get_slice( &self, addr: GuestAddress, count: usize, ) -> Result<VolatileSlice<'_, MS<'_, Self>>>
Source§fn get_slices<'a>(
&'a self,
addr: GuestAddress,
count: usize,
) -> GuestMemoryBackendSliceIterator<'a, Self> ⓘ
fn get_slices<'a>( &'a self, addr: GuestAddress, count: usize, ) -> GuestMemoryBackendSliceIterator<'a, Self> ⓘ
Auto Trait Implementations§
impl<R> Freeze for GuestRegionCollection<R>
impl<R> RefUnwindSafe for GuestRegionCollection<R>where
R: RefUnwindSafe,
impl<R> Send for GuestRegionCollection<R>
impl<R> Sync for GuestRegionCollection<R>
impl<R> Unpin for GuestRegionCollection<R>
impl<R> UnwindSafe for GuestRegionCollection<R>where
R: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Bytes<GuestAddress> for Twhere
T: GuestMemory + ?Sized,
impl<T> Bytes<GuestAddress> for Twhere
T: GuestMemory + ?Sized,
Source§fn write_slice(&self, buf: &[u8], addr: GuestAddress) -> Result<(), Error>
fn write_slice(&self, buf: &[u8], addr: GuestAddress) -> Result<(), Error>
§Examples
- Write a slice at guestaddress 0x1000. (uses the
backend-mmapfeature)
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>
fn read_slice(&self, buf: &mut [u8], addr: GuestAddress) -> Result<(), Error>
§Examples
- Read a slice of length 16 at guestaddress 0x1000. (uses the
backend-mmapfeature)
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 write(&self, buf: &[u8], addr: GuestAddress) -> Result<usize, Error>
fn write(&self, buf: &[u8], addr: GuestAddress) -> Result<usize, Error>
addr. Read moreSource§fn read(&self, buf: &mut [u8], addr: GuestAddress) -> Result<usize, Error>
fn read(&self, buf: &mut [u8], addr: GuestAddress) -> Result<usize, Error>
addr into a slice. Read moreSource§fn read_volatile_from<F>(
&self,
addr: GuestAddress,
src: &mut F,
count: usize,
) -> Result<usize, Error>where
F: ReadVolatile,
fn read_volatile_from<F>(
&self,
addr: GuestAddress,
src: &mut F,
count: usize,
) -> Result<usize, Error>where
F: ReadVolatile,
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 moreSource§fn read_exact_volatile_from<F>(
&self,
addr: GuestAddress,
src: &mut F,
count: usize,
) -> Result<(), Error>where
F: ReadVolatile,
fn read_exact_volatile_from<F>(
&self,
addr: GuestAddress,
src: &mut F,
count: usize,
) -> Result<(), Error>where
F: ReadVolatile,
Source§fn write_volatile_to<F>(
&self,
addr: GuestAddress,
dst: &mut F,
count: usize,
) -> Result<usize, Error>where
F: WriteVolatile,
fn write_volatile_to<F>(
&self,
addr: GuestAddress,
dst: &mut F,
count: usize,
) -> Result<usize, Error>where
F: WriteVolatile,
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 moreSource§fn write_all_volatile_to<F>(
&self,
addr: GuestAddress,
dst: &mut F,
count: usize,
) -> Result<(), Error>where
F: WriteVolatile,
fn write_all_volatile_to<F>(
&self,
addr: GuestAddress,
dst: &mut F,
count: usize,
) -> Result<(), Error>where
F: WriteVolatile,
Source§fn store<O>(
&self,
val: O,
addr: GuestAddress,
order: Ordering,
) -> Result<(), Error>where
O: AtomicAccess,
fn store<O>(
&self,
val: O,
addr: GuestAddress,
order: Ordering,
) -> Result<(), Error>where
O: AtomicAccess,
Source§fn load<O>(&self, addr: GuestAddress, order: Ordering) -> Result<O, Error>where
O: AtomicAccess,
fn load<O>(&self, addr: GuestAddress, order: Ordering) -> Result<O, Error>where
O: AtomicAccess,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<M> GuestMemory for Mwhere
M: GuestMemoryBackend + ?Sized,
impl<M> GuestMemory for Mwhere
M: GuestMemoryBackend + ?Sized,
Source§type PhysicalMemory = M
type PhysicalMemory = M
GuestMemoryBackend type.Source§type Bitmap = <<M as GuestMemoryBackend>::R as GuestMemoryRegion>::B
type Bitmap = <<M as GuestMemoryBackend>::R as GuestMemoryRegion>::B
Source§fn check_range(
&self,
addr: GuestAddress,
count: usize,
_access: Permissions,
) -> bool
fn check_range( &self, addr: GuestAddress, count: usize, _access: Permissions, ) -> bool
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>
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>
Source§fn physical_memory(&self) -> Option<&<M as GuestMemory>::PhysicalMemory>
fn physical_memory(&self) -> Option<&<M as GuestMemory>::PhysicalMemory>
GuestMemoryBackend object underneath without an IOMMU
translation layer in between, return that GuestMemoryBackend object.