[−][src]Trait vm_memory::guest_memory::GuestAddressSpace
GuestAddressSpace provides a way to retrieve a GuestMemory object. The vm-memory crate already provides trivial implementation for references to GuestMemory or reference-counted GuestMemory objects, but the trait can also be implemented by any other struct in order to provide temporary access to a snapshot of the memory map.
In order to support generic mutable memory maps, devices (or other things
that access memory) should store the memory as a GuestAddressSpace
pub struct VirtioDevice<AS: GuestAddressSpace> { mem: Option<AS>, } impl<AS: GuestAddressSpace> VirtioDevice<AS> { fn new() -> Self { VirtioDevice { mem: None } } fn activate(&mut self, mem: AS) { self.mem = Some(mem) } } // Using `VirtioDevice` with an immutable GuestMemoryMmap: let mut for_immutable_mmap: VirtioDevice<&GuestMemoryMmap> = VirtioDevice::new(); let mmap = get_mmap(); for_immutable_mmap.activate(&mmap); let mut another: VirtioDevice<&GuestMemoryMmap> = VirtioDevice::new(); another.activate(&mmap); // Using `VirtioDevice` with a mutable GuestMemoryMmap: let mut for_mutable_mmap: VirtioDevice<GuestMemoryAtomic<GuestMemoryMmap>> = VirtioDevice::new(); let atomic = GuestMemoryAtomic::new(get_mmap()); for_mutable_mmap.activate(atomic.clone()); let mut another: VirtioDevice<GuestMemoryAtomic<GuestMemoryMmap>> = VirtioDevice::new(); another.activate(atomic.clone()); // atomic can be modified here...
Associated Types
type M: GuestMemory
The type that will be used to access guest memory.
type T: Clone + Deref<Target = Self::M>
A type that provides access to the memory.
Required methods
fn memory(&self) -> Self::T
Return an object (e.g. a reference or guard) that can be used to access memory through this address space. The object provides a consistent snapshot of the memory map.