Skip to content

Commit ed6a42f

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

File tree

15 files changed

+58
-39
lines changed

15 files changed

+58
-39
lines changed

src/hyperlight_common/src/hyperlight_peb.rs

+2-2
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

+3
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

+3-2
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

+8
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

+1-1
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

+1-1
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

+12-8
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

+13-13
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};
@@ -480,9 +480,9 @@ impl Hypervisor for HypervLinuxDriver {
480480
rflags: 2, //bit 1 of rlags is required to be set
481481

482482
// function args
483-
rcx: hyperlight_peb_guest_memory_region_address.into(),
484-
rdx: hyperlight_peb_guest_memory_region_size.into(),
485-
r8: seed.into(),
483+
rcx: hyperlight_peb_guest_memory_region_address,
484+
rdx: hyperlight_peb_guest_memory_region_size,
485+
r8: seed,
486486
r9: max_guest_log_level,
487487

488488
..Default::default()
@@ -788,13 +788,13 @@ impl Hypervisor for HypervLinuxDriver {
788788
// crate::mem::memory_region::MemoryRegionType::Code,
789789
// );
790790
// super::HypervLinuxDriver::new(
791-
regions.build(),
792-
entrypoint_ptr,
793-
rsp_ptr,
794-
pml4_ptr,
795-
#[cfg(gdb)]
796-
None,
797-
)
798-
.unwrap();
791+
// regions.build(),
792+
// entrypoint_ptr,
793+
// rsp_ptr,
794+
// pml4_ptr,
795+
// #[cfg(gdb)]
796+
// None,
797+
// )
798+
// .unwrap();
799799
// }
800800
// }

src/hyperlight_host/src/hypervisor/hypervisor_handler.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl HvHandlerExecVars {
133133
.thread_id
134134
.try_lock()
135135
.map_err(|_| new_error!("Failed to get_thread_id"))?)
136-
.ok_or_else(|| new_error!("thread_id not set"))
136+
.ok_or_else(|| new_error!("thread_id not set"))
137137
}
138138

139139
#[cfg(target_os = "windows")]
@@ -792,7 +792,7 @@ impl HypervisorHandler {
792792
0,
793793
0,
794794
)
795-
.map_err(|e| new_error!("Failed to cancel guest execution {:?}", e))?;
795+
.map_err(|e| new_error!("Failed to cancel guest execution {:?}", e))?;
796796
}
797797
}
798798
// if running in-process on windows, we currently have no way of cancelling the execution

src/hyperlight_host/src/hypervisor/kvm.rs

+4-4
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()

src/hyperlight_host/src/mem/mgr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ use super::ptr::RawPtr;
3535
use super::ptr_offset::Offset;
3636
use super::shared_mem::{ExclusiveSharedMemory, GuestSharedMemory, HostSharedMemory, SharedMemory};
3737
use super::shared_mem_snapshot::SharedMemorySnapshot;
38+
use crate::error::HyperlightHostError;
3839
use crate::sandbox::sandbox_builder::{
3940
MemoryRegionFlags, SandboxMemorySections, BASE_ADDRESS, PDPT_OFFSET, PD_OFFSET, PT_OFFSET,
4041
};
4142
use crate::HyperlightError::{
4243
ExceptionDataLengthIncorrect, ExceptionMessageTooBig, JsonConversionFailure, NoMemorySnapshot,
4344
UTF8SliceConversionFailure,
4445
};
45-
use crate::error::HyperlightHostError;
4646
use crate::{log_then_return, new_error, HyperlightError, Result};
4747

4848
/// Paging Flags

src/hyperlight_host/src/sandbox/initialized_multi_use.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ use hyperlight_common::flatbuffer_wrappers::function_types::{
1919
};
2020
use tracing::{instrument, Span};
2121

22-
use crate::mem::mgr::SandboxMemoryManager;
2322
use crate::func::call_ctx::MultiUseGuestCallContext;
2423
use crate::func::guest_dispatch::call_function_on_guest;
2524
use crate::hypervisor::hypervisor_handler::HypervisorHandler;
25+
use crate::mem::mgr::SandboxMemoryManager;
2626
use crate::mem::shared_mem::HostSharedMemory;
2727
use crate::sandbox_state::sandbox::{DevolvableSandbox, EvolvableSandbox, Sandbox};
2828
use crate::sandbox_state::transition::{MultiUseContextCallback, Noop};

src/hyperlight_host/src/sandbox/mem_access.rs

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ use crate::hypervisor::handlers::{DbgMemAccessHandlerCaller, DbgMemAccessHandler
2323
use crate::hypervisor::handlers::{
2424
MemAccessHandler, MemAccessHandlerFunction, MemAccessHandlerWrapper,
2525
};
26+
#[cfg(gdb)]
27+
use crate::mem::mgr::SandboxMemoryManager;
2628

2729
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
2830
pub(crate) fn mem_access_handler_wrapper() -> MemAccessHandlerWrapper {

src/hyperlight_host/src/sandbox/sandbox_builder.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,9 @@ impl SandboxBuilder {
370370
/// Set the sandbox run mode. Options:
371371
/// - SandboxRunOptions::RunInHypervisor: Run the sandbox in a hypervisor.
372372
/// - SandboxRunOptions::RunInProcess(false): Run the sandbox in process (i.e., without a
373-
/// hypervisor), but also without using the Windows LoadLibrary to load the guest binary.
373+
/// hypervisor), but also without using the Windows LoadLibrary to load the guest binary.
374374
/// - SandboxRunOptions::RunInProcess(true): Run the sandbox in process (i.e., without a
375-
/// hypervisor), and use the Windows LoadLibrary to load the guest binary.
375+
/// hypervisor), and use the Windows LoadLibrary to load the guest binary.
376376
pub fn set_sandbox_run_options(
377377
mut self,
378378
sandbox_run_options: SandboxRunOptions,
@@ -495,7 +495,7 @@ impl SandboxBuilder {
495495
/// - +--------------------------+ 0x0
496496
///
497497
/// - Note 1: The guest stack size can be set manually via the `stack_size_override` parameter. If
498-
/// not provided, the stack size is set to the default stack reserve size of the guest binary.
498+
/// not provided, the stack size is set to the default stack reserve size of the guest binary.
499499
fn set_memory_layout(mut self) -> Result<Self> {
500500
// Name of guard page regions
501501
const DEFAULT_TMP_STACK_GUARD_PAGE_NAME: &str = "tmp stack guard page";

src/hyperlight_host/src/sandbox/uninitialized_evolve.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ where
6565
Duration::from_millis(u_sbox.config.get_max_initialization_time() as u64),
6666
Duration::from_millis(u_sbox.config.get_max_execution_time() as u64),
6767
Duration::from_millis(u_sbox.config.get_max_wait_for_cancellation() as u64),
68-
u_sbox.max_guest_log_level,#[cfg(gdb)]
68+
u_sbox.max_guest_log_level,
69+
#[cfg(gdb)]
6970
u_sbox.debug_info,
7071
)?;
7172

0 commit comments

Comments
 (0)