Struct vm_memory::mmap::GuestMemoryMmap
source · pub struct GuestMemoryMmap<B = ()> { /* private fields */ }
Expand description
GuestMemory
implementation that mmaps the guest’s memory
in the current process.
Represents the entire physical memory of the guest by tracking all its memory regions.
Each region is an instance of GuestRegionMmap
, being backed by a mapping in the
virtual address space of the calling process.
Implementations§
source§impl<B: NewBitmap> GuestMemoryMmap<B>
impl<B: NewBitmap> GuestMemoryMmap<B>
sourcepub fn from_ranges(ranges: &[(GuestAddress, usize)]) -> Result<Self, Error>
pub fn from_ranges(ranges: &[(GuestAddress, usize)]) -> Result<Self, Error>
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, Error>
pub fn from_ranges_with_files<A, T>(ranges: T) -> Result<Self, Error>
Creates a container and allocates anonymous memory for guest memory regions.
Valid memory regions are specified as a sequence of (Address, Size, Option
source§impl<B: Bitmap> GuestMemoryMmap<B>
impl<B: Bitmap> GuestMemoryMmap<B>
sourcepub fn from_regions(regions: Vec<GuestRegionMmap<B>>) -> Result<Self, Error>
pub fn from_regions(regions: Vec<GuestRegionMmap<B>>) -> Result<Self, Error>
Creates a new GuestMemoryMmap
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<GuestRegionMmap<B>>>,
) -> Result<Self, Error>
pub fn from_arc_regions( regions: Vec<Arc<GuestRegionMmap<B>>>, ) -> Result<Self, Error>
Creates a new GuestMemoryMmap
from a vector of Arc regions.
Similar to the constructor from_regions()
as it returns a
GuestMemoryMmap
. The need for this constructor is to provide a way for
consumer of this API to create a new GuestMemoryMmap
based on existing
regions coming from an existing GuestMemoryMmap
instance.
§Arguments
regions
- The vector ofArc
regions. The regions shouldn’t overlap and they should be sorted by the starting address.
sourcepub fn insert_region(
&self,
region: Arc<GuestRegionMmap<B>>,
) -> Result<GuestMemoryMmap<B>, Error>
pub fn insert_region( &self, region: Arc<GuestRegionMmap<B>>, ) -> Result<GuestMemoryMmap<B>, Error>
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<(GuestMemoryMmap<B>, Arc<GuestRegionMmap<B>>), Error>
pub fn remove_region( &self, base: GuestAddress, size: GuestUsize, ) -> Result<(GuestMemoryMmap<B>, Arc<GuestRegionMmap<B>>), Error>
Remove a region into the GuestMemoryMmap
object and return a new GuestMemoryMmap
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§
source§impl<B: Clone> Clone for GuestMemoryMmap<B>
impl<B: Clone> Clone for GuestMemoryMmap<B>
source§fn clone(&self) -> GuestMemoryMmap<B>
fn clone(&self) -> GuestMemoryMmap<B>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<B: Debug> Debug for GuestMemoryMmap<B>
impl<B: Debug> Debug for GuestMemoryMmap<B>
source§impl<B: Default> Default for GuestMemoryMmap<B>
impl<B: Default> Default for GuestMemoryMmap<B>
source§fn default() -> GuestMemoryMmap<B>
fn default() -> GuestMemoryMmap<B>
source§impl<B: Bitmap + 'static> GuestMemory for GuestMemoryMmap<B>
impl<B: Bitmap + 'static> GuestMemory for GuestMemoryMmap<B>
source§type R = GuestRegionMmap<B>
type R = GuestRegionMmap<B>
source§type I = GuestMemoryMmap<B>
type I = GuestMemoryMmap<B>
Self
.source§fn num_regions(&self) -> usize
fn num_regions(&self) -> usize
source§fn find_region(&self, addr: GuestAddress) -> Option<&GuestRegionMmap<B>>
fn find_region(&self, addr: GuestAddress) -> Option<&GuestRegionMmap<B>>
None
.source§fn iter(&self) -> Iter<'_, B> ⓘ
fn iter(&self) -> Iter<'_, B> ⓘ
source§fn with_regions<F, E>(&self, cb: F) -> Result<(), E>
fn with_regions<F, E>(&self, cb: F) -> Result<(), E>
.iter()
insteadsource§fn with_regions_mut<F, E>(&self, cb: F) -> Result<(), E>
fn with_regions_mut<F, E>(&self, cb: F) -> Result<(), E>
.iter()
insteadsource§fn map_and_fold<F, G, T>(&self, init: T, mapf: F, foldf: G) -> T
fn map_and_fold<F, G, T>(&self, init: T, mapf: F, foldf: G) -> T
.iter()
insteadsource§fn last_addr(&self) -> GuestAddress
fn last_addr(&self) -> GuestAddress
GuestMemory
. 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>
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§impl<'a, B: 'a> GuestMemoryIterator<'a, GuestRegionMmap<B>> for GuestMemoryMmap<B>
impl<'a, B: 'a> GuestMemoryIterator<'a, GuestRegionMmap<B>> for GuestMemoryMmap<B>
Auto Trait Implementations§
impl<B> Freeze for GuestMemoryMmap<B>
impl<B> RefUnwindSafe for GuestMemoryMmap<B>where
B: RefUnwindSafe,
impl<B> Send for GuestMemoryMmap<B>
impl<B> Sync for GuestMemoryMmap<B>
impl<B> Unpin for GuestMemoryMmap<B>
impl<B> UnwindSafe for GuestMemoryMmap<B>where
B: 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-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>
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,
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,
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,
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§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_exact_from<F>(
&self,
addr: GuestAddress,
src: &mut F,
count: usize,
) -> Result<(), Error>where
F: Read,
fn read_exact_from<F>(
&self,
addr: GuestAddress,
src: &mut F,
count: usize,
) -> Result<(), Error>where
F: Read,
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)