pub struct GuestRegionMmap<B = ()> { /* private fields */ }
Expand description

GuestMemoryRegion implementation that mmaps the guest’s memory region in the current process.

Represents a continuous region of the guest’s physical memory that is backed by a mapping in the virtual address space of the calling process.

Implementations

Create a new memory-mapped memory region for the guest’s physical memory.

Methods from Deref<Target = MmapRegion<B>>

Returns a pointer to the beginning of the memory region. Mutable accesses performed using the resulting pointer are not automatically accounted for by the dirty bitmap tracking functionality.

Should only be used for passing this region to ioctls for setting guest memory.

Returns the size of this region.

Returns information regarding the offset into the file backing this region (if any).

Returns the value of the prot parameter passed to mmap when mapping this region.

Returns the value of the flags parameter passed to mmap when mapping this region.

Returns true if the mapping is owned by this MmapRegion instance.

Checks whether this region and other are backed by overlapping FileOffset objects.

This is mostly a sanity check available for convenience, as different file descriptors can alias the same file.

Returns true if the region is hugetlbfs

Returns a reference to the inner bitmap object.

Trait Implementations

Examples
  • Write a slice at guest address 0x1200.
let res = gm
    .write(&[1, 2, 3, 4, 5], GuestAddress(0x1200))
    .expect("Could not write to guest memory");
assert_eq!(5, res);
Examples
  • Read a slice of length 16 at guestaddress 0x1200.
let buf = &mut [0u8; 16];
let res = gm
    .read(buf, GuestAddress(0x1200))
    .expect("Could not read from guest memory");
assert_eq!(16, res);
Examples
  • Read bytes from /dev/urandom
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");
Examples
  • Read bytes from /dev/urandom
let mut file = File::open(Path::new("/dev/urandom")).expect("Could not open /dev/urandom");

gm.read_exact_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");

Writes data from the region to a writable object.

Examples
  • Write 128 bytes to a /dev/null file
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 to file from guest memory");

Writes data from the region to a writable object.

Examples
  • Write 128 bytes to a /dev/null file
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 to file from guest memory");

Associated error codes

Writes the entire content of a slice into the container at addr. Read more

Reads data from the container at addr to fill an entire slice. Read more

Atomically store a value at the specified address.

Atomically load a value from the specified address.

Writes an object into the container at addr. Read more

Reads an object from the container at addr. Read more

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Type of the iter method’s return value.

Type used for dirty memory tracking.

Returns the size of the region.

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

Borrow the associated Bitmap object.

Returns the host virtual address corresponding to the region address. Read more

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

Returns a slice corresponding to the data in the region. Read more

Returns a mutable slice corresponding to the data in the region. Read more

Returns a VolatileSlice of count bytes starting at offset. Read more

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. Read more

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. Read more

Gets a slice of memory for the entire region that supports volatile access. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.