Skip to content

Commit 56bd9a9

Browse files
committed
[*] clippy fix and fmt
Signed-off-by: danbugs <[email protected]>
1 parent 6412927 commit 56bd9a9

File tree

15 files changed

+58
-39
lines changed

15 files changed

+58
-39
lines changed

src/hyperlight_common/src/hyperlight_peb.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ impl HyperlightPEB {
111111
let guest_heap_size = self.get_guest_heap_data_size();
112112

113113
self.set_guest_error_data_region(
114-
guest_stack_size + guest_heap_size as u64, // start at the end of the host function details
115-
PAGE_SIZE as u64, // 4KB
114+
guest_stack_size + guest_heap_size, // start at the end of the host function details
115+
PAGE_SIZE as u64, // 4KB
116116
);
117117

118118
self.set_host_error_data_region(

src/hyperlight_guest/src/gdt.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ struct GdtPointer {
7272
}
7373

7474
/// Load the GDT
75+
///
76+
/// # Safety
77+
/// TODO
7578
pub unsafe fn load_gdt() {
7679
let gdt_ptr = GdtPointer {
7780
size: (core::mem::size_of::<[GdtEntry; 3]>() - 1) as u16,

src/hyperlight_guest/src/guest_function_call.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ fn internal_dispatch_function() -> Result<()> {
9898
set_error(e.kind.clone(), e.message.as_str());
9999
})?;
100100

101-
Ok(output_data_section
101+
output_data_section
102102
.push_shared_output_data(result_vec)
103-
.unwrap())
103+
.unwrap();
104+
Ok(())
104105
}
105106

106107
// This is implemented as a separate function to make sure that epilogue in the internal_dispatch_function is called before the halt()

src/hyperlight_guest/src/idtr.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,19 @@ pub struct Idtr {
1111
static mut IDTR: Idtr = Idtr { limit: 0, base: 0 };
1212

1313
impl Idtr {
14+
/// Initializes the IDTR with the given base address and size.
15+
///
16+
/// # Safety
17+
/// TODO
1418
pub unsafe fn init(&mut self, base: u64, size: u16) {
1519
self.limit = size - 1;
1620
self.base = base;
1721
}
1822

23+
/// Loads the IDTR with the current IDT.
24+
///
25+
/// # Safety
26+
/// TODO
1927
pub unsafe fn load(&self) {
2028
core::arch::asm!("lidt [{}]", in(reg) self, options(readonly, nostack, preserves_flags));
2129
}

src/hyperlight_guest/src/logging.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ use alloc::vec::Vec;
1919

2020
use hyperlight_common::flatbuffer_wrappers::guest_log_data::GuestLogData;
2121
use hyperlight_common::flatbuffer_wrappers::guest_log_level::LogLevel;
22+
use hyperlight_common::input_output::OutputDataSection;
2223

2324
use crate::host_function_call::{outb, OutBAction};
24-
use hyperlight_common::input_output::OutputDataSection;
2525
use crate::PEB;
2626

2727
fn write_log_data(

src/hyperlight_host/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ use thiserror::Error;
4141

4242
#[cfg(target_os = "windows")]
4343
use crate::hypervisor::wrappers::HandleWrapper;
44-
use crate::sandbox::sandbox_builder::MemoryRegionFlags;
4544
use crate::mem::ptr::RawPtr;
45+
use crate::sandbox::sandbox_builder::MemoryRegionFlags;
4646

4747
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
4848
pub(crate) struct HyperlightHostError {

src/hyperlight_host/src/hypervisor/gdb/mod.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use event_loop::event_loop_thread;
3131
use gdbstub::conn::ConnectionExt;
3232
use gdbstub::stub::GdbStub;
3333
use gdbstub::target::TargetError;
34-
use hyperlight_common::mem::PAGE_SIZE;
34+
use hyperlight_common::PAGE_SIZE;
3535
#[cfg(kvm)]
3636
pub(crate) use kvm_debug::KvmDebug;
3737
#[cfg(mshv)]
@@ -40,7 +40,7 @@ use thiserror::Error;
4040
use x86_64_target::HyperlightSandboxTarget;
4141

4242
use crate::hypervisor::handlers::DbgMemAccessHandlerCaller;
43-
use crate::mem::layout::SandboxMemoryLayout;
43+
use crate::sandbox::sandbox_builder::BASE_ADDRESS;
4444
use crate::{new_error, HyperlightError};
4545

4646
/// Software Breakpoint size in memory
@@ -252,14 +252,16 @@ pub(crate) trait GuestDebug {
252252

253253
let read_len = std::cmp::min(
254254
data.len(),
255-
(PAGE_SIZE - (gpa & (PAGE_SIZE - 1))).try_into().unwrap(),
255+
(PAGE_SIZE as u64 - (gpa & (PAGE_SIZE as u64 - 1)))
256+
.try_into()
257+
.unwrap(),
256258
);
257259
let offset = (gpa as usize)
258-
.checked_sub(SandboxMemoryLayout::BASE_ADDRESS)
260+
.checked_sub(BASE_ADDRESS)
259261
.ok_or_else(|| {
260262
log::warn!(
261263
"gva=0x{:#X} causes subtract with underflow: \"gpa - BASE_ADDRESS={:#X}-{:#X}\"",
262-
gva, gpa, SandboxMemoryLayout::BASE_ADDRESS);
264+
gva, gpa, BASE_ADDRESS);
263265
HyperlightError::TranslateGuestAddress(gva)
264266
})?;
265267

@@ -324,14 +326,16 @@ pub(crate) trait GuestDebug {
324326

325327
let write_len = std::cmp::min(
326328
data.len(),
327-
(PAGE_SIZE - (gpa & (PAGE_SIZE - 1))).try_into().unwrap(),
329+
(PAGE_SIZE as u64 - (gpa & (PAGE_SIZE as u64 - 1)))
330+
.try_into()
331+
.unwrap(),
328332
);
329333
let offset = (gpa as usize)
330-
.checked_sub(SandboxMemoryLayout::BASE_ADDRESS)
334+
.checked_sub(BASE_ADDRESS)
331335
.ok_or_else(|| {
332336
log::warn!(
333337
"gva=0x{:#X} causes subtract with underflow: \"gpa - BASE_ADDRESS={:#X}-{:#X}\"",
334-
gva, gpa, SandboxMemoryLayout::BASE_ADDRESS);
338+
gva, gpa, BASE_ADDRESS);
335339
HyperlightError::TranslateGuestAddress(gva)
336340
})?;
337341

src/hyperlight_host/src/hypervisor/hyperv_linux.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extern crate mshv_ioctls3 as mshv_ioctls;
2626

2727
use std::fmt::{Debug, Formatter};
2828

29-
use log::{error, LevelFilter};
29+
use log::LevelFilter;
3030
#[cfg(mshv2)]
3131
use mshv_bindings::hv_message;
3232
#[cfg(gdb)]
@@ -61,8 +61,8 @@ use super::{
6161
};
6262
use crate::hypervisor::hypervisor_handler::HypervisorHandler;
6363
use crate::hypervisor::HyperlightExit;
64-
use crate::sandbox::sandbox_builder::SandboxMemorySections;
6564
use crate::mem::ptr::{GuestPtr, RawPtr};
65+
use crate::sandbox::sandbox_builder::SandboxMemorySections;
6666
#[cfg(gdb)]
6767
use crate::HyperlightError;
6868
use crate::{log_then_return, new_error, Result};
@@ -475,9 +475,9 @@ impl Hypervisor for HypervLinuxDriver {
475475
rflags: 2, //bit 1 of rlags is required to be set
476476

477477
// function args
478-
rcx: hyperlight_peb_guest_memory_region_address.into(),
479-
rdx: hyperlight_peb_guest_memory_region_size.into(),
480-
r8: seed.into(),
478+
rcx: hyperlight_peb_guest_memory_region_address,
479+
rdx: hyperlight_peb_guest_memory_region_size,
480+
r8: seed,
481481
r9: max_guest_log_level,
482482

483483
..Default::default()
@@ -783,13 +783,13 @@ impl Hypervisor for HypervLinuxDriver {
783783
// crate::mem::memory_region::MemoryRegionType::Code,
784784
// );
785785
// super::HypervLinuxDriver::new(
786-
regions.build(),
787-
entrypoint_ptr,
788-
rsp_ptr,
789-
pml4_ptr,
790-
#[cfg(gdb)]
791-
None,
792-
)
793-
.unwrap();
786+
// regions.build(),
787+
// entrypoint_ptr,
788+
// rsp_ptr,
789+
// pml4_ptr,
790+
// #[cfg(gdb)]
791+
// None,
792+
// )
793+
// .unwrap();
794794
// }
795795
// }

src/hyperlight_host/src/hypervisor/hypervisor_handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl HvHandlerExecVars {
129129
.thread_id
130130
.try_lock()
131131
.map_err(|_| new_error!("Failed to get_thread_id"))?)
132-
.ok_or_else(|| new_error!("thread_id not set"))
132+
.ok_or_else(|| new_error!("thread_id not set"))
133133
}
134134

135135
#[cfg(target_os = "windows")]
@@ -772,7 +772,7 @@ impl HypervisorHandler {
772772
0,
773773
0,
774774
)
775-
.map_err(|e| new_error!("Failed to cancel guest execution {:?}", e))?;
775+
.map_err(|e| new_error!("Failed to cancel guest execution {:?}", e))?;
776776
}
777777
}
778778
// if running in-process on windows, we currently have no way of cancelling the execution

src/hyperlight_host/src/hypervisor/kvm.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ use super::{
3535
CR4_OSFXSR, CR4_OSXMMEXCPT, CR4_PAE, EFER_LMA, EFER_LME, EFER_NX, EFER_SCE,
3636
};
3737
use crate::hypervisor::hypervisor_handler::HypervisorHandler;
38-
use crate::sandbox::sandbox_builder::{MemoryRegionFlags, SandboxMemorySections};
3938
use crate::mem::ptr::{GuestPtr, RawPtr};
39+
use crate::sandbox::sandbox_builder::{MemoryRegionFlags, SandboxMemorySections};
4040
#[cfg(gdb)]
4141
use crate::HyperlightError;
4242
use crate::{log_then_return, new_error, Result};
@@ -422,9 +422,9 @@ impl Hypervisor for KVMDriver {
422422
rsp: self.orig_rsp.absolute()?,
423423

424424
// function args
425-
rcx: hyperlight_peb_guest_memory_region_address.into(),
426-
rdx: hyperlight_peb_guest_memory_region_size.into(),
427-
r8: seed.into(),
425+
rcx: hyperlight_peb_guest_memory_region_address,
426+
rdx: hyperlight_peb_guest_memory_region_size,
427+
r8: seed,
428428
r9: max_guest_log_level,
429429

430430
..Default::default()

0 commit comments

Comments
 (0)