[−][src]Trait vm_memory::guest_memory::GuestMemoryRegion
Represents a continuous region of guest physical memory.
Required methods
fn len(&self) -> GuestUsize
Returns the size of the region.
fn start_addr(&self) -> GuestAddress
Returns the minimum (inclusive) address managed by the region.
Provided methods
fn last_addr(&self) -> GuestAddress
Returns the maximum (inclusive) address managed by the region.
fn check_address(
&self,
addr: MemoryRegionAddress
) -> Option<MemoryRegionAddress>
&self,
addr: MemoryRegionAddress
) -> Option<MemoryRegionAddress>
Returns the given address if it is within this region.
fn address_in_range(&self, addr: MemoryRegionAddress) -> bool
Returns true
if the given address is within this region.
fn checked_offset(
&self,
base: MemoryRegionAddress,
offset: usize
) -> Option<MemoryRegionAddress>
&self,
base: MemoryRegionAddress,
offset: usize
) -> Option<MemoryRegionAddress>
Returns the address plus the offset if it is in this region.
fn to_region_addr(&self, addr: GuestAddress) -> Option<MemoryRegionAddress>
Tries to convert an absolute address to a relative address within this region.
Returns None
if addr
is out of the bounds of this region.
fn get_host_address(&self, _addr: MemoryRegionAddress) -> Result<*mut u8>
Returns the host virtual address corresponding to the region address.
Some GuestMemory
implementations, like GuestMemoryMmap
,
have the capability to mmap guest address range into host virtual address space for
direct access, so the corresponding host virtual address may be passed to other subsystems.
Note
The underlying guest memory is not protected from memory aliasing, which breaks the Rust memory safety model. It's the caller's responsibility to ensure that there's no concurrent accesses to the underlying guest memory.
fn file_offset(&self) -> Option<&FileOffset>
Returns information regarding the file and offset backing this memory region.
unsafe fn as_slice(&self) -> Option<&[u8]>
Returns a slice corresponding to the data in the region.
Returns None
if the region does not support slice-based access.
Safety
Unsafe because of possible aliasing.
unsafe fn as_mut_slice(&self) -> Option<&mut [u8]>
Returns a mutable slice corresponding to the data in the region.
Returns None
if the region does not support slice-based access.
Safety
Unsafe because of possible aliasing.
fn get_slice(
&self,
offset: MemoryRegionAddress,
count: usize
) -> Result<VolatileSlice>
&self,
offset: MemoryRegionAddress,
count: usize
) -> Result<VolatileSlice>
Returns a VolatileSlice
of count
bytes starting at
offset
.
fn as_volatile_slice(&self) -> Result<VolatileSlice>
Gets a slice of memory for the entire region that supports volatile access.
Examples
let region = GuestRegionMmap::new(MmapRegion::new(0x400).unwrap(), GuestAddress(0x0)) .unwrap(); let slice = region.as_volatile_slice().unwrap(); let v = 42u32; let r = slice.get_ref::<u32>(0x200).unwrap(); r.store(v); assert_eq!(r.load(), v);