Skip to content

Commit 01d00f5

Browse files
got rid of one last format!
1 parent d8610fe commit 01d00f5

File tree

6 files changed

+12
-13
lines changed

6 files changed

+12
-13
lines changed

mythril/src/acpi/madt.rs

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use num_enum::TryFromPrimitive;
1616
/// SDT (the end of the Creator Revision at offset 36).
1717
mod offsets {
1818
use super::*;
19-
2019
/// 32-bit physical address at which each processor can access its
2120
/// local APIC.
2221
pub const LOCAL_INT_CTRL_ADDR: Range<usize> = 0..4;

mythril/src/error.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ pub enum VmInstructionError {
4343
InvalidOperandToInveptInvvpid = 28,
4444
}
4545

46-
pub fn check_vm_instruction(rflags: u64, error: &str) -> Result<()> {
46+
pub fn check_vm_instruction(rflags: u64, log_error: impl Fn()) -> Result<()> {
4747
let rflags = rflags::RFlags::from_bits_truncate(rflags);
4848

4949
if rflags.contains(RFlags::FLAGS_CF) {
50-
error!("{}", error);
50+
log_error();
5151
Err(Error::VmFailInvalid)
5252
} else if rflags.contains(RFlags::FLAGS_ZF) {
5353
let errno = unsafe {
@@ -63,7 +63,7 @@ pub fn check_vm_instruction(rflags: u64, error: &str) -> Result<()> {
6363
.unwrap_or(VmInstructionError::UnknownError);
6464

6565
error!("{:?}", vm_error);
66-
error!("{}", error);
66+
log_error();
6767
Err(Error::VmFailValid)
6868
} else {
6969
Ok(())

mythril/src/vcpu.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl VCpu {
171171
/// Begin execution in the guest context for this core
172172
pub fn launch(&mut self) -> Result<!> {
173173
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"))?;
175175

176176
unreachable!()
177177
}

mythril/src/vmcs.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ fn vmcs_write(field: VmcsField, value: u64) -> Result<()> {
335335

336336
error::check_vm_instruction(
337337
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),
339339
)
340340
}
341341

@@ -369,7 +369,7 @@ fn vmcs_activate(vmcs: &mut Vmcs, _vmx: &vmx::Vmx) -> Result<()> {
369369
rflags
370370
};
371371

372-
error::check_vm_instruction(rflags, "Failed to activate VMCS")
372+
error::check_vm_instruction(rflags, ||error!("Failed to activate VMCS"))
373373
}
374374

375375
fn vmcs_clear(vmcs_page: &mut Raw4kPage) -> Result<()> {
@@ -382,7 +382,7 @@ fn vmcs_clear(vmcs_page: &mut Raw4kPage) -> Result<()> {
382382
: "volatile");
383383
rflags
384384
};
385-
error::check_vm_instruction(rflags, "Failed to clear VMCS")
385+
error::check_vm_instruction(rflags, ||error!("Failed to clear VMCS"))
386386
}
387387

388388
pub struct Vmcs {

mythril/src/vmexit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub extern "C" fn vmexit_handler(state: *mut GuestCpuState) {
5454

5555
#[no_mangle]
5656
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"))
5858
.expect("vmresume failed");
5959
}
6060

mythril/src/vmx.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl Vmx {
5252
rflags
5353
};
5454

55-
error::check_vm_instruction(rflags, "Failed to enable vmx")?;
55+
error::check_vm_instruction(rflags, ||error!("Failed to enable vmx"))?;
5656
Ok(Vmx {
5757
_vmxon_region: vmxon_region,
5858
})
@@ -70,7 +70,7 @@ impl Vmx {
7070
rflags
7171
};
7272

73-
error::check_vm_instruction(rflags, "Failed to disable vmx")
73+
error::check_vm_instruction(rflags, ||error!("Failed to disable vmx"))
7474
}
7575

7676
pub fn revision() -> u32 {
@@ -90,7 +90,7 @@ impl Vmx {
9090
: "m"(val), "r"(t));
9191
rflags
9292
};
93-
error::check_vm_instruction(rflags, "Failed to execute invept")
93+
error::check_vm_instruction(rflags, ||error!("Failed to execute invept"))
9494
}
9595

9696
pub fn invvpid(&self, mode: InvVpidMode) -> Result<()> {
@@ -112,7 +112,7 @@ impl Vmx {
112112
: "m"(val), "r"(t));
113113
rflags
114114
};
115-
error::check_vm_instruction(rflags, "Failed to execute invvpid")
115+
error::check_vm_instruction(rflags, ||error!("Failed to execute invvpid"))
116116
}
117117
}
118118

0 commit comments

Comments
 (0)