diff --git a/.github/workflows/dep_rust.yml b/.github/workflows/dep_rust.yml index 079373dbc..f31807903 100644 --- a/.github/workflows/dep_rust.yml +++ b/.github/workflows/dep_rust.yml @@ -74,6 +74,10 @@ jobs: # with only one driver enabled (driver mshv/kvm feature is ignored on windows) + seccomp + inprocess just test-rust ${{ matrix.config }} inprocess,seccomp,${{ matrix.hypervisor == 'mshv' && 'mshv' || 'kvm' }} + # make sure certain cargo features compile + cargo check -p hyperlight-host --features crashdump + cargo check -p hyperlight-host --features print_debug + # without any driver (shouldn't compile) just test-rust-feature-compilation-fail ${{ matrix.config }} diff --git a/docs/debugging-hyperlight.md b/docs/debugging-hyperlight.md index b933c775e..9ff3b8229 100644 --- a/docs/debugging-hyperlight.md +++ b/docs/debugging-hyperlight.md @@ -39,6 +39,6 @@ cargo test --package hyperlight-host --test integration_test --features print_de ## Dumping the memory configuration, virtual processor register state and memory contents on a crash or unexpected VM Exit -To dump the details of the memory configuration, the virtual processors register state and the contents of the VM memory set the feature `dump_on_crash` and run a debug build. This will result in a dump file being created in the temporary directory. The name and location of the dump file will be printed to the console and logged as an error message. +To dump the details of the memory configuration, the virtual processors register state and the contents of the VM memory set the feature `crashdump` and run a debug build. This will result in a dump file being created in the temporary directory. The name and location of the dump file will be printed to the console and logged as an error message. There are no tools at this time to analyze the dump file, but it can be useful for debugging. diff --git a/src/hyperlight_host/Cargo.toml b/src/hyperlight_host/Cargo.toml index f876fd294..f4c36f416 100644 --- a/src/hyperlight_host/Cargo.toml +++ b/src/hyperlight_host/Cargo.toml @@ -118,9 +118,7 @@ function_call_metrics = [] executable_heap = [] # This feature enables printing of debug information to stdout in debug builds print_debug = [] -# This feature enables dunping of the VMs details to a file when an unexpected or error exit occurs in a VM in debug mode -# the name of the file is output to stdout and logged. -dump_on_crash = ["dep:tempfile"] +crashdump = ["dep:tempfile"] # Dumps the VM state to a file on unexpected errors or crashes. The path of the file will be printed on stdout and logged. This feature can only be used in debug builds. kvm = ["dep:kvm-bindings", "dep:kvm-ioctls"] mshv = ["dep:mshv-bindings", "dep:mshv-ioctls"] inprocess = [] diff --git a/src/hyperlight_host/build.rs b/src/hyperlight_host/build.rs index f115c6e31..2aa321e79 100644 --- a/src/hyperlight_host/build.rs +++ b/src/hyperlight_host/build.rs @@ -94,6 +94,10 @@ fn main() -> Result<()> { // inprocess feature is aliased with debug_assertions to make it only available in debug-builds. // You should never use #[cfg(feature = "inprocess")] in the codebase. Use #[cfg(inprocess)] instead. inprocess: { all(feature = "inprocess", debug_assertions) }, + // crashdump feature is aliased with debug_assertions to make it only available in debug-builds. + crashdump: { all(feature = "crashdump", debug_assertions) }, + // print_debug feature is aliased with debug_assertions to make it only available in debug-builds. + print_debug: { all(feature = "print_debug", debug_assertions) }, } write_built_file()?; diff --git a/src/hyperlight_host/src/hypervisor/crashdump.rs b/src/hyperlight_host/src/hypervisor/crashdump.rs new file mode 100644 index 000000000..a70dc34c1 --- /dev/null +++ b/src/hyperlight_host/src/hypervisor/crashdump.rs @@ -0,0 +1,44 @@ +use std::io::Write; + +use tempfile::NamedTempFile; + +use super::Hypervisor; +use crate::{new_error, Result}; + +/// Dump registers + memory regions + raw memory to a tempfile +#[cfg(crashdump)] +pub(crate) fn crashdump_to_tempfile(hv: &dyn Hypervisor) -> Result<()> { + let mut temp_file = NamedTempFile::with_prefix("mem")?; + let hv_details = format!("{:#x?}", hv); + + // write hypervisor details such as registers, info about mapped memory regions, etc. + temp_file.write_all(hv_details.as_bytes())?; + temp_file.write_all(b"================ MEMORY DUMP =================\n")?; + + // write the raw memory dump for each memory region + for region in hv.get_memory_regions() { + if region.host_region.start == 0 || region.host_region.is_empty() { + continue; + } + // SAFETY: we got this memory region from the hypervisor so should never be invalid + let region_slice = unsafe { + std::slice::from_raw_parts( + region.host_region.start as *const u8, + region.host_region.len(), + ) + }; + temp_file.write_all(region_slice)?; + } + temp_file.flush()?; + + // persist the tempfile to disk + let persist_path = temp_file.path().with_extension("dmp"); + temp_file + .persist(&persist_path) + .map_err(|e| new_error!("Failed to persist crashdump file: {:?}", e))?; + + println!("Memory dumped to file: {:?}", persist_path); + log::error!("Memory dumped to file: {:?}", persist_path); + + Ok(()) +} diff --git a/src/hyperlight_host/src/hypervisor/hyperv_linux.rs b/src/hyperlight_host/src/hypervisor/hyperv_linux.rs index 4bbaef7b7..b8a18303e 100644 --- a/src/hyperlight_host/src/hypervisor/hyperv_linux.rs +++ b/src/hyperlight_host/src/hypervisor/hyperv_linux.rs @@ -37,7 +37,7 @@ use crate::hypervisor::hypervisor_handler::HypervisorHandler; use crate::hypervisor::HyperlightExit; use crate::mem::memory_region::{MemoryRegion, MemoryRegionFlags}; use crate::mem::ptr::{GuestPtr, RawPtr}; -use crate::{debug, log_then_return, new_error, Result}; +use crate::{log_then_return, new_error, Result}; /// Determine whether the HyperV for Linux hypervisor API is present /// and functional. @@ -287,7 +287,7 @@ impl Hypervisor for HypervLinuxDriver { let result = match &self.vcpu_fd.run(hv_message) { Ok(m) => match m.header.message_type { HALT_MESSAGE => { - debug!("mshv - Halt Details : {:#?}", &self); + crate::debug!("mshv - Halt Details : {:#?}", &self); HyperlightExit::Halt() } IO_PORT_INTERCEPT_MESSAGE => { @@ -296,7 +296,7 @@ impl Hypervisor for HypervLinuxDriver { let rip = io_message.header.rip; let rax = io_message.rax; let instruction_length = io_message.header.instruction_length() as u64; - debug!("mshv IO Details : \nPort : {}\n{:#?}", port_number, &self); + crate::debug!("mshv IO Details : \nPort : {}\n{:#?}", port_number, &self); HyperlightExit::IoOut( port_number, rax.to_le_bytes().to_vec(), @@ -307,24 +307,22 @@ impl Hypervisor for HypervLinuxDriver { UNMAPPED_GPA_MESSAGE => { let mimo_message = m.to_memory_info()?; let addr = mimo_message.guest_physical_address; - debug!( + crate::debug!( "mshv MMIO unmapped GPA -Details: Address: {} \n {:#?}", - addr, &self + addr, + &self ); - #[cfg(all(debug_assertions, feature = "dump_on_crash"))] - self.dump_on_crash(self.mem_regions.clone()); HyperlightExit::Mmio(addr) } INVALID_GPA_ACCESS_MESSAGE => { let mimo_message = m.to_memory_info()?; let gpa = mimo_message.guest_physical_address; let access_info = MemoryRegionFlags::try_from(mimo_message)?; - debug!( + crate::debug!( "mshv MMIO invalid GPA access -Details: Address: {} \n {:#?}", - gpa, &self + gpa, + &self ); - #[cfg(all(debug_assertions, feature = "dump_on_crash"))] - self.dump_on_crash(self.mem_regions.clone()); match self.get_memory_access_violation( gpa as usize, &self.mem_regions, @@ -335,9 +333,7 @@ impl Hypervisor for HypervLinuxDriver { } } other => { - debug!("mshv Other Exit: Exit: {:#?} \n {:#?}", other, &self); - #[cfg(all(debug_assertions, feature = "dump_on_crash"))] - self.dump_on_crash(self.mem_regions.clone()); + crate::debug!("mshv Other Exit: Exit: {:#?} \n {:#?}", other, &self); log_then_return!("unknown Hyper-V run message type {:?}", other); } }, @@ -346,9 +342,7 @@ impl Hypervisor for HypervLinuxDriver { libc::EINTR => HyperlightExit::Cancelled(), libc::EAGAIN => HyperlightExit::Retry(), _ => { - debug!("mshv Error - Details: Error: {} \n {:#?}", e, &self); - #[cfg(all(debug_assertions, feature = "dump_on_crash"))] - self.dump_on_crash(self.mem_regions.clone()); + crate::debug!("mshv Error - Details: Error: {} \n {:#?}", e, &self); log_then_return!("Error running VCPU {:?}", e); } }, @@ -360,6 +354,11 @@ impl Hypervisor for HypervLinuxDriver { fn as_mut_hypervisor(&mut self) -> &mut dyn Hypervisor { self as &mut dyn Hypervisor } + + #[cfg(crashdump)] + fn get_memory_regions(&self) -> &[MemoryRegion] { + &self.mem_regions + } } impl Drop for HypervLinuxDriver { diff --git a/src/hyperlight_host/src/hypervisor/hyperv_windows.rs b/src/hyperlight_host/src/hypervisor/hyperv_windows.rs index 80d16736c..5c5bbc604 100644 --- a/src/hyperlight_host/src/hypervisor/hyperv_windows.rs +++ b/src/hyperlight_host/src/hypervisor/hyperv_windows.rs @@ -19,7 +19,6 @@ use std::fmt; use std::fmt::{Debug, Formatter}; use std::string::String; -use cfg_if::cfg_if; use hyperlight_common::mem::PAGE_SIZE_USIZE; use tracing::{instrument, Span}; use windows::Win32::Foundation::HANDLE; @@ -463,19 +462,10 @@ impl Hypervisor for HypervWindowsDriver { // see https://learn.microsoft.com/en-us/virtualization/api/hypervisor-platform/funcs/whvexitcontextdatatypes) let instruction_length = exit_context.VpContext._bitfield & 0xF; unsafe { - cfg_if! { - if #[cfg(all(feature = "print_debug", debug_assertions))] { - println!( - "HyperV IO Details :\n Port: {:#x} \n {:#?}", - exit_context.Anonymous.IoPortAccess.PortNumber, &self - ); - } else { - debug!( - "HyperV IO Details :\n Port: {:#x} \n {:#?}", - exit_context.Anonymous.IoPortAccess.PortNumber, &self - ); - } - } + debug!( + "HyperV IO Details :\n Port: {:#x} \n {:#?}", + exit_context.Anonymous.IoPortAccess.PortNumber, &self + ); HyperlightExit::IoOut( exit_context.Anonymous.IoPortAccess.PortNumber, exit_context @@ -508,18 +498,6 @@ impl Hypervisor for HypervWindowsDriver { "HyperV Memory Access Details :\n GPA: {:#?}\n Access Info :{:#?}\n {:#?} ", gpa, access_info, &self ); - #[cfg(all(debug_assertions, feature = "dump_on_crash"))] - { - if let Err(e) = unsafe { - self.write_dump_file( - self.mem_regions.clone(), - self.source_address.add(PAGE_SIZE_USIZE) as *const u8, - self.size, - ) - } { - println!("Error dumping memory: {}", e); - } - } match self.get_memory_access_violation(gpa as usize, &self.mem_regions, access_info) { @@ -539,18 +517,6 @@ impl Hypervisor for HypervWindowsDriver { "HyperV Unexpected Exit Details :#nReason {:#?}\n {:#?}", exit_context.ExitReason, &self ); - #[cfg(all(debug_assertions, feature = "dump_on_crash"))] - { - if let Err(e) = unsafe { - self.write_dump_file( - self.mem_regions.clone(), - self.source_address.add(PAGE_SIZE_USIZE) as *const u8, - self.size, - ) - } { - println!("Error dumping memory: {}", e); - } - } match self.get_exit_details(exit_context.ExitReason) { Ok(error) => HyperlightExit::Unknown(error), Err(e) => HyperlightExit::Unknown(format!("Error getting exit details: {}", e)), @@ -569,6 +535,11 @@ impl Hypervisor for HypervWindowsDriver { fn as_mut_hypervisor(&mut self) -> &mut dyn Hypervisor { self as &mut dyn Hypervisor } + + #[cfg(crashdump)] + fn get_memory_regions(&self) -> &[MemoryRegion] { + &self.mem_regions + } } #[cfg(test)] diff --git a/src/hyperlight_host/src/hypervisor/inprocess.rs b/src/hyperlight_host/src/hypervisor/inprocess.rs index a8ff862e1..f7076a5b4 100644 --- a/src/hyperlight_host/src/hypervisor/inprocess.rs +++ b/src/hyperlight_host/src/hypervisor/inprocess.rs @@ -18,6 +18,8 @@ use std::fmt::Debug; use std::os::raw::c_void; use super::{HyperlightExit, Hypervisor}; +#[cfg(crashdump)] +use crate::mem::memory_region::MemoryRegion; use crate::sandbox::leaked_outb::LeakedOutBWrapper; use crate::Result; @@ -123,4 +125,9 @@ impl<'a> Hypervisor for InprocessDriver<'a> { fn get_partition_handle(&self) -> windows::Win32::System::Hypervisor::WHV_PARTITION_HANDLE { unimplemented!("get_partition_handle should not be needed since we are in in-process mode") } + + #[cfg(crashdump)] + fn get_memory_regions(&self) -> &[MemoryRegion] { + unimplemented!("get_memory_regions is not supported since we are in in-process mode") + } } diff --git a/src/hyperlight_host/src/hypervisor/kvm.rs b/src/hyperlight_host/src/hypervisor/kvm.rs index 5caf82415..991e1e24b 100644 --- a/src/hyperlight_host/src/hypervisor/kvm.rs +++ b/src/hyperlight_host/src/hypervisor/kvm.rs @@ -17,7 +17,6 @@ limitations under the License. use std::convert::TryFrom; use std::fmt::Debug; -use cfg_if::cfg_if; use kvm_bindings::{kvm_fpu, kvm_regs, kvm_userspace_memory_region, KVM_MEM_READONLY}; use kvm_ioctls::Cap::UserMemory; use kvm_ioctls::{Kvm, VcpuExit, VcpuFd, VmFd}; @@ -32,7 +31,7 @@ use super::{ use crate::hypervisor::hypervisor_handler::HypervisorHandler; use crate::mem::memory_region::{MemoryRegion, MemoryRegionFlags}; use crate::mem::ptr::{GuestPtr, RawPtr}; -use crate::{debug, log_then_return, new_error, Result}; +use crate::{log_then_return, new_error, Result}; /// Return `true` if the KVM API is available, version 12, and has UserMemory capability, or `false` otherwise #[instrument(skip_all, parent = Span::current(), level = "Trace")] @@ -272,22 +271,20 @@ impl Hypervisor for KVMDriver { let exit_reason = self.vcpu_fd.run(); let result = match exit_reason { Ok(VcpuExit::Hlt) => { - debug!("KVM - Halt Details : {:#?}", &self); + crate::debug!("KVM - Halt Details : {:#?}", &self); HyperlightExit::Halt() } Ok(VcpuExit::IoOut(port, data)) => { - // because vcpufd.run() mutably borrows self we cannot pass self to debug! macro here - debug!("KVM IO Details : \nPort : {}\nData : {:?}", port, data); + // because vcpufd.run() mutably borrows self we cannot pass self to crate::debug! macro here + crate::debug!("KVM IO Details : \nPort : {}\nData : {:?}", port, data); // KVM does not need to set RIP or instruction length so these are set to 0 HyperlightExit::IoOut(port, data.to_vec(), 0, 0) } Ok(VcpuExit::MmioRead(addr, _)) => { - debug!("KVM MMIO Read -Details: Address: {} \n {:#?}", addr, &self); - #[cfg(all(debug_assertions, feature = "dump_on_crash"))] - self.dump_on_crash(self.mem_regions.clone()); - let gpa = addr as usize; + crate::debug!("KVM MMIO Read -Details: Address: {} \n {:#?}", addr, &self); + match self.get_memory_access_violation( - gpa, + addr as usize, &self.mem_regions, MemoryRegionFlags::READ, ) { @@ -296,12 +293,10 @@ impl Hypervisor for KVMDriver { } } Ok(VcpuExit::MmioWrite(addr, _)) => { - debug!("KVM MMIO Write -Details: Address: {} \n {:#?}", addr, &self); - #[cfg(all(debug_assertions, feature = "dump_on_crash"))] - self.dump_on_crash(self.mem_regions.clone()); - let gpa = addr as usize; + crate::debug!("KVM MMIO Write -Details: Address: {} \n {:#?}", addr, &self); + match self.get_memory_access_violation( - gpa, + addr as usize, &self.mem_regions, MemoryRegionFlags::WRITE, ) { @@ -314,26 +309,13 @@ impl Hypervisor for KVMDriver { libc::EINTR => HyperlightExit::Cancelled(), libc::EAGAIN => HyperlightExit::Retry(), _ => { - debug!("KVM Error -Details: Address: {} \n {:#?}", e, &self); - #[cfg(all(debug_assertions, feature = "dump_on_crash"))] - self.dump_on_crash(self.mem_regions.clone()); + crate::debug!("KVM Error -Details: Address: {} \n {:#?}", e, &self); log_then_return!("Error running VCPU {:?}", e); } }, Ok(other) => { - cfg_if! { - if #[cfg(all(feature = "print_debug", debug_assertions))] { - let _ = other; - debug!("KVM Other Exit: \n {:#?}", &self); - HyperlightExit::Unknown("Unexpected KVM Exit".to_string()) - } else if #[cfg(all(feature = "dump_on_crash", debug_assertions))] { - self.dump_on_crash(self.mem_regions.clone()); - HyperlightExit::Unknown(format!("Unexpected KVM Exit {:?}", other)) - } else{ - debug!("KVM Other Exit {:?}", other); - HyperlightExit::Unknown(format!("Unexpected KVM Exit {:?}", other)) - } - } + crate::debug!("KVM Other Exit {:?}", other); + HyperlightExit::Unknown(format!("Unexpected KVM Exit {:?}", other)) } }; Ok(result) @@ -343,6 +325,11 @@ impl Hypervisor for KVMDriver { fn as_mut_hypervisor(&mut self) -> &mut dyn Hypervisor { self as &mut dyn Hypervisor } + + #[cfg(crashdump)] + fn get_memory_regions(&self) -> &[MemoryRegion] { + &self.mem_regions + } } #[cfg(test)] diff --git a/src/hyperlight_host/src/hypervisor/mod.rs b/src/hyperlight_host/src/hypervisor/mod.rs index 4f13ff2b8..c34d7eb1f 100644 --- a/src/hyperlight_host/src/hypervisor/mod.rs +++ b/src/hyperlight_host/src/hypervisor/mod.rs @@ -55,6 +55,9 @@ pub(crate) mod windows_hypervisor_platform; #[cfg(target_os = "windows")] pub(crate) mod wrappers; +#[cfg(crashdump)] +pub(crate) mod crashdump; + use std::fmt::Debug; use std::sync::{Arc, Mutex}; @@ -184,70 +187,8 @@ pub(crate) trait Hypervisor: Debug + Sync + Send { #[cfg(target_os = "windows")] fn get_partition_handle(&self) -> windows::Win32::System::Hypervisor::WHV_PARTITION_HANDLE; - /// Dump memory to a file on crash - #[cfg(all(debug_assertions, feature = "dump_on_crash", target_os = "linux"))] - fn dump_on_crash(&self, mem_regions: Vec) { - let memory_size = mem_regions - .iter() - .map(|region| region.guest_region.end - region.guest_region.start) - .sum(); - if let Err(e) = unsafe { - self.write_dump_file( - mem_regions.clone(), - mem_regions[0].host_region.start as *const u8, - memory_size, - ) - } { - println!("Error dumping memory: {}", e); - } - } - - /// A function that takes an address and a size and writes the memory at that address to a file in the temp/tmp directory - /// # Safety - /// This function is unsafe because it is writing memory to a file, make sure that the address is valid and that the size is correct - /// This function is only available when the `dump_on_crash` feature is enabled and running in debug mode - #[cfg(all(feature = "dump_on_crash", debug_assertions))] - unsafe fn write_dump_file( - &self, - regions: Vec, - address: *const u8, - size: usize, - ) -> Result<()> { - use std::io::Write; - - use tempfile::NamedTempFile; - - if address.is_null() || size == 0 { - return Err(new_error!("Invalid address or size")); - } - - let hv_details = format!("{:#?}", self); - let regions_details = format!("{:#?}", regions); - - // Create a temporary file - let mut file = NamedTempFile::with_prefix("mem")?; - let temp_path = file.path().to_path_buf(); - - file.write_all(hv_details.as_bytes())?; - file.write_all(b"\n")?; - file.write_all(regions_details.as_bytes())?; - file.write_all(b"\n")?; - - // SAFETY: Ensure the address and size are valid and accessible - unsafe { - let slice = std::slice::from_raw_parts(address, size); - file.write_all(slice)?; - file.flush()?; - } - let persist_path = temp_path.with_extension("dmp"); - file.persist(&persist_path) - .map_err(|e| new_error!("Failed to persist file: {:?}", e))?; - - print!("Memory dumped to file: {:?}", persist_path); - log::error!("Memory dumped to file: {:?}", persist_path); - - Ok(()) - } + #[cfg(crashdump)] + fn get_memory_regions(&self) -> &[MemoryRegion]; } /// A virtual CPU that can be run until an exit occurs @@ -263,22 +204,29 @@ impl VirtualCPU { mem_access_fn: Arc>, ) -> Result<()> { loop { - match hv.run()? { - HyperlightExit::Halt() => { + match hv.run() { + Ok(HyperlightExit::Halt()) => { break; } - HyperlightExit::IoOut(port, data, rip, instruction_length) => { + Ok(HyperlightExit::IoOut(port, data, rip, instruction_length)) => { hv.handle_io(port, data, rip, instruction_length, outb_handle_fn.clone())? } - HyperlightExit::Mmio(addr) => { + Ok(HyperlightExit::Mmio(addr)) => { + #[cfg(crashdump)] + crashdump::crashdump_to_tempfile(hv)?; + mem_access_fn .clone() .try_lock() .map_err(|e| new_error!("Error locking at {}:{}: {}", file!(), line!(), e))? .call()?; + log_then_return!("MMIO access address {:#x}", addr); } - HyperlightExit::AccessViolation(addr, tried, region_permission) => { + Ok(HyperlightExit::AccessViolation(addr, tried, region_permission)) => { + #[cfg(crashdump)] + crashdump::crashdump_to_tempfile(hv)?; + if region_permission.intersects(MemoryRegionFlags::STACK_GUARD) { return Err(HyperlightError::StackOverflow()); } @@ -288,7 +236,7 @@ impl VirtualCPU { region_permission )); } - HyperlightExit::Cancelled() => { + Ok(HyperlightExit::Cancelled()) => { // Shutdown is returned when the host has cancelled execution // After termination, the main thread will re-initialize the VM if let Some(hvh) = hv_handler { @@ -301,10 +249,19 @@ impl VirtualCPU { int_counter_inc!(&NumberOfCancelledGuestExecutions); log_then_return!(ExecutionCanceledByHost()); } - HyperlightExit::Unknown(reason) => { + Ok(HyperlightExit::Unknown(reason)) => { + #[cfg(crashdump)] + crashdump::crashdump_to_tempfile(hv)?; + log_then_return!("Unexpected VM Exit {:?}", reason); } - HyperlightExit::Retry() => continue, + Ok(HyperlightExit::Retry()) => continue, + Err(e) => { + #[cfg(crashdump)] + crashdump::crashdump_to_tempfile(hv)?; + + return Err(e); + } } } diff --git a/src/hyperlight_host/src/lib.rs b/src/hyperlight_host/src/lib.rs index 7170552d7..2dac703fe 100644 --- a/src/hyperlight_host/src/lib.rs +++ b/src/hyperlight_host/src/lib.rs @@ -143,19 +143,14 @@ macro_rules! log_then_return { }; } +// same as log::debug!, but will additionally print to stdout if the print_debug feature is enabled #[macro_export] macro_rules! debug { - ($($arg:tt)+) => { - // If the print_debug feature is enabled, print the debug message to the console - #[cfg(all(feature = "print_debug", debug_assertions))] - { - (println!($($arg)+)) - } - - // Then log/trace the debug message - (log::debug!($($arg)+)) + #[cfg(print_debug)] + println!($($arg)+); + log::debug!($($arg)+); } } diff --git a/src/hyperlight_host/src/mem/pe/pe_info.rs b/src/hyperlight_host/src/mem/pe/pe_info.rs index eb4b792c1..97a99bfaa 100644 --- a/src/hyperlight_host/src/mem/pe/pe_info.rs +++ b/src/hyperlight_host/src/mem/pe/pe_info.rs @@ -23,7 +23,7 @@ use goblin::pe::PE; use tracing::{instrument, Span}; use crate::mem::pe::base_relocations; -use crate::{debug, log_then_return, Result}; +use crate::{log_then_return, Result}; const IMAGE_REL_BASED_DIR64: u8 = 10; const IMAGE_REL_BASED_ABSOLUTE: u8 = 0; @@ -106,9 +106,11 @@ impl PEInfo { let name = section.name().unwrap_or("Unknown"); let virtual_size = section.virtual_size; let raw_size = section.size_of_raw_data; - debug!( + crate::debug!( "Section: {}, Virtual Size: {}, On-Disk Size: {}", - name, virtual_size, raw_size + name, + virtual_size, + raw_size ); if virtual_size > raw_size { @@ -122,16 +124,16 @@ impl PEInfo { data_section_raw_pointer = section.pointer_to_raw_data; data_section_additional_bytes = virtual_size - raw_size; - debug!( + crate::debug!( "Resizing the data section - Additional bytes required: {}", data_section_additional_bytes ); - debug!( + crate::debug!( "Resizing the data section - Existing PE File Size: {} New PE File Size: {}", pe_bytes.len(), pe_bytes.len() + data_section_additional_bytes as usize, ); - debug!( + crate::debug!( "Resizing the data section - Data Section Raw Pointer: {}", data_section_raw_pointer ); @@ -140,19 +142,19 @@ impl PEInfo { end_of_data_index = (section.pointer_to_raw_data + section.size_of_raw_data) as usize; - debug!("End of data index: {}", end_of_data_index); + crate::debug!("End of data index: {}", end_of_data_index); // the remainder of the data is the rest of the file after the .data section if any let next_section = pe.sections.get(i + 1); if let Some(next_section) = next_section { - debug!( + crate::debug!( "Start of section after data index: {}", next_section.pointer_to_raw_data ); } else { - debug!("No more sections after the .data section"); + crate::debug!("No more sections after the .data section"); } } else { log_then_return!( diff --git a/src/hyperlight_host/src/sandbox/uninitialized.rs b/src/hyperlight_host/src/sandbox/uninitialized.rs index eaa573de6..6ae2e1a0c 100644 --- a/src/hyperlight_host/src/sandbox/uninitialized.rs +++ b/src/hyperlight_host/src/sandbox/uninitialized.rs @@ -35,7 +35,7 @@ use crate::sandbox::SandboxConfiguration; use crate::sandbox_state::sandbox::EvolvableSandbox; use crate::sandbox_state::transition::Noop; use crate::{ - debug, log_build_details, log_then_return, new_error, MultiUseSandbox, Result, SingleUseSandbox, + log_build_details, log_then_return, new_error, MultiUseSandbox, Result, SingleUseSandbox, }; /// A preliminary `Sandbox`, not yet ready to execute guest code. @@ -258,7 +258,7 @@ impl UninitializedSandbox { } } - debug!("Sandbox created: {:#?}", sandbox); + crate::debug!("Sandbox created: {:#?}", sandbox); Ok(sandbox) }