Skip to content

Commit 2d6fd66

Browse files
autoreformat.
1 parent 00ff70d commit 2d6fd66

File tree

3 files changed

+31
-31
lines changed

3 files changed

+31
-31
lines changed

mythril/src/emulate/cpuid.rs

+27-26
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
use crate::apic::get_local_apic;
12
use crate::error::Result;
3+
use crate::vcpu::VCpu;
24
use crate::{vcpu, vmexit};
3-
use raw_cpuid::CpuIdResult;
45
use arrayvec::ArrayVec;
5-
use core::convert::TryInto;
66
use bitfield::bitfield;
77
use bitflags::_core::num::flt2dec::to_shortest_exp_str;
8-
use crate::apic::get_local_apic;
9-
use crate::vcpu::VCpu;
8+
use core::convert::TryInto;
9+
use raw_cpuid::CpuIdResult;
1010

1111
const CPUID_NAME: u32 = 0;
1212
const CPUID_MODEL_FAMILY_STEPPING: u32 = 1;
@@ -26,13 +26,13 @@ const MAX_CPUID_INPUT: u32 = 0x80000008;
2626
//todo //CPUID leaves above 2 and below 80000000H are visible only when
2727
// // IA32_MISC_ENABLE[bit 22] has its default value of 0.
2828

29-
30-
31-
32-
33-
fn get_cpu_id_result(vcpu: &vcpu::VCpu, eax_in: u32, ecx_in: u32) -> CpuIdResult {
34-
const NAME_CREATION_ERROR_MESSAGE: &'static str = "Somehow bytes was not actually a 12 element array";
35-
29+
fn get_cpu_id_result(
30+
vcpu: &vcpu::VCpu,
31+
eax_in: u32,
32+
ecx_in: u32,
33+
) -> CpuIdResult {
34+
const NAME_CREATION_ERROR_MESSAGE: &'static str =
35+
"Somehow bytes was not actually a 12 element array";
3636

3737
let mut actual = raw_cpuid::native_cpuid::cpuid_count(
3838
guest_cpu.rax as u32,
@@ -100,8 +100,6 @@ bitfield! {
100100
max_addressable_ids_physical,_:26,31;
101101
}
102102

103-
104-
105103
fn intel_cache_topo(mut actual: CpuIdResult) -> CpuIdResult {
106104
let mut cache_topo_eax = IntelCoreCacheTopologyEaxRes(actual.eax);
107105
cache_topo_eax.set_max_addressable_ids_logical(todo!("waiting on apics"));
@@ -112,7 +110,7 @@ fn intel_cache_topo(mut actual: CpuIdResult) -> CpuIdResult {
112110
//no changes should be required for these:
113111
ebx: actual.ebx,
114112
ecx: actual.ecx,
115-
edx: actual.edx
113+
edx: actual.edx,
116114
}
117115
}
118116

@@ -152,12 +150,14 @@ bitfield! {
152150
}
153151

154152
fn cpuid_model_family_stepping(actual: CpuIdResult) -> CpuIdResult {
155-
let family_model_stepping = IntelTypeFamilyModelSteppingIDEaxRes(actual.eax);
153+
let family_model_stepping =
154+
IntelTypeFamilyModelSteppingIDEaxRes(actual.eax);
156155
//we can change family_model_stepping, but for now just use actual.
157156
let eax = family_model_stepping.0;
158157
let mut brand_cflush_max_initial = BrandCFlushMaxIDsInitialAPIC(actual.ebx);
159158
brand_cflush_max_initial.set_apic_id(todo!("Waiting on virtual APICs"));
160-
brand_cflush_max_initial.set_max_processor_ids(todo!("Waiting on virtual APICs"));
159+
brand_cflush_max_initial
160+
.set_max_processor_ids(todo!("Waiting on virtual APICs"));
161161
let ebx = brand_cflush_max_initial.0;
162162
let mut features_ecx = FeatureInformationECX(actual.ecx);
163163
let mut features_edx = FeatureInformationEDX(actual.edx);
@@ -174,21 +174,22 @@ fn cpuid_model_family_stepping(actual: CpuIdResult) -> CpuIdResult {
174174
features_ecx.set_hypervisor(0);
175175
let ecx = features_ecx.0;
176176
let edx = features_edx.0;
177-
CpuIdResult {
178-
eax,
179-
ebx,
180-
ecx,
181-
edx
182-
}
177+
CpuIdResult { eax, ebx, ecx, edx }
183178
}
184179

185180
fn cpuid_name(vcpu: &VCpu, actual: CpuIdResult) -> CpuIdResult {
186181
if vcpu.vm.read().config.override_cpu_name() {
187182
let cpu_name = "MythrilCPU__";
188-
let bytes = cpu_name.chars().map(|char| char as u8).collect::<ArrayVec<[u8; 12]>>();
189-
let first_bytes: [u8; 4] = bytes[0..4].try_into().expect(NAME_CREATION_ERROR_MESSAGE);
190-
let second_bytes: [u8; 4] = bytes[4..8].try_into().expect(NAME_CREATION_ERROR_MESSAGE);
191-
let third_bytes: [u8; 4] = bytes[8..12].try_into().expect(NAME_CREATION_ERROR_MESSAGE);
183+
let bytes = cpu_name
184+
.chars()
185+
.map(|char| char as u8)
186+
.collect::<ArrayVec<[u8; 12]>>();
187+
let first_bytes: [u8; 4] =
188+
bytes[0..4].try_into().expect(NAME_CREATION_ERROR_MESSAGE);
189+
let second_bytes: [u8; 4] =
190+
bytes[4..8].try_into().expect(NAME_CREATION_ERROR_MESSAGE);
191+
let third_bytes: [u8; 4] =
192+
bytes[8..12].try_into().expect(NAME_CREATION_ERROR_MESSAGE);
192193
return CpuIdResult {
193194
eax: MAX_CPUID_INPUT,
194195
ebx: u32::from_le_bytes(first_bytes),

mythril/src/vcpu.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub struct VCpu {
9494
pub local_apic: virtdev::lapic::LocalApic,
9595
pending_interrupts: BTreeMap<u8, InjectedInterruptType>,
9696
stack: Vec<u8>,
97-
vcpu_apic_id: usize
97+
vcpu_apic_id: usize,
9898
}
9999

100100
impl VCpu {

mythril/src/vm.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ pub struct VirtualMachineConfig {
301301
virtual_devices: DeviceMap,
302302
physical_devices: PhysicalDeviceConfig,
303303
memory: u64, // in MB
304-
override_cpu_name: bool
304+
override_cpu_name: bool,
305305
}
306306

307307
impl VirtualMachineConfig {
@@ -322,8 +322,8 @@ impl VirtualMachineConfig {
322322
cpus: cpu_array,
323323
images: vec![],
324324
virtual_devices: DeviceMap::default(),
325-
physical_devices: physical_devices,
326-
memory: memory,
325+
physical_devices,
326+
memory,
327327
override_cpu_name: todo!()
328328
})
329329
}
@@ -366,7 +366,6 @@ impl VirtualMachineConfig {
366366
self.cpus[0]
367367
}
368368

369-
370369
pub fn override_cpu_name(&self) -> bool {
371370
self.override_cpu_name
372371
}

0 commit comments

Comments
 (0)