Skip to content
This repository has been archived by the owner on Sep 1, 2024. It is now read-only.

Commit

Permalink
GuestActivityState Enum created
Browse files Browse the repository at this point in the history
  • Loading branch information
memN0ps committed Mar 3, 2024
1 parent cc17f93 commit d9b52bd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions hypervisor/src/intel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod page;
pub mod paging;
pub mod segmentation;
pub mod shared;
pub mod state;
pub mod support;
pub mod vm;
pub mod vmcs;
Expand Down
17 changes: 17 additions & 0 deletions hypervisor/src/intel/state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/// Represents the activity state of a logical processor in VMX operation.
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum GuestActivityState {
/// The logical processor is executing instructions normally.
Active = 0x00000000,

/// The logical processor is inactive because it executed the HLT instruction.
Hlt = 0x00000001,

/// The logical processor is inactive because it incurred a triple fault
/// or some other serious error.
Shutdown = 0x00000002,

/// The logical processor is inactive because it is waiting for a startup-IPI (SIPI).
WaitForSipi = 0x00000003,
}
7 changes: 5 additions & 2 deletions hypervisor/src/intel/vmexit/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use {
capture::GuestRegisters,
invvpid::invvpid_single_context,
segmentation::VmxSegmentAccessRights,
state::GuestActivityState,
support::{
cr2_write, dr0_read, dr0_write, dr1_read, dr1_write, dr2_read, dr2_write, dr3_read,
dr3_write, dr6_read, dr6_write, dr7_read, rdmsr, vmread, vmwrite,
Expand Down Expand Up @@ -218,8 +219,10 @@ pub fn handle_init_signal(guest_registers: &mut GuestRegisters) -> ExitType {
//
// Set the activity state to "Wait for SIPI".
//
let vmx_wait_for_sipi = 0x3u64;
vmwrite(vmcs::guest::ACTIVITY_STATE, vmx_wait_for_sipi);
vmwrite(
vmcs::guest::ACTIVITY_STATE,
GuestActivityState::WaitForSipi as u32,
);

ExitType::Continue
}
Expand Down
7 changes: 5 additions & 2 deletions hypervisor/src/intel/vmexit/sipi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use {
crate::intel::{
capture::GuestRegisters,
state::GuestActivityState,
support::{vmread, vmwrite},
vmexit::ExitType,
},
Expand Down Expand Up @@ -36,8 +37,10 @@ pub fn handle_sipi_signal(guest_registers: &mut GuestRegisters) -> ExitType {
guest_registers.rip = 0x0u64;
vmwrite(vmcs::guest::RIP, guest_registers.rip);

let vmx_active = 0x0u64;
vmwrite(vmcs::guest::ACTIVITY_STATE, vmx_active);
vmwrite(
vmcs::guest::ACTIVITY_STATE,
GuestActivityState::Active as u32,
);

ExitType::Continue
}

0 comments on commit d9b52bd

Please sign in to comment.