Trait hypervisor::Vcpu

source ·
pub trait Vcpu: DowncastSync {
Show 13 methods // 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) -> Option<[u8; 8]> ) -> Result<()>; fn handle_io( &self, handle_fn: &mut dyn FnMut(IoParams) -> Option<[u8; 8]> ) -> Result<()>; fn handle_hyperv_hypercall( &self, func: &mut dyn FnMut(HypervHypercall) -> u64 ) -> Result<()>; fn handle_rdmsr(&self, data: u64) -> Result<()>; fn handle_wrmsr(&self); 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) -> Option<[u8; 8]> ) -> 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) -> Option<[u8; 8]> ) -> 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 handle_hyperv_hypercall( &self, func: &mut dyn FnMut(HypervHypercall) -> u64 ) -> Result<()>

Handles the HYPERV_HYPERCALL exit from a vcpu.

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

Once called, it will parse the appropriate input parameters to the provided function to handle the hyperv call, and then set the return data into the vcpu so it can resume running.

source

fn handle_rdmsr(&self, data: u64) -> Result<()>

Handles a RDMSR exit from the guest.

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

It will put data into the guest buffer and return.

source

fn handle_wrmsr(&self)

Handles a WRMSR exit from the guest by removing any error indication for the operation.

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

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>(self: Arc<Self>) -> Result<Arc<__T>, Arc<Self>>where __T: Any + Send + Sync + Vcpu,

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§