use crate::{Architecture, Registers, VcpuId, View};
bitflags::bitflags! {
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct VmiEventFlags: u8 {
const VCPU_PAUSED = 1 << 0;
}
}
#[derive(Debug, Clone, Copy)]
pub struct VmiEvent<Arch>
where
Arch: Architecture,
{
vcpu_id: VcpuId,
flags: VmiEventFlags,
view: Option<View>,
registers: Arch::Registers,
reason: Arch::EventReason,
}
impl<Arch> VmiEvent<Arch>
where
Arch: Architecture,
{
pub fn new(
vcpu_id: VcpuId,
flags: VmiEventFlags,
view: Option<View>,
registers: Arch::Registers,
reason: Arch::EventReason,
) -> Self {
Self {
vcpu_id,
flags,
view,
registers,
reason,
}
}
pub fn vcpu_id(&self) -> VcpuId {
self.vcpu_id
}
pub fn flags(&self) -> VmiEventFlags {
self.flags
}
pub fn view(&self) -> Option<View> {
self.view
}
pub fn registers(&self) -> &Arch::Registers {
&self.registers
}
pub fn reason(&self) -> &Arch::EventReason {
&self.reason
}
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub enum VmiEventAction {
#[default]
Continue,
Deny,
ReinjectInterrupt,
Singlestep,
FastSinglestep,
Emulate,
}
#[derive(Debug)]
pub struct VmiEventResponse<Arch>
where
Arch: Architecture,
{
pub action: VmiEventAction,
pub view: Option<View>,
pub registers: Option<<Arch::Registers as Registers>::GpRegisters>,
}
impl<Arch> Default for VmiEventResponse<Arch>
where
Arch: Architecture,
{
fn default() -> Self {
Self {
action: VmiEventAction::Continue,
view: None,
registers: None,
}
}
}
impl<Arch> VmiEventResponse<Arch>
where
Arch: Architecture,
{
pub fn deny() -> Self {
Self {
action: VmiEventAction::Deny,
..Self::default()
}
}
pub fn reinject_interrupt() -> Self {
Self {
action: VmiEventAction::ReinjectInterrupt,
..Self::default()
}
}
pub fn singlestep() -> Self {
Self {
action: VmiEventAction::Singlestep,
..Self::default()
}
}
pub fn fast_singlestep(view: View) -> Self {
Self {
action: VmiEventAction::FastSinglestep,
view: Some(view),
..Self::default()
}
}
pub fn emulate() -> Self {
Self {
action: VmiEventAction::Emulate,
..Self::default()
}
}
pub fn with_view(self, view: View) -> Self {
Self {
view: Some(view),
..self
}
}
pub fn with_registers(self, registers: <Arch::Registers as Registers>::GpRegisters) -> Self {
Self {
registers: Some(registers),
..self
}
}
}