Trait vm_memory::guest_memory::GuestMemoryRegion
source · pub trait GuestMemoryRegion: Bytes<MemoryRegionAddress, E = Error> {
type B: Bitmap;
Show 15 methods
// Required methods
fn len(&self) -> GuestUsize;
fn start_addr(&self) -> GuestAddress;
fn bitmap(&self) -> &Self::B;
// Provided methods
fn last_addr(&self) -> GuestAddress { ... }
fn check_address(
&self,
addr: MemoryRegionAddress,
) -> Option<MemoryRegionAddress> { ... }
fn address_in_range(&self, addr: MemoryRegionAddress) -> bool { ... }
fn checked_offset(
&self,
base: MemoryRegionAddress,
offset: usize,
) -> Option<MemoryRegionAddress> { ... }
fn to_region_addr(&self, addr: GuestAddress) -> Option<MemoryRegionAddress> { ... }
fn get_host_address(&self, _addr: MemoryRegionAddress) -> Result<*mut u8> { ... }
fn file_offset(&self) -> Option<&FileOffset> { ... }
unsafe fn as_slice(&self) -> Option<&[u8]> { ... }
unsafe fn as_mut_slice(&self) -> Option<&mut [u8]> { ... }
fn get_slice(
&self,
offset: MemoryRegionAddress,
count: usize,
) -> Result<VolatileSlice<'_, BS<'_, Self::B>>> { ... }
fn as_volatile_slice(&self) -> Result<VolatileSlice<'_, BS<'_, Self::B>>> { ... }
fn is_hugetlbfs(&self) -> Option<bool> { ... }
}
Expand description
Represents a continuous region of guest physical memory.
Required Associated Types§
Required Methods§
sourcefn len(&self) -> GuestUsize
fn len(&self) -> GuestUsize
Returns the size of the region.
sourcefn start_addr(&self) -> GuestAddress
fn start_addr(&self) -> GuestAddress
Returns the minimum (inclusive) address managed by the region.
Provided Methods§
sourcefn last_addr(&self) -> GuestAddress
fn last_addr(&self) -> GuestAddress
Returns the maximum (inclusive) address managed by the region.
sourcefn check_address(
&self,
addr: MemoryRegionAddress,
) -> Option<MemoryRegionAddress>
fn check_address( &self, addr: MemoryRegionAddress, ) -> Option<MemoryRegionAddress>
Returns the given address if it is within this region.
sourcefn address_in_range(&self, addr: MemoryRegionAddress) -> bool
fn address_in_range(&self, addr: MemoryRegionAddress) -> bool
Returns true
if the given address is within this region.
sourcefn checked_offset(
&self,
base: MemoryRegionAddress,
offset: usize,
) -> Option<MemoryRegionAddress>
fn checked_offset( &self, base: MemoryRegionAddress, offset: usize, ) -> Option<MemoryRegionAddress>
Returns the address plus the offset if it is in this region.
sourcefn to_region_addr(&self, addr: GuestAddress) -> Option<MemoryRegionAddress>
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.
sourcefn get_host_address(&self, _addr: MemoryRegionAddress) -> Result<*mut u8>
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.
sourcefn file_offset(&self) -> Option<&FileOffset>
fn file_offset(&self) -> Option<&FileOffset>
Returns information regarding the file and offset backing this memory region.
sourceunsafe fn as_slice(&self) -> Option<&[u8]>
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.
sourceunsafe fn as_mut_slice(&self) -> Option<&mut [u8]>
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. Mutable accesses performed through the returned slice are not visible to the dirty bitmap tracking functionality of the region, and must be manually recorded using the associated bitmap object.
sourcefn get_slice(
&self,
offset: MemoryRegionAddress,
count: usize,
) -> Result<VolatileSlice<'_, BS<'_, Self::B>>>
fn get_slice( &self, offset: MemoryRegionAddress, count: usize, ) -> Result<VolatileSlice<'_, BS<'_, Self::B>>>
Returns a VolatileSlice
of count
bytes starting at
offset
.
sourcefn as_volatile_slice(&self) -> Result<VolatileSlice<'_, BS<'_, Self::B>>>
fn as_volatile_slice(&self) -> Result<VolatileSlice<'_, BS<'_, Self::B>>>
Gets a slice of memory for the entire region that supports volatile access.
§Examples (uses the backend-mmap
feature)
let region = MmapRegion::<()>::new(0x400).expect("Could not create mmap region");
let region =
GuestRegionMmap::new(region, GuestAddress(0x0)).expect("Could not create guest memory");
let slice = region
.as_volatile_slice()
.expect("Could not get volatile slice");
let v = 42u32;
let r = slice
.get_ref::<u32>(0x200)
.expect("Could not get reference");
r.store(v);
assert_eq!(r.load(), v);
sourcefn is_hugetlbfs(&self) -> Option<bool>
fn is_hugetlbfs(&self) -> Option<bool>
Show if the region is based on the HugeTLBFS
.
Returns Some(true) if the region is backed by hugetlbfs.
None represents that no information is available.
§Examples (uses the backend-mmap
feature)
let addr = GuestAddress(0x1000);
let mem = GuestMemoryMmap::<()>::from_ranges(&[(addr, 0x1000)]).unwrap();
let r = mem.find_region(addr).unwrap();
assert_eq!(r.is_hugetlbfs(), None);