Trait Vcpu

Source
pub trait Vcpu:
    Any
    + Send
    + Sync {
    // Required methods
    fn run(&self) -> Result<VcpuExit>;
    fn id(&self) -> usize;
    fn set_immediate_exit(&self, exit: bool);
    fn signal_handle(&self) -> VcpuSignalHandle;
    fn handle_mmio(
        &self,
        handle_fn: &mut dyn FnMut(IoParams<'_>) -> Result<()>,
    ) -> Result<()>;
    fn handle_io(&self, handle_fn: &mut dyn FnMut(IoParams<'_>)) -> Result<()>;
    fn on_suspend(&self) -> Result<()>;
    unsafe fn enable_raw_capability(
        &self,
        cap: u32,
        args: &[u64; 4],
    ) -> Result<()>;

    // Provided method
    fn handle_hypercall(
        &self,
        _handle_fn: &mut dyn FnMut(&mut HypercallAbi) -> Result<()>,
    ) -> Result<()> { ... }
}
Expand description

A virtual CPU holding a virtualized hardware thread’s state, such as registers and interrupt state, which may be used to execute virtual machines.

Required Methods§

Source

fn run(&self) -> Result<VcpuExit>

Runs the VCPU until it exits, returning the reason for the exit.

Source

fn id(&self) -> usize

Returns the vcpu id.

Source

fn set_immediate_exit(&self, exit: bool)

Sets the bit that requests an immediate exit.

Source

fn signal_handle(&self) -> VcpuSignalHandle

Returns a handle that can be used to cause this VCPU to exit from run() from a signal handler.

Source

fn handle_mmio( &self, handle_fn: &mut dyn FnMut(IoParams<'_>) -> Result<()>, ) -> Result<()>

Handles an incoming MMIO request from the guest.

This function should be called after Vcpu::run returns VcpuExit::Mmio, and in the same thread as run().

Once called, it will determine whether a MMIO read or MMIO write was the reason for the MMIO exit, call handle_fn with the respective IoParams to perform the MMIO read or write, and set the return data in the vcpu so that the vcpu can resume running.

Source

fn handle_io(&self, handle_fn: &mut dyn FnMut(IoParams<'_>)) -> Result<()>

Handles an incoming PIO from the guest.

This function should be called after Vcpu::run returns VcpuExit::Io, and in the same thread as run().

Once called, it will determine whether an input or output was the reason for the Io exit, call handle_fn with the respective IoParams to perform the input/output operation, and set the return data in the vcpu so that the vcpu can resume running.

Source

fn on_suspend(&self) -> Result<()>

Signals to the hypervisor that this Vcpu is being paused by userspace.

Source

unsafe fn enable_raw_capability(&self, cap: u32, args: &[u64; 4]) -> Result<()>

Enables a hypervisor-specific extension on this Vcpu. cap is a constant defined by the hypervisor API (e.g., kvm.h). args are the arguments for enabling the feature, if any.

§Safety

This function is marked as unsafe because args may be interpreted as pointers for some capabilities. The caller must ensure that any pointers passed in the args array are allocated as the kernel expects, and that mutable pointers are owned.

Provided Methods§

Source

fn handle_hypercall( &self, _handle_fn: &mut dyn FnMut(&mut HypercallAbi) -> Result<()>, ) -> Result<()>

Handles an incoming hypercall from the guest.

Implementors§