From 58fd45ca5a4d42a93d61875462e96b10f2765770 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 27 Aug 2025 09:58:30 +0000 Subject: [PATCH] Remove DbgMemAccessHandlerCaller trait and DbgMemAccessHandlerWrapper Co-authored-by: simongdavies <1397489+simongdavies@users.noreply.github.com> Signed-off-by: Simon Davies --- src/hyperlight_host/src/hypervisor/gdb/mod.rs | 19 +++-- .../src/hypervisor/handlers.rs | 39 ---------- .../src/hypervisor/hyperv_linux.rs | 24 +++--- .../src/hypervisor/hyperv_windows.rs | 22 +++--- src/hyperlight_host/src/hypervisor/kvm.rs | 22 +++--- src/hyperlight_host/src/hypervisor/mod.rs | 24 +++--- .../src/sandbox/initialized_multi_use.rs | 9 +-- src/hyperlight_host/src/sandbox/mem_access.rs | 78 ------------------- src/hyperlight_host/src/sandbox/mod.rs | 3 - .../src/sandbox/uninitialized_evolve.rs | 6 +- 10 files changed, 55 insertions(+), 191 deletions(-) delete mode 100644 src/hyperlight_host/src/hypervisor/handlers.rs delete mode 100644 src/hyperlight_host/src/sandbox/mem_access.rs diff --git a/src/hyperlight_host/src/hypervisor/gdb/mod.rs b/src/hyperlight_host/src/hypervisor/gdb/mod.rs index 3cc8ecd7c..118246d3c 100644 --- a/src/hyperlight_host/src/hypervisor/gdb/mod.rs +++ b/src/hyperlight_host/src/hypervisor/gdb/mod.rs @@ -46,8 +46,9 @@ use thiserror::Error; use x86_64_target::HyperlightSandboxTarget; use super::InterruptHandle; -use crate::hypervisor::handlers::DbgMemAccessHandlerCaller; use crate::mem::layout::SandboxMemoryLayout; +use crate::mem::shared_mem::HostSharedMemory; +use crate::sandbox::mem_mgr::MemMgrWrapper; use crate::{HyperlightError, new_error}; #[derive(Debug, Error)] @@ -209,7 +210,7 @@ pub(super) trait GuestDebug { &mut self, vcpu_fd: &Self::Vcpu, addr: u64, - dbg_mem_access_fn: Arc>, + dbg_mem_access_fn: Arc>>, ) -> crate::Result<()> { let addr = self.translate_gva(vcpu_fd, addr)?; @@ -234,7 +235,7 @@ pub(super) trait GuestDebug { vcpu_fd: &Self::Vcpu, mut gva: u64, mut data: &mut [u8], - dbg_mem_access_fn: Arc>, + dbg_mem_access_fn: Arc>>, ) -> crate::Result<()> { let data_len = data.len(); log::debug!("Read addr: {:X} len: {:X}", gva, data_len); @@ -258,7 +259,9 @@ pub(super) trait GuestDebug { dbg_mem_access_fn .try_lock() .map_err(|e| new_error!("Error locking at {}:{}: {}", file!(), line!(), e))? - .read(offset, &mut data[..read_len])?; + .unwrap_mgr_mut() + .get_shared_mem_mut() + .copy_to_slice(&mut data[..read_len], offset)?; data = &mut data[read_len..]; gva += read_len as u64; @@ -282,7 +285,7 @@ pub(super) trait GuestDebug { &mut self, vcpu_fd: &Self::Vcpu, addr: u64, - dbg_mem_access_fn: Arc>, + dbg_mem_access_fn: Arc>>, ) -> crate::Result<()> { let addr = self.translate_gva(vcpu_fd, addr)?; @@ -306,7 +309,7 @@ pub(super) trait GuestDebug { vcpu_fd: &Self::Vcpu, mut gva: u64, mut data: &[u8], - dbg_mem_access_fn: Arc>, + dbg_mem_access_fn: Arc>>, ) -> crate::Result<()> { let data_len = data.len(); log::debug!("Write addr: {:X} len: {:X}", gva, data_len); @@ -330,7 +333,9 @@ pub(super) trait GuestDebug { dbg_mem_access_fn .try_lock() .map_err(|e| new_error!("Error locking at {}:{}: {}", file!(), line!(), e))? - .write(offset, data)?; + .unwrap_mgr_mut() + .get_shared_mem_mut() + .copy_from_slice(&data[..write_len], offset)?; data = &data[write_len..]; gva += write_len as u64; diff --git a/src/hyperlight_host/src/hypervisor/handlers.rs b/src/hyperlight_host/src/hypervisor/handlers.rs deleted file mode 100644 index 842b44a37..000000000 --- a/src/hyperlight_host/src/hypervisor/handlers.rs +++ /dev/null @@ -1,39 +0,0 @@ -/* -Copyright 2025 The Hyperlight Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -use std::sync::{Arc, Mutex}; - -use crate::Result; - -/// The trait representing custom logic to handle the case when -/// a Hypervisor's virtual CPU (vCPU) informs Hyperlight a debug memory access -/// has been requested. -pub trait DbgMemAccessHandlerCaller: Send { - /// Function that gets called when a read is requested. - fn read(&mut self, addr: usize, data: &mut [u8]) -> Result<()>; - - /// Function that gets called when a write is requested. - fn write(&mut self, addr: usize, data: &[u8]) -> Result<()>; - - /// Function that gets called for a request to get guest code offset. - fn get_code_offset(&mut self) -> Result; -} - -/// A convenient type representing an implementer of `DbgMemAccessHandlerCaller` -/// -/// Note: This needs to be wrapped in a Mutex to be able to grab a mutable -/// reference to the underlying data -pub type DbgMemAccessHandlerWrapper = Arc>; diff --git a/src/hyperlight_host/src/hypervisor/hyperv_linux.rs b/src/hyperlight_host/src/hypervisor/hyperv_linux.rs index cc7528610..1907d8e0b 100644 --- a/src/hyperlight_host/src/hypervisor/hyperv_linux.rs +++ b/src/hyperlight_host/src/hypervisor/hyperv_linux.rs @@ -65,8 +65,6 @@ use super::fpu::{FP_CONTROL_WORD_DEFAULT, FP_TAG_WORD_DEFAULT, MXCSR_DEFAULT}; use super::gdb::{ DebugCommChannel, DebugMsg, DebugResponse, GuestDebug, MshvDebug, VcpuStopReason, }; -#[cfg(gdb)] -use super::handlers::DbgMemAccessHandlerWrapper; #[cfg(feature = "init-paging")] use super::{ CR0_AM, CR0_ET, CR0_MP, CR0_NE, CR0_PE, CR0_PG, CR0_WP, CR4_OSFXSR, CR4_OSXMMEXCPT, CR4_PAE, @@ -96,7 +94,8 @@ mod debug { use super::mshv_bindings::hv_x64_exception_intercept_message; use super::{HypervLinuxDriver, *}; use crate::hypervisor::gdb::{DebugMsg, DebugResponse, VcpuStopReason, X86_64Regs}; - use crate::hypervisor::handlers::DbgMemAccessHandlerCaller; + use crate::mem::shared_mem::HostSharedMemory; + use crate::sandbox::mem_mgr::MemMgrWrapper; use crate::{Result, new_error}; impl HypervLinuxDriver { @@ -127,7 +126,7 @@ mod debug { pub(crate) fn process_dbg_request( &mut self, req: DebugMsg, - dbg_mem_access_fn: Arc>, + dbg_mem_access_fn: Arc>>, ) -> Result { if let Some(debug) = self.debug.as_mut() { match req { @@ -175,12 +174,9 @@ mod debug { .map_err(|e| { new_error!("Error locking at {}:{}: {}", file!(), line!(), e) })? - .get_code_offset() - .map_err(|e| { - log::error!("Failed to get code offset: {:?}", e); - - e - })?; + .unwrap_mgr() + .layout + .get_guest_code_address(); Ok(DebugResponse::GetCodeSectionOffset(offset as u64)) } @@ -591,7 +587,7 @@ impl Hypervisor for HypervLinuxDriver { mem_mgr: MemMgrWrapper, host_funcs: Arc>, max_guest_log_level: Option, - #[cfg(gdb)] dbg_mem_access_fn: DbgMemAccessHandlerWrapper, + #[cfg(gdb)] dbg_mem_access_fn: Arc>>, ) -> Result<()> { self.mem_mgr = Some(mem_mgr); self.host_funcs = Some(host_funcs); @@ -663,7 +659,7 @@ impl Hypervisor for HypervLinuxDriver { fn dispatch_call_from_host( &mut self, dispatch_func_addr: RawPtr, - #[cfg(gdb)] dbg_mem_access_fn: DbgMemAccessHandlerWrapper, + #[cfg(gdb)] dbg_mem_access_fn: Arc>>, ) -> Result<()> { // Reset general purpose registers, then set RIP and RSP let regs = StandardRegisters { @@ -1025,9 +1021,7 @@ impl Hypervisor for HypervLinuxDriver { #[cfg(gdb)] fn handle_debug( &mut self, - dbg_mem_access_fn: std::sync::Arc< - std::sync::Mutex, - >, + dbg_mem_access_fn: Arc>>, stop_reason: VcpuStopReason, ) -> Result<()> { if self.debug.is_none() { diff --git a/src/hyperlight_host/src/hypervisor/hyperv_windows.rs b/src/hyperlight_host/src/hypervisor/hyperv_windows.rs index 0fc701a13..f8b4727d1 100644 --- a/src/hyperlight_host/src/hypervisor/hyperv_windows.rs +++ b/src/hyperlight_host/src/hypervisor/hyperv_windows.rs @@ -38,9 +38,7 @@ use { super::gdb::{ DebugCommChannel, DebugMsg, DebugResponse, GuestDebug, HypervDebug, VcpuStopReason, }, - super::handlers::DbgMemAccessHandlerWrapper, crate::HyperlightError, - crate::hypervisor::handlers::DbgMemAccessHandlerCaller, }; #[cfg(feature = "trace_guest")] @@ -80,7 +78,8 @@ mod debug { use super::{HypervWindowsDriver, *}; use crate::Result; use crate::hypervisor::gdb::{DebugMsg, DebugResponse, VcpuStopReason, X86_64Regs}; - use crate::hypervisor::handlers::DbgMemAccessHandlerCaller; + use crate::mem::shared_mem::HostSharedMemory; + use crate::sandbox::mem_mgr::MemMgrWrapper; impl HypervWindowsDriver { /// Resets the debug information to disable debugging @@ -110,7 +109,7 @@ mod debug { pub(crate) fn process_dbg_request( &mut self, req: DebugMsg, - dbg_mem_access_fn: Arc>, + dbg_mem_access_fn: Arc>>, ) -> Result { if let Some(debug) = self.debug.as_mut() { match req { @@ -158,12 +157,9 @@ mod debug { .map_err(|e| { new_error!("Error locking at {}:{}: {}", file!(), line!(), e) })? - .get_code_offset() - .map_err(|e| { - log::error!("Failed to get code offset: {:?}", e); - - e - })?; + .unwrap_mgr() + .layout + .get_guest_code_address(); Ok(DebugResponse::GetCodeSectionOffset(offset as u64)) } @@ -606,7 +602,7 @@ impl Hypervisor for HypervWindowsDriver { mem_mgr: MemMgrWrapper, host_funcs: Arc>, max_guest_log_level: Option, - #[cfg(gdb)] dbg_mem_access_hdl: DbgMemAccessHandlerWrapper, + #[cfg(gdb)] dbg_mem_access_hdl: Arc>>, ) -> Result<()> { self.mem_mgr = Some(mem_mgr); self.host_funcs = Some(host_funcs); @@ -656,7 +652,7 @@ impl Hypervisor for HypervWindowsDriver { fn dispatch_call_from_host( &mut self, dispatch_func_addr: RawPtr, - #[cfg(gdb)] dbg_mem_access_hdl: DbgMemAccessHandlerWrapper, + #[cfg(gdb)] dbg_mem_access_hdl: Arc>>, ) -> Result<()> { // Reset general purpose registers, then set RIP and RSP let regs = WHvGeneralRegisters { @@ -959,7 +955,7 @@ impl Hypervisor for HypervWindowsDriver { #[cfg(gdb)] fn handle_debug( &mut self, - dbg_mem_access_fn: Arc>, + dbg_mem_access_fn: Arc>>, stop_reason: super::gdb::VcpuStopReason, ) -> Result<()> { if self.debug.is_none() { diff --git a/src/hyperlight_host/src/hypervisor/kvm.rs b/src/hyperlight_host/src/hypervisor/kvm.rs index 26eae3e25..be76129fb 100644 --- a/src/hyperlight_host/src/hypervisor/kvm.rs +++ b/src/hyperlight_host/src/hypervisor/kvm.rs @@ -32,8 +32,6 @@ use super::TraceRegister; use super::fpu::{FP_CONTROL_WORD_DEFAULT, FP_TAG_WORD_DEFAULT, MXCSR_DEFAULT}; #[cfg(gdb)] use super::gdb::{DebugCommChannel, DebugMsg, DebugResponse, GuestDebug, KvmDebug, VcpuStopReason}; -#[cfg(gdb)] -use super::handlers::DbgMemAccessHandlerWrapper; #[cfg(feature = "init-paging")] use super::{ CR0_AM, CR0_ET, CR0_MP, CR0_NE, CR0_PE, CR0_PG, CR0_WP, CR4_OSFXSR, CR4_OSXMMEXCPT, CR4_PAE, @@ -88,7 +86,8 @@ mod debug { use crate::hypervisor::gdb::{ DebugMsg, DebugResponse, GuestDebug, KvmDebug, VcpuStopReason, X86_64Regs, }; - use crate::hypervisor::handlers::DbgMemAccessHandlerCaller; + use crate::mem::shared_mem::HostSharedMemory; + use crate::sandbox::mem_mgr::MemMgrWrapper; use crate::{Result, new_error}; impl KVMDriver { @@ -119,7 +118,7 @@ mod debug { pub(crate) fn process_dbg_request( &mut self, req: DebugMsg, - dbg_mem_access_fn: Arc>, + dbg_mem_access_fn: Arc>>, ) -> Result { if let Some(debug) = self.debug.as_mut() { match req { @@ -167,12 +166,9 @@ mod debug { .map_err(|e| { new_error!("Error locking at {}:{}: {}", file!(), line!(), e) })? - .get_code_offset() - .map_err(|e| { - log::error!("Failed to get code offset: {:?}", e); - - e - })?; + .unwrap_mgr() + .layout + .get_guest_code_address(); Ok(DebugResponse::GetCodeSectionOffset(offset as u64)) } @@ -479,7 +475,7 @@ impl Hypervisor for KVMDriver { mem_mgr: MemMgrWrapper, host_funcs: Arc>, max_guest_log_level: Option, - #[cfg(gdb)] dbg_mem_access_fn: DbgMemAccessHandlerWrapper, + #[cfg(gdb)] dbg_mem_access_fn: Arc>>, ) -> Result<()> { self.mem_mgr = Some(mem_mgr); self.host_funcs = Some(host_funcs); @@ -574,7 +570,7 @@ impl Hypervisor for KVMDriver { fn dispatch_call_from_host( &mut self, dispatch_func_addr: RawPtr, - #[cfg(gdb)] dbg_mem_access_fn: DbgMemAccessHandlerWrapper, + #[cfg(gdb)] dbg_mem_access_fn: Arc>>, ) -> Result<()> { // Reset general purpose registers, then set RIP and RSP let regs = kvm_regs { @@ -902,7 +898,7 @@ impl Hypervisor for KVMDriver { #[cfg(gdb)] fn handle_debug( &mut self, - dbg_mem_access_fn: Arc>, + dbg_mem_access_fn: Arc>>, stop_reason: VcpuStopReason, ) -> Result<()> { if self.debug.is_none() { diff --git a/src/hyperlight_host/src/hypervisor/mod.rs b/src/hyperlight_host/src/hypervisor/mod.rs index 53b721c7c..4e55e7ac5 100644 --- a/src/hyperlight_host/src/hypervisor/mod.rs +++ b/src/hyperlight_host/src/hypervisor/mod.rs @@ -17,6 +17,7 @@ limitations under the License. use log::LevelFilter; use tracing::{Span, instrument}; +use crate::HyperlightError::StackOverflow; use crate::error::HyperlightError::ExecutionCanceledByHost; use crate::mem::memory_region::{MemoryRegion, MemoryRegionFlags}; use crate::metrics::METRIC_GUEST_CANCELLATION; @@ -27,9 +28,7 @@ use crate::{HyperlightError, Result, log_then_return}; /// Util for handling x87 fpu state #[cfg(any(kvm, mshv, target_os = "windows"))] pub mod fpu; -/// Handlers for Hypervisor custom logic -#[cfg(gdb)] -pub mod handlers; + /// HyperV-on-linux functionality #[cfg(mshv)] pub mod hyperv_linux; @@ -71,12 +70,9 @@ use std::time::Duration; #[cfg(gdb)] use gdb::VcpuStopReason; -#[cfg(gdb)] -use self::handlers::{DbgMemAccessHandlerCaller, DbgMemAccessHandlerWrapper}; use crate::mem::ptr::RawPtr; use crate::mem::shared_mem::HostSharedMemory; use crate::sandbox::host_funcs::FunctionRegistry; -use crate::sandbox::mem_access::handle_mem_access; use crate::sandbox::mem_mgr::MemMgrWrapper; cfg_if::cfg_if! { @@ -148,7 +144,7 @@ pub(crate) trait Hypervisor: Debug + Send { mem_mgr: MemMgrWrapper, host_funcs: Arc>, guest_max_log_level: Option, - #[cfg(gdb)] dbg_mem_access_fn: DbgMemAccessHandlerWrapper, + #[cfg(gdb)] dbg_mem_access_fn: Arc>>, ) -> Result<()>; /// Map a region of host memory into the sandbox. @@ -175,7 +171,7 @@ pub(crate) trait Hypervisor: Debug + Send { fn dispatch_call_from_host( &mut self, dispatch_func_addr: RawPtr, - #[cfg(gdb)] dbg_mem_access_fn: DbgMemAccessHandlerWrapper, + #[cfg(gdb)] dbg_mem_access_fn: Arc>>, ) -> Result<()>; /// Handle an IO exit from the internally stored vCPU. @@ -240,7 +236,7 @@ pub(crate) trait Hypervisor: Debug + Send { /// handles the cases when the vCPU stops due to a Debug event fn handle_debug( &mut self, - _dbg_mem_access_fn: Arc>, + _dbg_mem_access_fn: Arc>>, _stop_reason: VcpuStopReason, ) -> Result<()> { unimplemented!() @@ -293,7 +289,7 @@ impl VirtualCPU { #[instrument(err(Debug), skip_all, parent = Span::current(), level = "Trace")] pub(crate) fn run( hv: &mut dyn Hypervisor, - #[cfg(gdb)] dbg_mem_access_fn: Arc>, + #[cfg(gdb)] dbg_mem_access_fn: Arc>>, ) -> Result<()> { loop { match hv.run() { @@ -314,7 +310,9 @@ impl VirtualCPU { #[cfg(crashdump)] crashdump::generate_crashdump(hv)?; - handle_mem_access(hv)?; + if !hv.check_stack_guard()? { + log_then_return!(StackOverflow()); + } log_then_return!("MMIO access address {:#x}", addr); } @@ -544,8 +542,6 @@ pub(crate) mod tests { use crate::mem::ptr::RawPtr; use crate::sandbox::host_funcs::FunctionRegistry; - #[cfg(gdb)] - use crate::sandbox::mem_access::dbg_mem_access_handler_wrapper; let filename = dummy_guest_as_string().map_err(|e| new_error!("{}", e))?; @@ -571,7 +567,7 @@ pub(crate) mod tests { let guest_max_log_level = Some(log::LevelFilter::Error); #[cfg(gdb)] - let dbg_mem_access_fn = dbg_mem_access_handler_wrapper(mem_mgr.clone()); + let dbg_mem_access_fn = Arc::new(Mutex::new(mem_mgr.clone())); // Test the initialise method vm.initialise( diff --git a/src/hyperlight_host/src/sandbox/initialized_multi_use.rs b/src/hyperlight_host/src/sandbox/initialized_multi_use.rs index ecc650c99..40464e328 100644 --- a/src/hyperlight_host/src/sandbox/initialized_multi_use.rs +++ b/src/hyperlight_host/src/sandbox/initialized_multi_use.rs @@ -33,12 +33,10 @@ use tracing::{Span, instrument}; use super::host_funcs::FunctionRegistry; use super::snapshot::Snapshot; -use super::{Callable, MemMgrWrapper, WrapperGetter}; +use super::{Callable, WrapperGetter}; use crate::HyperlightError::SnapshotSandboxMismatch; use crate::func::guest_err::check_for_guest_error; use crate::func::{ParameterTuple, SupportedReturnType}; -#[cfg(gdb)] -use crate::hypervisor::handlers::DbgMemAccessHandlerWrapper; use crate::hypervisor::{Hypervisor, InterruptHandle}; #[cfg(unix)] use crate::mem::memory_region::MemoryRegionType; @@ -46,6 +44,7 @@ use crate::mem::memory_region::{MemoryRegion, MemoryRegionFlags}; use crate::mem::ptr::RawPtr; use crate::mem::shared_mem::HostSharedMemory; use crate::metrics::maybe_time_and_emit_guest_call; +use crate::sandbox::mem_mgr::MemMgrWrapper; use crate::{Result, log_then_return}; /// Global counter for assigning unique IDs to sandboxes @@ -64,7 +63,7 @@ pub struct MultiUseSandbox { vm: Box, dispatch_ptr: RawPtr, #[cfg(gdb)] - dbg_mem_access_fn: DbgMemAccessHandlerWrapper, + dbg_mem_access_fn: Arc>>, /// If the current state of the sandbox has been captured in a snapshot, /// that snapshot is stored here. snapshot: Option, @@ -82,7 +81,7 @@ impl MultiUseSandbox { mgr: MemMgrWrapper, vm: Box, dispatch_ptr: RawPtr, - #[cfg(gdb)] dbg_mem_access_fn: DbgMemAccessHandlerWrapper, + #[cfg(gdb)] dbg_mem_access_fn: Arc>>, ) -> MultiUseSandbox { Self { id: SANDBOX_ID_COUNTER.fetch_add(1, Ordering::Relaxed), diff --git a/src/hyperlight_host/src/sandbox/mem_access.rs b/src/hyperlight_host/src/sandbox/mem_access.rs deleted file mode 100644 index e9de96e99..000000000 --- a/src/hyperlight_host/src/sandbox/mem_access.rs +++ /dev/null @@ -1,78 +0,0 @@ -/* -Copyright 2025 The Hyperlight Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#[cfg(gdb)] -use std::sync::{Arc, Mutex}; - -use tracing::{Span, instrument}; - -#[cfg(gdb)] -use super::mem_mgr::MemMgrWrapper; -use crate::error::HyperlightError::StackOverflow; -use crate::hypervisor::Hypervisor; -#[cfg(gdb)] -use crate::hypervisor::handlers::{DbgMemAccessHandlerCaller, DbgMemAccessHandlerWrapper}; -#[cfg(gdb)] -use crate::mem::shared_mem::HostSharedMemory; -use crate::{Result, log_then_return}; - -#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")] -pub(crate) fn handle_mem_access(hv: &dyn Hypervisor) -> Result<()> { - if !hv.check_stack_guard()? { - log_then_return!(StackOverflow()); - } - - Ok(()) -} - -#[cfg(gdb)] -struct DbgMemAccessContainer { - wrapper: MemMgrWrapper, -} - -#[cfg(gdb)] -impl DbgMemAccessHandlerCaller for DbgMemAccessContainer { - #[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")] - fn read(&mut self, addr: usize, data: &mut [u8]) -> Result<()> { - self.wrapper - .unwrap_mgr_mut() - .get_shared_mem_mut() - .copy_to_slice(data, addr) - } - - #[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")] - fn write(&mut self, addr: usize, data: &[u8]) -> Result<()> { - self.wrapper - .unwrap_mgr_mut() - .get_shared_mem_mut() - .copy_from_slice(data, addr) - } - - #[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")] - fn get_code_offset(&mut self) -> Result { - Ok(self.wrapper.unwrap_mgr().layout.get_guest_code_address()) - } -} - -#[cfg(gdb)] -#[instrument(skip_all, parent = Span::current(), level= "Trace")] -pub(crate) fn dbg_mem_access_handler_wrapper( - wrapper: MemMgrWrapper, -) -> DbgMemAccessHandlerWrapper { - let container = DbgMemAccessContainer { wrapper }; - - Arc::new(Mutex::new(container)) -} diff --git a/src/hyperlight_host/src/sandbox/mod.rs b/src/hyperlight_host/src/sandbox/mod.rs index 5b367cb6f..b3f54e738 100644 --- a/src/hyperlight_host/src/sandbox/mod.rs +++ b/src/hyperlight_host/src/sandbox/mod.rs @@ -23,9 +23,6 @@ pub(crate) mod hypervisor; /// Functionality for dealing with initialized sandboxes that can /// call 0 or more guest functions pub mod initialized_multi_use; -/// Functionality for dealing with memory access from the VM guest -/// executable -pub(crate) mod mem_access; /// Functionality for interacting with a sandbox's internally-stored /// `SandboxMemoryManager` pub(crate) mod mem_mgr; diff --git a/src/hyperlight_host/src/sandbox/uninitialized_evolve.rs b/src/hyperlight_host/src/sandbox/uninitialized_evolve.rs index 5db2722ef..dc84c97a3 100644 --- a/src/hyperlight_host/src/sandbox/uninitialized_evolve.rs +++ b/src/hyperlight_host/src/sandbox/uninitialized_evolve.rs @@ -21,8 +21,6 @@ use tracing::{Span, instrument}; use super::SandboxConfiguration; use super::hypervisor::{HypervisorType, get_available_hypervisor}; -#[cfg(gdb)] -use super::mem_access::dbg_mem_access_handler_wrapper; #[cfg(any(crashdump, gdb))] use super::uninitialized::SandboxRuntimeConfig; use crate::HyperlightError::NoHypervisorFound; @@ -90,7 +88,7 @@ where let page_size = u32::try_from(page_size::get())?; #[cfg(gdb)] - let dbg_mem_access_hdl = dbg_mem_access_handler_wrapper(hshm.clone()); + let dbg_mem_access_hdl = Arc::new(Mutex::new(hshm.clone())); #[cfg(target_os = "linux")] setup_signal_handlers(&u_sbox.config)?; @@ -123,7 +121,7 @@ where pub(super) fn evolve_impl_multi_use(u_sbox: UninitializedSandbox) -> Result { evolve_impl(u_sbox, |hf, hshm, vm, dispatch_ptr| { #[cfg(gdb)] - let dbg_mem_wrapper = dbg_mem_access_handler_wrapper(hshm.clone()); + let dbg_mem_wrapper = Arc::new(Mutex::new(hshm.clone())); Ok(MultiUseSandbox::from_uninit( hf, hshm,