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§
sourcefn as_vcpu(&self) -> &dyn Vcpu
fn as_vcpu(&self) -> &dyn Vcpu
Casts this architecture specific trait object to the base trait object Vcpu
.
sourcefn run(&mut self) -> Result<VcpuExit>
fn run(&mut self) -> Result<VcpuExit>
Runs the VCPU until it exits, returning the reason for the exit.
sourcefn set_immediate_exit(&self, exit: bool)
fn set_immediate_exit(&self, exit: bool)
Sets the bit that requests an immediate exit.
sourcefn signal_handle(&self) -> VcpuSignalHandle
fn signal_handle(&self) -> VcpuSignalHandle
Returns a handle that can be used to cause this VCPU to exit from run()
from a signal
handler.
sourcefn handle_mmio(
&self,
handle_fn: &mut dyn FnMut(IoParams<'_>) -> Result<()>
) -> Result<()>
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.
sourcefn handle_io(&self, handle_fn: &mut dyn FnMut(IoParams<'_>)) -> Result<()>
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.
sourcefn on_suspend(&self) -> Result<()>
fn on_suspend(&self) -> Result<()>
Signals to the hypervisor that this Vcpu is being paused by userspace.
sourceunsafe fn enable_raw_capability(&self, cap: u32, args: &[u64; 4]) -> Result<()>
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
impl dyn Vcpu
sourcepub fn is<__T: Vcpu>(&self) -> bool
pub fn is<__T: Vcpu>(&self) -> bool
Returns true if the trait object wraps an object of type __T
.
sourcepub fn downcast<__T: Vcpu>(self: Box<Self>) -> Result<Box<__T>, Box<Self>>
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.
sourcepub fn downcast_rc<__T: Vcpu>(self: Rc<Self>) -> Result<Rc<__T>, Rc<Self>>
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.
sourcepub fn downcast_ref<__T: Vcpu>(&self) -> Option<&__T>
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.
sourcepub fn downcast_mut<__T: Vcpu>(&mut self) -> Option<&mut __T>
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.