VirtualMachineInstance

Struct VirtualMachineInstance 

Source
pub struct VirtualMachineInstance<Gic> { /* private fields */ }
Expand description

Represents the unique virtual machine instance of the current process.

This object can be safely shared among threads and guarantees the VM to exist as long as this handle does.

Implementations§

Source§

impl VirtualMachineInstance<GicEnabled>

Source

pub fn gic_reset(&self) -> Result<()>

Resets the GIC device.

§Discussion

When the virtual machine is being reset, call this function to reset the GIC distributor, redistributor registers and the internal state of the device.

Source

pub fn gic_state_create(&self) -> Result<GicState>

Creates a global interrupt controller configuration object.

Source

pub fn gic_set_spi(&self, intid: u32, level: bool) -> Result<()>

Trigger a Shared Peripheral Interrupt (SPI).

Source

pub fn gic_send_msi(&self, address: hv_ipa_t, intid: u32) -> Result<()>

Send a Message Signaled Interrupt (MSI).

Source

pub fn gic_get_distributor_reg(&self, reg: GicDistributorReg) -> Result<u64>

Read a GIC distributor register.

Source

pub fn gic_set_distributor_reg( &self, reg: GicDistributorReg, value: u64, ) -> Result<()>

Write a GIC distributor register.

Source

pub fn gic_get_msi_reg(&self, reg: GicMsiReg) -> Result<u64>

Read a GIC distributor MSI register.

Source

pub fn gic_set_msi_reg(&self, reg: GicMsiReg, value: u64) -> Result<()>

Write a GIC distributor MSI register.

Source§

impl<Gic> VirtualMachineInstance<Gic>

Source

pub fn vcpu_create(&self) -> Result<Vcpu>

Creates a new vCPU.

§Example
use applevisor::prelude::*;

let vcpu = vm.vcpu_create()?;
Source

pub fn vcpu_with_config(&self, config: VcpuConfig) -> Result<Vcpu>

Creates a new vCPU with a user-provided config.

§Example
use applevisor::prelude::*;

let vcpu_config = VcpuConfig::default();
let vcpu = vm.vcpu_with_config(vcpu_config)?;
Source

pub fn vcpus_exit(&self, vcpus: &[VcpuHandle]) -> Result<()>

Stops all vCPUs corresponding to the VcpuHandles of the vcpu input array.

§Example
use applevisor::prelude::*;

let thread_count = 3;
let (tx, rx) = mpsc::channel();

thread::scope(|s| {
    // Each thread will have a Vcpu looping indefinitely.
    for i in 0..thread_count {
        let vm_thread = vm.clone();
        let tx_thread = tx.clone();
        s.spawn(move || {
            // Create the vCPU and memory region that will hold the infinite loop
            // instruction.
            let vcpu = vm_thread.vcpu_create().unwrap();

            // Write the instruction that while loop indefinitely.
            let mut mem = vm_thread.memory_create(PAGE_SIZE).unwrap();
            let addr = (PAGE_SIZE * i) as u64;
            mem.map(addr, MemPerms::ReadWriteExec).unwrap();
            mem.write_u32(addr, 0x14000000).unwrap();

            // Set PC to the loop address.
            vcpu.set_reg(Reg::PC, 0x10000).unwrap();

            // Sending the vCPU handle back to the main thread.
            let handle = vcpu.get_handle();
            tx_thread.send(handle).unwrap();

            // Starting the VCPU, we should loop indefinitely here.
            vcpu.run().unwrap();
        });
    }
    // Wait for the vCPU handles from each thread.
    let mut handles = vec![];
    for _ in 0..thread_count {
        handles.push(rx.recv().unwrap());
    }
    // Make the vCPU of each thread exit.
    vm.vcpus_exit(&handles).unwrap();
});
Source

pub fn memory_create(&self, size: usize) -> Result<Memory>

Creates a memory object.

§Discussion

The size provided must be aligned to PAGE_SIZE.

§Example
use applevisor::prelude::*;

let vm = VirtualMachine::new()?;
let mem = vm.memory_create(PAGE_SIZE * 10)?;

Trait Implementations§

Source§

impl<Gic: Clone> Clone for VirtualMachineInstance<Gic>

Source§

fn clone(&self) -> VirtualMachineInstance<Gic>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Gic: Debug> Debug for VirtualMachineInstance<Gic>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Gic> Drop for VirtualMachineInstance<Gic>

Destroys the virtual machine context of the current process.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl From<VirtualMachineInstance<GicEnabled>> for VirtualMachineInstance<GicDisabled>

Available on crate feature macos-15-0 only.

Transformes a GicEnabled instance into a GicDisabled one. The underlying object still has a GIC instance, but related APIs can’t be called.

Source§

fn from(value: VirtualMachineInstance<GicEnabled>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<Gic> Freeze for VirtualMachineInstance<Gic>

§

impl<Gic> RefUnwindSafe for VirtualMachineInstance<Gic>
where Gic: RefUnwindSafe,

§

impl<Gic> Send for VirtualMachineInstance<Gic>
where Gic: Send,

§

impl<Gic> Sync for VirtualMachineInstance<Gic>
where Gic: Sync,

§

impl<Gic> Unpin for VirtualMachineInstance<Gic>
where Gic: Unpin,

§

impl<Gic> UnwindSafe for VirtualMachineInstance<Gic>
where Gic: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.