Trait hypervisor::Vcpu

source ·
pub trait Vcpu: DowncastSync {
    // Required methods
    fn try_clone(&self) -> Result<Self>
       where Self: Sized;
    fn as_vcpu(&self) -> &dyn Vcpu;
    fn run(&mut 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<()>;
}
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 try_clone(&self) -> Result<Self>
where Self: Sized,

Makes a shallow clone of this Vcpu.

source

fn as_vcpu(&self) -> &dyn Vcpu

Casts this architecture specific trait object to the base trait object Vcpu.

source

fn run(&mut 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.

Implementations§

source§

impl dyn Vcpu

source

pub fn is<__T: Vcpu>(&self) -> bool

Returns true if the trait object wraps an object of type __T.

source

pub fn downcast<__T: Vcpu>(self: Box<Self>) -> Result<Box<__T>, Box<Self>>

Returns a boxed object from a boxed trait object if the underlying object is of type __T. Returns the original boxed trait if it isn’t.

source

pub fn downcast_rc<__T: Vcpu>(self: Rc<Self>) -> Result<Rc<__T>, Rc<Self>>

Returns an Rc-ed object from an Rc-ed trait object if the underlying object is of type __T. Returns the original Rc-ed trait if it isn’t.

source

pub fn downcast_ref<__T: Vcpu>(&self) -> Option<&__T>

Returns a reference to the object within the trait object if it is of type __T, or None if it isn’t.

source

pub fn downcast_mut<__T: Vcpu>(&mut self) -> Option<&mut __T>

Returns a mutable reference to the object within the trait object if it is of type __T, or None if it isn’t.

source

pub fn downcast_arc<__T: Vcpu + Any + Send + Sync>( self: Arc<Self> ) -> Result<Arc<__T>, Arc<Self>>

Returns an Arc-ed object from an Arc-ed trait object if the underlying object is of type __T. Returns the original Arc-ed trait if it isn’t.

Implementors§