Skip to main content

MiniVm

Struct MiniVm 

Source
pub struct MiniVm {
    pub kvm: Kvm,
    pub vm: VmFd,
    pub mem: Arc<MappedMemory>,
    pub vcpus: Vec<VcpuFd>,
    /* private fields */
}
Expand description

A minimal long-mode VM.

Fields§

§kvm: Kvm

The /dev/kvm handle.

§vm: VmFd

The VM.

§mem: Arc<MappedMemory>

Guest RAM.

§vcpus: Vec<VcpuFd>

The vCPUs.

Implementations§

Source§

impl MiniVm

Source

pub const CODE: u64 = 0x1_0000

Where programs are loaded.

Source

pub const GDT: u64 = 0x500

GDT.

Source

pub const PML4: u64 = 0x1000

PML4.

Source

pub const PT: u64 = 0x4000

The 4 KiB page table covering 0x20_0000..0x40_0000.

Source

pub const IDT: u64 = 0x6000

IDT.

Source

pub const STACK_TOP: u64 = 0x8_0000

Top of vCPU 0’s stack.

Source

pub fn new(mem_mib: usize, vcpus: u32) -> Result<MiniVm>

Creates a VM with mem_mib MiB of RAM and vcpus vCPUs, all in 64-bit mode at MiniVm::CODE with interrupts disabled.

Source

pub fn reset_vcpu(&mut self, idx: usize, rip: u64, rsp: u64) -> Result<()>

Puts vCPU idx in 64-bit mode at rip with stack rsp.

Source

pub fn load(&self, gpa: u64, bytes: &[u8])

Copies bytes to guest-physical address gpa.

Source

pub fn set_gate(&self, vector: u8, handler: u64)

Points IDT vector vector at handler (a 64-bit interrupt gate).

Source

pub fn unmap_page(&self, la: u64)

Marks the 4 KiB page at la (which must be in 0x20_0000..0x40_0000) not present.

Source

pub fn set_msrs(&self, entries: &[(u32, u64)]) -> Result<()>

Sets MSRs on every vCPU (for example LSTAR for SYSCALL).

Source

pub fn memory(&self) -> Arc<dyn GuestMemory> ⓘ

Guest RAM as a shareable GuestMemory.

Trait Implementations§

Source§

impl Drop for MiniVm

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for MiniVm

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.