Skip to content

Commit caaa894

Browse files
committed
Add exit reason enum for Apple Silicon
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
1 parent 0d7b97a commit caaa894

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

hv-sys/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ fn main() {
1313
.allowlist_var("VM.*")
1414
.allowlist_var("IRQ.*")
1515
.derive_default(true)
16+
.derive_debug(true)
1617
.generate_comments(false)
1718
.generate()
1819
.expect("Failed to generate bindings")

hv/src/arm64/mod.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,45 @@ pub enum InterruptType {
1313
FIQ = sys::hv_interrupt_type_t_HV_INTERRUPT_TYPE_FIQ,
1414
}
1515

16+
/// Events that can trigger a guest exit to the VMM.
17+
#[repr(u32)]
18+
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
19+
pub enum ExitReason {
20+
/// Asynchronous exit requested explicitly by `hv_vcpus_exit` call.
21+
Canceled = sys::hv_exit_reason_t_HV_EXIT_REASON_CANCELED,
22+
/// Synchronous exception to EL2 triggered by the guest.
23+
Exception = sys::hv_exit_reason_t_HV_EXIT_REASON_EXCEPTION,
24+
/// ARM Generic VTimer became pending since the last hv_vcpu_run() call
25+
/// returned. The caller is expected to make the interrupt corresponding to
26+
/// the VTimer pending in the guest's interrupt controller.
27+
///
28+
/// This exit automatically sets the VTimer mask.
29+
/// The VCPU will not exit with this status again until after the mask is cleared
30+
/// with hv_vcpu_set_vtimer_mask(), which should be called during a trap of
31+
/// the EOI for the guest's VTimer interrupt handler.
32+
VTimerActivated = sys::hv_exit_reason_t_HV_EXIT_REASON_VTIMER_ACTIVATED,
33+
/// Unable to determine exit reason: this should not happen under normal operation.
34+
Unknown = sys::hv_exit_reason_t_HV_EXIT_REASON_UNKNOWN,
35+
}
36+
37+
impl Default for ExitReason {
38+
fn default() -> Self {
39+
ExitReason::Unknown
40+
}
41+
}
42+
43+
impl From<sys::hv_exit_reason_t> for ExitReason {
44+
fn from(value: sys::hv_exit_reason_t) -> Self {
45+
match value {
46+
sys::hv_exit_reason_t_HV_EXIT_REASON_CANCELED => ExitReason::Canceled,
47+
sys::hv_exit_reason_t_HV_EXIT_REASON_EXCEPTION => ExitReason::Exception,
48+
sys::hv_exit_reason_t_HV_EXIT_REASON_VTIMER_ACTIVATED => ExitReason::VTimerActivated,
49+
sys::hv_exit_reason_t_HV_EXIT_REASON_UNKNOWN => ExitReason::Unknown,
50+
_ => ExitReason::Unknown,
51+
}
52+
}
53+
}
54+
1655
/// Contains information about an exit from the vcpu to the host.
1756
pub type VcpuExit = sys::hv_vcpu_exit_t;
1857

0 commit comments

Comments
 (0)