Struct dbs_address_space::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
sourceimpl<B: NewBitmap> GuestMemoryHybrid<B>
impl<B: NewBitmap> GuestMemoryHybrid<B>
sourceimpl<B: Bitmap> GuestMemoryHybrid<B>
impl<B: Bitmap> GuestMemoryHybrid<B>
sourcepub fn from_regions(regions: Vec<GuestRegionHybrid<B>>) -> Result<Self, Error>
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.
sourcepub fn from_arc_regions(
regions: Vec<Arc<GuestRegionHybrid<B>>>
) -> Result<Self, Error>
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 ofArcregions. The regions shouldn’t overlap and they should be sorted by the starting address.
sourcepub fn insert_region(
&self,
region: Arc<GuestRegionHybrid<B>>
) -> Result<GuestMemoryHybrid<B>, Error>
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.
sourcepub fn remove_region(
&self,
base: GuestAddress,
size: GuestUsize
) -> Result<(GuestMemoryHybrid<B>, Arc<GuestRegionHybrid<B>>), Error>
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 removedsize: size of the region to be removed
Trait Implementations
sourceimpl<B: Clone> Clone for GuestMemoryHybrid<B>
impl<B: Clone> Clone for GuestMemoryHybrid<B>
sourcefn clone(&self) -> GuestMemoryHybrid<B>
fn clone(&self) -> GuestMemoryHybrid<B>
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresourceimpl<B: Debug> Debug for GuestMemoryHybrid<B>
impl<B: Debug> Debug for GuestMemoryHybrid<B>
sourceimpl<B: Default> Default for GuestMemoryHybrid<B>
impl<B: Default> Default for GuestMemoryHybrid<B>
sourcefn default() -> GuestMemoryHybrid<B>
fn default() -> GuestMemoryHybrid<B>
sourceimpl<B: Bitmap + 'static> GuestMemory for GuestMemoryHybrid<B>
impl<B: Bitmap + 'static> GuestMemory for GuestMemoryHybrid<B>
type R = GuestRegionHybrid<B>
type R = GuestRegionHybrid<B>
type I = GuestMemoryHybrid<B>
type I = GuestMemoryHybrid<B>
Self.sourcefn num_regions(&self) -> usize
fn num_regions(&self) -> usize
sourcefn find_region(&self, addr: GuestAddress) -> Option<&GuestRegionHybrid<B>>
fn find_region(&self, addr: GuestAddress) -> Option<&GuestRegionHybrid<B>>
None.sourcefn with_regions<F, E>(&self, cb: F) -> Result<(), E>where
F: Fn(usize, &Self::R) -> Result<(), E>,
fn with_regions<F, E>(&self, cb: F) -> Result<(), E>where
F: Fn(usize, &Self::R) -> Result<(), E>,
.iter() insteadsourcefn with_regions_mut<F, E>(&self, cb: F) -> Result<(), E>where
F: FnMut(usize, &Self::R) -> Result<(), E>,
fn with_regions_mut<F, E>(&self, cb: F) -> Result<(), E>where
F: FnMut(usize, &Self::R) -> Result<(), E>,
.iter() insteadsourcefn map_and_fold<F, G, T>(&self, init: T, mapf: F, foldf: G) -> Twhere
F: Fn((usize, &Self::R)) -> T,
G: Fn(T, T) -> T,
fn map_and_fold<F, G, T>(&self, init: T, mapf: F, foldf: G) -> Twhere
F: Fn((usize, &Self::R)) -> T,
G: Fn(T, T) -> T,
.iter() insteadsourcefn last_addr(&self) -> GuestAddress
fn last_addr(&self) -> GuestAddress
GuestMemory. Read moresourcefn to_region_addr(
&self,
addr: GuestAddress
) -> Option<(&Self::R, MemoryRegionAddress)>
fn to_region_addr(
&self,
addr: GuestAddress
) -> Option<(&Self::R, MemoryRegionAddress)>
sourcefn 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.sourcefn check_address(&self, addr: GuestAddress) -> Option<GuestAddress>
fn check_address(&self, addr: GuestAddress) -> Option<GuestAddress>
sourcefn check_range(&self, base: GuestAddress, len: usize) -> bool
fn check_range(&self, base: GuestAddress, len: usize) -> bool
sourcefn checked_offset(
&self,
base: GuestAddress,
offset: usize
) -> Option<GuestAddress>
fn checked_offset(
&self,
base: GuestAddress,
offset: usize
) -> Option<GuestAddress>
sourcefn try_access<F>(
&self,
count: usize,
addr: GuestAddress,
f: F
) -> Result<usize, Error>where
F: FnMut(usize, usize, MemoryRegionAddress, &Self::R) -> Result<usize, Error>,
fn try_access<F>(
&self,
count: usize,
addr: GuestAddress,
f: F
) -> Result<usize, Error>where
F: FnMut(usize, usize, MemoryRegionAddress, &Self::R) -> Result<usize, Error>,
sourcefn get_host_address(&self, addr: GuestAddress) -> Result<*mut u8, Error>
fn get_host_address(&self, addr: GuestAddress) -> Result<*mut u8, Error>
sourcefn get_slice(
&self,
addr: GuestAddress,
count: usize
) -> Result<VolatileSlice<'_, <<Self::R as GuestMemoryRegion>::B as WithBitmapSlice<'_>>::S>, Error>
fn get_slice(
&self,
addr: GuestAddress,
count: usize
) -> Result<VolatileSlice<'_, <<Self::R as GuestMemoryRegion>::B as WithBitmapSlice<'_>>::S>, Error>
sourceimpl<'a, B: 'a> GuestMemoryIterator<'a, GuestRegionHybrid<B>> for GuestMemoryHybrid<B>
impl<'a, B: 'a> GuestMemoryIterator<'a, GuestRegionHybrid<B>> for GuestMemoryHybrid<B>
type Iter = Iter<'a, B>
type Iter = Iter<'a, B>
iter method’s return value.Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<T> Bytes<GuestAddress> for Twhere
T: GuestMemory + ?Sized,
impl<T> Bytes<GuestAddress> for Twhere
T: GuestMemory + ?Sized,
sourcefn 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");sourcefn 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");sourcefn read_from<F>(
&self,
addr: GuestAddress,
src: &mut F,
count: usize
) -> Result<usize, Error>where
F: Read,
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-mmapfeature)
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");sourcefn write_to<F>(
&self,
addr: GuestAddress,
dst: &mut F,
count: usize
) -> Result<usize, Error>where
F: Write,
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-mmapfeature)
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");sourcefn write_all_to<F>(
&self,
addr: GuestAddress,
dst: &mut F,
count: usize
) -> Result<(), Error>where
F: Write,
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-mmapfeature)
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");sourcefn write(&self, buf: &[u8], addr: GuestAddress) -> Result<usize, Error>
fn write(&self, buf: &[u8], addr: GuestAddress) -> Result<usize, Error>
addr. Read moresourcefn 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 more