Skip to content

Commit 857a1b4

Browse files
committed
Dont pass hv to outb_handler
Signed-off-by: Ludvig Liljenberg <[email protected]>
1 parent a165f74 commit 857a1b4

File tree

4 files changed

+38
-15
lines changed

4 files changed

+38
-15
lines changed

src/hyperlight_host/src/hypervisor/hyperv_linux.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,16 @@ impl Hypervisor for HypervLinuxDriver {
585585
padded[..copy_len].copy_from_slice(&data[..copy_len]);
586586
let val = u32::from_le_bytes(padded);
587587

588-
handle_outb(mem_mgr, host_funcs, port, val, self)?;
588+
#[cfg(feature = "mem_profile")]
589+
{
590+
let regs = self.regs()?;
591+
let trace_info = self.trace_info_mut();
592+
handle_outb(mem_mgr, host_funcs, port, val, &regs, trace_info)?;
593+
}
594+
#[cfg(not(feature = "mem_profile"))]
595+
{
596+
handle_outb(mem_mgr, host_funcs, port, val)?;
597+
}
589598

590599
// update rip
591600
self.vcpu_fd.set_reg(&[hv_register_assoc {

src/hyperlight_host/src/hypervisor/hyperv_windows.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,16 @@ impl Hypervisor for HypervWindowsDriver {
502502
padded[..copy_len].copy_from_slice(&data[..copy_len]);
503503
let val = u32::from_le_bytes(padded);
504504

505-
handle_outb(mem_mgr, host_funcs, port, val, self)?;
505+
#[cfg(feature = "mem_profile")]
506+
{
507+
let regs = self.regs()?;
508+
let trace_info = self.trace_info_mut();
509+
handle_outb(mem_mgr, host_funcs, port, val, &regs, trace_info)?;
510+
}
511+
#[cfg(not(feature = "mem_profile"))]
512+
{
513+
handle_outb(mem_mgr, host_funcs, port, val)?;
514+
}
506515

507516
let mut regs = self.regs()?;
508517
regs.rip = rip + instruction_length;

src/hyperlight_host/src/hypervisor/kvm.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,16 @@ impl Hypervisor for KVMDriver {
578578
padded[..copy_len].copy_from_slice(&data[..copy_len]);
579579
let value = u32::from_le_bytes(padded);
580580

581-
handle_outb(mem_mgr, host_funcs, port, value, self)?;
581+
#[cfg(feature = "mem_profile")]
582+
{
583+
let regs = self.regs()?;
584+
let trace_info = self.trace_info_mut();
585+
handle_outb(mem_mgr, host_funcs, port, value, &regs, trace_info)?;
586+
}
587+
#[cfg(not(feature = "mem_profile"))]
588+
{
589+
handle_outb(mem_mgr, host_funcs, port, value)?;
590+
}
582591
}
583592

584593
Ok(())

src/hyperlight_host/src/sandbox/outb.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ use tracing::{Span, instrument};
2525
use tracing_log::format_trace;
2626

2727
use super::host_funcs::FunctionRegistry;
28-
use crate::hypervisor::Hypervisor;
28+
#[cfg(feature = "mem_profile")]
29+
use crate::hypervisor::regs::CommonRegisters;
2930
use crate::mem::mgr::SandboxMemoryManager;
3031
use crate::mem::shared_mem::HostSharedMemory;
32+
#[cfg(feature = "mem_profile")]
33+
use crate::sandbox::trace::MemTraceInfo;
3134
use crate::{HyperlightError, Result, new_error};
3235

3336
#[instrument(err(Debug), skip_all, parent = Span::current(), level="Trace")]
@@ -149,7 +152,8 @@ pub(crate) fn handle_outb(
149152
host_funcs: &Arc<Mutex<FunctionRegistry>>,
150153
port: u16,
151154
data: u32,
152-
_hv: &mut dyn Hypervisor,
155+
#[cfg(feature = "mem_profile")] regs: &CommonRegisters,
156+
#[cfg(feature = "mem_profile")] trace_info: &mut MemTraceInfo,
153157
) -> Result<()> {
154158
match port.try_into()? {
155159
OutBAction::Log => outb_log(mem_mgr),
@@ -184,17 +188,9 @@ pub(crate) fn handle_outb(
184188
#[cfg(feature = "trace_guest")]
185189
OutBAction::TraceBatch => Ok(()),
186190
#[cfg(feature = "mem_profile")]
187-
OutBAction::TraceMemoryAlloc => {
188-
let regs = _hv.regs()?;
189-
let trace_info = _hv.trace_info_mut();
190-
trace_info.handle_trace_mem_alloc(&regs, mem_mgr)
191-
}
191+
OutBAction::TraceMemoryAlloc => trace_info.handle_trace_mem_alloc(regs, mem_mgr),
192192
#[cfg(feature = "mem_profile")]
193-
OutBAction::TraceMemoryFree => {
194-
let regs = _hv.regs()?;
195-
let trace_info = _hv.trace_info_mut();
196-
trace_info.handle_trace_mem_free(&regs, mem_mgr)
197-
}
193+
OutBAction::TraceMemoryFree => trace_info.handle_trace_mem_free(regs, mem_mgr),
198194
}
199195
}
200196
#[cfg(test)]

0 commit comments

Comments
 (0)