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

Creates an empty GuestMemoryMmap instance.

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.

Creates a container and allocates anonymous memory for guest memory regions.

Valid memory regions are specified as a sequence of (Address, Size, Option) tuples sorted by Address.

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.

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 of Arc regions. The regions shouldn’t overlap and they should be sorted by the starting address.

Insert a region into the GuestMemoryMmap object and return a new GuestMemoryMmap.

Arguments
  • region: the memory region to insert into the guest memory object.

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 removed
  • size: size of the region to be removed

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Type of objects hosted by the address space.
Lifetime generic associated iterators. Usually this is just Self.
Returns the number of regions in the collection.
Returns the region containing the specified address or None.
Gets an iterator over the entries in the collection. Read more
👎Deprecated since 0.6.0: Use .iter() instead
Perform the specified action on each region. Read more
👎Deprecated since 0.6.0: Use .iter() instead
Perform the specified action on each region mutably. Read more
👎Deprecated since 0.6.0: Use .iter() instead
Applies two functions, specified as callbacks, on the inner memory regions. Read more
Returns the maximum (inclusive) address managed by the GuestMemory. Read more
Tries to convert an absolute address to a relative address within the corresponding region. Read more
Returns true if the given address is present within the memory of the guest.
Returns the given address if it is present within the memory of the guest.
Check whether the range [base, base + len) is valid.
Returns the address plus the offset if it is present within the memory of the guest.
Invokes callback f to handle data in the address range [addr, addr + count). Read more
Get the host virtual address corresponding to the guest address. Read more
Returns a VolatileSlice of count bytes starting at addr. Read more
Type of the iter method’s return value.

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
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");
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");
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");
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");
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");
Associated error codes
Writes a slice into the container at addr. Read more
Reads data from the container at addr into a slice. Read more
Reads exactly count bytes from an object and writes them into the container at addr. 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

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 resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
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.