@@ -16,9 +16,8 @@ limitations under the License.
1616
1717//! This file contains architecture specific code for the x86_64
1818
19- use std:: collections:: HashMap ;
20-
2119use super :: VcpuStopReason ;
20+ use crate :: Result ;
2221
2322// Described in Table 6-1. Exceptions and Interrupts at Page 6-13 Vol. 1
2423// of Intel 64 and IA-32 Architectures Software Developer's Manual
@@ -51,61 +50,50 @@ pub(crate) const DR6_HW_BP_FLAGS_MASK: u64 = 0x0F << DR6_HW_BP_FLAGS_POS;
5150
5251/// Determine the reason the vCPU stopped
5352/// This is done by checking the DR6 register and the exception id
54- /// NOTE: Additional checks are done for the entrypoint, stored hw_breakpoints
55- /// and sw_breakpoints to ensure the stop reason is valid with internal state
5653pub ( crate ) fn vcpu_stop_reason (
57- single_step : bool ,
5854 rip : u64 ,
59- dr6 : u64 ,
6055 entrypoint : u64 ,
56+ dr6 : u64 ,
6157 exception : u32 ,
62- hw_breakpoints : & [ u64 ] ,
63- sw_breakpoints : & HashMap < u64 , [ u8 ; SW_BP_SIZE ] > ,
64- ) -> VcpuStopReason {
58+ ) -> Result < VcpuStopReason > {
6559 if DB_EX_ID == exception {
6660 // If the BS flag in DR6 register is set, it means a single step
6761 // instruction triggered the exit
6862 // Check page 19-4 Vol. 3B of Intel 64 and IA-32
6963 // Architectures Software Developer's Manual
70- if dr6 & DR6_BS_FLAG_MASK != 0 && single_step {
71- return VcpuStopReason :: DoneStep ;
64+ if dr6 & DR6_BS_FLAG_MASK != 0 {
65+ return Ok ( VcpuStopReason :: DoneStep ) ;
7266 }
7367
7468 // If any of the B0-B3 flags in DR6 register is set, it means a
7569 // hardware breakpoint triggered the exit
7670 // Check page 19-4 Vol. 3B of Intel 64 and IA-32
7771 // Architectures Software Developer's Manual
78- if DR6_HW_BP_FLAGS_MASK & dr6 != 0 && hw_breakpoints . contains ( & rip ) {
72+ if DR6_HW_BP_FLAGS_MASK & dr6 != 0 {
7973 if rip == entrypoint {
80- return VcpuStopReason :: EntryPointBp ;
74+ return Ok ( VcpuStopReason :: EntryPointBp ) ;
8175 }
82- return VcpuStopReason :: HwBp ;
76+ return Ok ( VcpuStopReason :: HwBp ) ;
8377 }
8478 }
8579
86- if BP_EX_ID == exception && sw_breakpoints . contains_key ( & rip ) {
87- return VcpuStopReason :: SwBp ;
80+ if BP_EX_ID == exception {
81+ return Ok ( VcpuStopReason :: SwBp ) ;
8882 }
8983
9084 // Log an error and provide internal debugging info
9185 log:: error!(
9286 r"The vCPU exited because of an unknown reason:
93- single_step: {:?}
9487 rip: {:?}
9588 dr6: {:?}
9689 entrypoint: {:?}
9790 exception: {:?}
98- hw_breakpoints: {:?}
99- sw_breakpoints: {:?}
10091 " ,
101- single_step,
10292 rip,
10393 dr6,
10494 entrypoint,
10595 exception,
106- hw_breakpoints,
107- sw_breakpoints,
10896 ) ;
10997
110- VcpuStopReason :: Unknown
98+ Ok ( VcpuStopReason :: Unknown )
11199}
0 commit comments