pub struct Vcpu {
pub(crate) vcpu: File,
pub(crate) run_mmap: MemoryMapping,
}Expand description
A wrapper around creating and using a VCPU.
Vcpu provides all functionality except for running. To run, to_runnable must be called to
lock the vcpu to a thread. Then the returned RunnableVcpu can be used for running.
Fields§
§vcpu: File§run_mmap: MemoryMappingImplementations§
source§impl Vcpu
impl Vcpu
sourcepub fn new(id: c_ulong, kvm: &Kvm, vm: &Vm) -> Result<Vcpu>
pub fn new(id: c_ulong, kvm: &Kvm, vm: &Vm) -> Result<Vcpu>
Constructs a new VCPU for vm.
The id argument is the CPU number between [0, max vcpus).
sourcepub fn to_runnable(self, signal_num: Option<c_int>) -> Result<RunnableVcpu>
pub fn to_runnable(self, signal_num: Option<c_int>) -> Result<RunnableVcpu>
Consumes self and returns a RunnableVcpu. A RunnableVcpu is required to run the
guest.
Assigns a vcpu to the current thread and stores it in a hash map that can be used by signal
handlers to call set_local_immediate_exit(). An optional signal number will be temporarily
blocked while assigning the vcpu to the thread and later blocked when RunnableVcpu is
destroyed.
Returns an error, EBUSY, if the current thread already contains a Vcpu.
sourcepub fn set_data(&self, data: &[u8]) -> Result<()>
pub fn set_data(&self, data: &[u8]) -> Result<()>
Sets the data received by a mmio read, ioport in, or hypercall instruction.
This function should be called after Vcpu::run returns an VcpuExit::IoIn,
VcpuExit::MmioRead, or ’VcpuExit::HypervHcall`.
sourcepub fn set_immediate_exit(&self, exit: bool)
pub fn set_immediate_exit(&self, exit: bool)
Sets the bit that requests an immediate exit.
sourcepub fn set_local_immediate_exit(exit: bool)
pub fn set_local_immediate_exit(exit: bool)
Sets/clears the bit for immediate exit for the vcpu on the current thread.
sourcepub fn set_fpu(&self, fpu: &kvm_fpu) -> Result<()>
pub fn set_fpu(&self, fpu: &kvm_fpu) -> Result<()>
X86 specific call to setup the FPU
See the documentation for KVM_SET_FPU.
sourcepub fn get_debugregs(&self) -> Result<kvm_debugregs>
pub fn get_debugregs(&self) -> Result<kvm_debugregs>
Gets the VCPU debug registers.
sourcepub fn set_debugregs(&self, dregs: &kvm_debugregs) -> Result<()>
pub fn set_debugregs(&self, dregs: &kvm_debugregs) -> Result<()>
Sets the VCPU debug registers
sourcepub fn get_msrs(&self, msr_entries: &mut Vec<kvm_msr_entry>) -> Result<()>
pub fn get_msrs(&self, msr_entries: &mut Vec<kvm_msr_entry>) -> Result<()>
X86 specific call to get the MSRS
See the documentation for KVM_SET_MSRS.
sourcepub fn set_msrs(&self, msrs: &kvm_msrs) -> Result<()>
pub fn set_msrs(&self, msrs: &kvm_msrs) -> Result<()>
X86 specific call to setup the MSRS
See the documentation for KVM_SET_MSRS.
sourcepub fn set_cpuid2(&self, cpuid: &CpuId) -> Result<()>
pub fn set_cpuid2(&self, cpuid: &CpuId) -> Result<()>
X86 specific call to setup the CPUID registers
See the documentation for KVM_SET_CPUID2.
sourcepub fn get_hyperv_cpuid(&self) -> Result<CpuId>
pub fn get_hyperv_cpuid(&self) -> Result<CpuId>
X86 specific call to get the system emulated hyper-v CPUID values
sourcepub fn get_lapic(&self) -> Result<kvm_lapic_state>
pub fn get_lapic(&self) -> Result<kvm_lapic_state>
X86 specific call to get the state of the “Local Advanced Programmable Interrupt Controller”.
See the documentation for KVM_GET_LAPIC.
sourcepub fn set_lapic(&self, klapic: &kvm_lapic_state) -> Result<()>
pub fn set_lapic(&self, klapic: &kvm_lapic_state) -> Result<()>
X86 specific call to set the state of the “Local Advanced Programmable Interrupt Controller”.
See the documentation for KVM_SET_LAPIC.
sourcepub fn get_mp_state(&self) -> Result<kvm_mp_state>
pub fn get_mp_state(&self) -> Result<kvm_mp_state>
Gets the vcpu’s current “multiprocessing state”.
See the documentation for KVM_GET_MP_STATE. This call can only succeed after
a call to Vm::create_irq_chip.
Note that KVM defines the call for both x86 and s390 but we do not expect anyone to run crosvm on s390.
sourcepub fn set_mp_state(&self, state: &kvm_mp_state) -> Result<()>
pub fn set_mp_state(&self, state: &kvm_mp_state) -> Result<()>
Sets the vcpu’s current “multiprocessing state”.
See the documentation for KVM_SET_MP_STATE. This call can only succeed after
a call to Vm::create_irq_chip.
Note that KVM defines the call for both x86 and s390 but we do not expect anyone to run crosvm on s390.
sourcepub fn get_vcpu_events(&self) -> Result<kvm_vcpu_events>
pub fn get_vcpu_events(&self) -> Result<kvm_vcpu_events>
Gets the vcpu’s currently pending exceptions, interrupts, NMIs, etc
See the documentation for KVM_GET_VCPU_EVENTS.
sourcepub fn set_vcpu_events(&self, events: &kvm_vcpu_events) -> Result<()>
pub fn set_vcpu_events(&self, events: &kvm_vcpu_events) -> Result<()>
Sets the vcpu’s currently pending exceptions, interrupts, NMIs, etc
See the documentation for KVM_SET_VCPU_EVENTS.
sourcepub unsafe fn kvm_enable_cap(&self, cap: &kvm_enable_cap) -> Result<()>
pub unsafe fn kvm_enable_cap(&self, cap: &kvm_enable_cap) -> Result<()>
Enable the specified capability. See documentation for KVM_ENABLE_CAP.
§Safety
This function is marked as unsafe because cap may contain values which are interpreted as
pointers by the kernel.
sourcepub fn set_signal_mask(&self, signals: &[c_int]) -> Result<()>
pub fn set_signal_mask(&self, signals: &[c_int]) -> Result<()>
Specifies set of signals that are blocked during execution of KVM_RUN. Signals that are not blocked will cause KVM_RUN to return with -EINTR.
See the documentation for KVM_SET_SIGNAL_MASK