pub trait GuestMemoryRegion: Bytes<MemoryRegionAddress, E = Error> {
    type B: Bitmap;

Show 15 methods fn len(&self) -> GuestUsize; fn start_addr(&self) -> GuestAddress; fn bitmap(&self) -> &Self::B; 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

Type used for dirty memory tracking.

Required Methods

Returns the size of the region.

Returns the minimum (inclusive) address managed by the region.

Borrow the associated Bitmap object.

Provided Methods

Returns the maximum (inclusive) address managed by the region.

Returns the given address if it is within this region.

Returns true if the given address is within this region.

Returns the address plus the offset if it is in this region.

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.

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.

Returns information regarding the file and offset backing this memory region.

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.

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.

Returns a VolatileSlice of count bytes starting at offset.

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);

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);

Implementors