File tree 6 files changed +12
-13
lines changed
6 files changed +12
-13
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,6 @@ use num_enum::TryFromPrimitive;
16
16
/// SDT (the end of the Creator Revision at offset 36).
17
17
mod offsets {
18
18
use super :: * ;
19
-
20
19
/// 32-bit physical address at which each processor can access its
21
20
/// local APIC.
22
21
pub const LOCAL_INT_CTRL_ADDR : Range < usize > = 0 ..4 ;
Original file line number Diff line number Diff line change @@ -43,11 +43,11 @@ pub enum VmInstructionError {
43
43
InvalidOperandToInveptInvvpid = 28 ,
44
44
}
45
45
46
- pub fn check_vm_instruction ( rflags : u64 , error : & str ) -> Result < ( ) > {
46
+ pub fn check_vm_instruction ( rflags : u64 , log_error : impl Fn ( ) ) -> Result < ( ) > {
47
47
let rflags = rflags:: RFlags :: from_bits_truncate ( rflags) ;
48
48
49
49
if rflags. contains ( RFlags :: FLAGS_CF ) {
50
- error ! ( "{}" , error ) ;
50
+ log_error ( ) ;
51
51
Err ( Error :: VmFailInvalid )
52
52
} else if rflags. contains ( RFlags :: FLAGS_ZF ) {
53
53
let errno = unsafe {
@@ -63,7 +63,7 @@ pub fn check_vm_instruction(rflags: u64, error: &str) -> Result<()> {
63
63
. unwrap_or ( VmInstructionError :: UnknownError ) ;
64
64
65
65
error ! ( "{:?}" , vm_error) ;
66
- error ! ( "{}" , error ) ;
66
+ log_error ( ) ;
67
67
Err ( Error :: VmFailValid )
68
68
} else {
69
69
Ok ( ( ) )
Original file line number Diff line number Diff line change @@ -171,7 +171,7 @@ impl VCpu {
171
171
/// Begin execution in the guest context for this core
172
172
pub fn launch ( & mut self ) -> Result < !> {
173
173
let rflags = unsafe { vmlaunch_wrapper ( ) } ;
174
- error:: check_vm_instruction ( rflags, "Failed to launch vm" ) ?;
174
+ error:: check_vm_instruction ( rflags, || error ! ( "Failed to launch vm" ) ) ?;
175
175
176
176
unreachable ! ( )
177
177
}
Original file line number Diff line number Diff line change @@ -335,7 +335,7 @@ fn vmcs_write(field: VmcsField, value: u64) -> Result<()> {
335
335
336
336
error:: check_vm_instruction (
337
337
rflags,
338
- format ! ( "Failed to write 0x{:x} to field {:?}" , value, field) . as_str ( ) ,
338
+ || error ! ( "Failed to write 0x{:x} to field {:?}" , value, field) ,
339
339
)
340
340
}
341
341
@@ -369,7 +369,7 @@ fn vmcs_activate(vmcs: &mut Vmcs, _vmx: &vmx::Vmx) -> Result<()> {
369
369
rflags
370
370
} ;
371
371
372
- error:: check_vm_instruction ( rflags, "Failed to activate VMCS" )
372
+ error:: check_vm_instruction ( rflags, || error ! ( "Failed to activate VMCS" ) )
373
373
}
374
374
375
375
fn vmcs_clear ( vmcs_page : & mut Raw4kPage ) -> Result < ( ) > {
@@ -382,7 +382,7 @@ fn vmcs_clear(vmcs_page: &mut Raw4kPage) -> Result<()> {
382
382
: "volatile" ) ;
383
383
rflags
384
384
} ;
385
- error:: check_vm_instruction ( rflags, "Failed to clear VMCS" )
385
+ error:: check_vm_instruction ( rflags, || error ! ( "Failed to clear VMCS" ) )
386
386
}
387
387
388
388
pub struct Vmcs {
Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ pub extern "C" fn vmexit_handler(state: *mut GuestCpuState) {
54
54
55
55
#[ no_mangle]
56
56
pub extern "C" fn vmresume_failure_handler ( rflags : u64 ) {
57
- error:: check_vm_instruction ( rflags, "Failed to vmresume" )
57
+ error:: check_vm_instruction ( rflags, || error ! ( "Failed to vmresume" ) )
58
58
. expect ( "vmresume failed" ) ;
59
59
}
60
60
Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ impl Vmx {
52
52
rflags
53
53
} ;
54
54
55
- error:: check_vm_instruction ( rflags, "Failed to enable vmx" ) ?;
55
+ error:: check_vm_instruction ( rflags, || error ! ( "Failed to enable vmx" ) ) ?;
56
56
Ok ( Vmx {
57
57
_vmxon_region : vmxon_region,
58
58
} )
@@ -70,7 +70,7 @@ impl Vmx {
70
70
rflags
71
71
} ;
72
72
73
- error:: check_vm_instruction ( rflags, "Failed to disable vmx" )
73
+ error:: check_vm_instruction ( rflags, || error ! ( "Failed to disable vmx" ) )
74
74
}
75
75
76
76
pub fn revision ( ) -> u32 {
@@ -90,7 +90,7 @@ impl Vmx {
90
90
: "m" ( val) , "r" ( t) ) ;
91
91
rflags
92
92
} ;
93
- error:: check_vm_instruction ( rflags, "Failed to execute invept" )
93
+ error:: check_vm_instruction ( rflags, || error ! ( "Failed to execute invept" ) )
94
94
}
95
95
96
96
pub fn invvpid ( & self , mode : InvVpidMode ) -> Result < ( ) > {
@@ -112,7 +112,7 @@ impl Vmx {
112
112
: "m" ( val) , "r" ( t) ) ;
113
113
rflags
114
114
} ;
115
- error:: check_vm_instruction ( rflags, "Failed to execute invvpid" )
115
+ error:: check_vm_instruction ( rflags, || error ! ( "Failed to execute invvpid" ) )
116
116
}
117
117
}
118
118
You can’t perform that action at this time.
0 commit comments