@@ -16,16 +16,17 @@ limitations under the License.
16
16
17
17
//! This file contains architecture specific code for the x86_64
18
18
19
- use std:: collections:: HashMap ;
20
-
21
19
use super :: VcpuStopReason ;
20
+ use crate :: hypervisor:: regs:: CommonRegisters ;
21
+ use crate :: hypervisor:: vm:: Vm ;
22
+ use crate :: Result ;
22
23
23
24
// Described in Table 6-1. Exceptions and Interrupts at Page 6-13 Vol. 1
24
25
// of Intel 64 and IA-32 Architectures Software Developer's Manual
25
26
/// Exception id for #DB
26
- const DB_EX_ID : u32 = 1 ;
27
+ pub ( crate ) const DB_EX_ID : u32 = 1 ;
27
28
/// Exception id for #BP - triggered by the INT3 instruction
28
- const BP_EX_ID : u32 = 3 ;
29
+ pub ( crate ) const BP_EX_ID : u32 = 3 ;
29
30
30
31
/// Software Breakpoint size in memory
31
32
pub ( crate ) const SW_BP_SIZE : usize = 1 ;
@@ -54,58 +55,51 @@ pub(crate) const DR6_HW_BP_FLAGS_MASK: u64 = 0x0F << DR6_HW_BP_FLAGS_POS;
54
55
/// NOTE: Additional checks are done for the entrypoint, stored hw_breakpoints
55
56
/// and sw_breakpoints to ensure the stop reason is valid with internal state
56
57
pub ( crate ) fn vcpu_stop_reason (
57
- single_step : bool ,
58
- rip : u64 ,
59
- dr6 : u64 ,
58
+ vm : & mut dyn Vm ,
60
59
entrypoint : u64 ,
60
+ dr6 : u64 ,
61
61
exception : u32 ,
62
- hw_breakpoints : & [ u64 ] ,
63
- sw_breakpoints : & HashMap < u64 , [ u8 ; SW_BP_SIZE ] > ,
64
- ) -> VcpuStopReason {
62
+ ) -> Result < VcpuStopReason > {
63
+ let CommonRegisters { rip, .. } = vm. get_regs ( ) ?;
65
64
if DB_EX_ID == exception {
66
65
// If the BS flag in DR6 register is set, it means a single step
67
66
// instruction triggered the exit
68
67
// Check page 19-4 Vol. 3B of Intel 64 and IA-32
69
68
// Architectures Software Developer's Manual
70
- if dr6 & DR6_BS_FLAG_MASK != 0 && single_step {
71
- return VcpuStopReason :: DoneStep ;
69
+ if dr6 & DR6_BS_FLAG_MASK != 0 {
70
+ return Ok ( VcpuStopReason :: DoneStep ) ;
72
71
}
73
72
74
73
// If any of the B0-B3 flags in DR6 register is set, it means a
75
74
// hardware breakpoint triggered the exit
76
75
// Check page 19-4 Vol. 3B of Intel 64 and IA-32
77
76
// Architectures Software Developer's Manual
78
- if DR6_HW_BP_FLAGS_MASK & dr6 != 0 && hw_breakpoints . contains ( & rip ) {
77
+ if DR6_HW_BP_FLAGS_MASK & dr6 != 0 {
79
78
if rip == entrypoint {
80
- return VcpuStopReason :: EntryPointBp ;
79
+ vm. remove_hw_breakpoint ( entrypoint) ?;
80
+ return Ok ( VcpuStopReason :: EntryPointBp ) ;
81
81
}
82
- return VcpuStopReason :: HwBp ;
82
+ return Ok ( VcpuStopReason :: HwBp ) ;
83
83
}
84
84
}
85
85
86
- if BP_EX_ID == exception && sw_breakpoints . contains_key ( & rip ) {
87
- return VcpuStopReason :: SwBp ;
86
+ if BP_EX_ID == exception {
87
+ return Ok ( VcpuStopReason :: SwBp ) ;
88
88
}
89
89
90
90
// Log an error and provide internal debugging info
91
91
log:: error!(
92
92
r"The vCPU exited because of an unknown reason:
93
- single_step: {:?}
94
93
rip: {:?}
95
94
dr6: {:?}
96
95
entrypoint: {:?}
97
96
exception: {:?}
98
- hw_breakpoints: {:?}
99
- sw_breakpoints: {:?}
100
97
" ,
101
- single_step,
102
98
rip,
103
99
dr6,
104
100
entrypoint,
105
101
exception,
106
- hw_breakpoints,
107
- sw_breakpoints,
108
102
) ;
109
103
110
- VcpuStopReason :: Unknown
104
+ Ok ( VcpuStopReason :: Unknown )
111
105
}
0 commit comments