Skip to content

Instantly share code, notes, and snippets.

@sameo
Last active March 4, 2019 13:50
Show Gist options
  • Save sameo/fd72f6d85ce596e183d1229c95761f15 to your computer and use it in GitHub Desktop.
Save sameo/fd72f6d85ce596e183d1229c95761f15 to your computer and use it in GitHub Desktop.

MmapRegion

MmapRegion is an mmap'ed memory region backed by volatile memory (RAM).

pub struct MmapRegion {
    addr: *mut u8,
    size: usize,
}

impl VolatileMemory for MmapRegion
impl Drop for MmapRegion

GuestRegionMmap

GuestRegionMmap is a guest memory region, mmap'ed to the host RAM. It is a esentially a MmapRegion linked to a base guest physical address.

pub struct GuestRegionMmap {
    mapping: MmapRegion,
    guest_base: GuestAddress,
}

/// Represents a guest physical address (GPA).
///
/// Notes:
/// - On ARM64, a 32-bit hypervisor may be used to support a 64-bit guest. For simplicity,
/// u64 is used to store the the raw value no matter the guest a 32-bit or 64-bit virtual machine.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub struct GuestAddress(pub u64);
impl_address_ops!(GuestAddress, u64);

/// Represents an offset inside a region.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub struct MemoryRegionAddress(pub u64);
impl_address_ops!(MemoryRegionAddress, u64);

impl Bytes<MemoryRegionAddress> for GuestRegionMmap
impl GuestMemoryRegion for GuestRegionMmap

GuestMemoryMmap

GuestMemoryMmap represents a guest memory mmap'ed to the host RAM. It is an array of GuestRegionMmap.

pub struct GuestMemoryMmap {
    regions: Arc<Vec<GuestRegionMmap>>,
}

impl GuestMemory for GuestMemoryMmap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment