Skip to content

Commit 731b426

Browse files
authored
Fixes issues from merge and splits trait to expose only public method (#994)
Signed-off-by: Simon Davies <[email protected]>
1 parent 86b25b6 commit 731b426

File tree

5 files changed

+97
-114
lines changed

5 files changed

+97
-114
lines changed

src/hyperlight_host/src/hypervisor/hyperv_linux.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ use super::gdb::{
4848
DebugCommChannel, DebugMemoryAccess, DebugMsg, DebugResponse, GuestDebug, MshvDebug,
4949
VcpuStopReason,
5050
};
51-
use super::{HyperlightExit, Hypervisor, InterruptHandle, LinuxInterruptHandle, VirtualCPU};
51+
use super::{HyperlightExit, Hypervisor, LinuxInterruptHandle, VirtualCPU};
5252
#[cfg(gdb)]
5353
use crate::HyperlightError;
5454
use crate::hypervisor::get_memory_access_violation;
@@ -647,11 +647,15 @@ impl Hypervisor for HypervLinuxDriver {
647647
.tid
648648
.store(unsafe { libc::pthread_self() as u64 }, Ordering::Release);
649649
// Note: if `InterruptHandle::kill()` is called while this thread is **here**
650+
// Cast to internal trait for access to internal methods
651+
let interrupt_handle_internal =
652+
self.interrupt_handle.as_ref() as &dyn super::InterruptHandleInternal;
653+
650654
// (after set_running_bit but before checking cancel_requested):
651655
// - kill() will stamp cancel_requested with the current generation
652656
// - We will check cancel_requested below and skip the VcpuFd::run() call
653657
// - This is the desired behavior - the kill takes effect immediately
654-
let generation = self.interrupt_handle.set_running_bit();
658+
let generation = interrupt_handle_internal.set_running_bit();
655659

656660
#[cfg(not(gdb))]
657661
let debug_interrupt = false;
@@ -668,8 +672,7 @@ impl Hypervisor for HypervLinuxDriver {
668672
// - kill() will stamp cancel_requested with the current generation
669673
// - We will proceed with vcpu.run(), but signals will be sent to interrupt it
670674
// - The vcpu will be interrupted and return EINTR (handled below)
671-
let exit_reason = if self
672-
.interrupt_handle
675+
let exit_reason = if interrupt_handle_internal
673676
.is_cancel_requested_for_generation(generation)
674677
|| debug_interrupt
675678
{
@@ -690,9 +693,8 @@ impl Hypervisor for HypervLinuxDriver {
690693
// - kill() continues sending signals to this thread (running bit is still set)
691694
// - The signals are harmless (no-op handler), we just need to check cancel_requested
692695
// - We load cancel_requested below to determine if this run was cancelled
693-
let cancel_requested = self
694-
.interrupt_handle
695-
.is_cancel_requested_for_generation(generation);
696+
let cancel_requested =
697+
interrupt_handle_internal.is_cancel_requested_for_generation(generation);
696698
#[cfg(gdb)]
697699
let debug_interrupt = self
698700
.interrupt_handle
@@ -704,7 +706,7 @@ impl Hypervisor for HypervLinuxDriver {
704706
// - kill() continues sending signals until running bit is cleared
705707
// - The newly stamped cancel_requested will affect the NEXT vcpu.run() call
706708
// - Signals sent now are harmless (no-op handler)
707-
self.interrupt_handle.clear_running_bit();
709+
interrupt_handle_internal.clear_running_bit();
708710
// At this point, running bit is clear so kill() will stop sending signals.
709711
// However, we may still receive delayed signals that were sent before clear_running_bit.
710712
// These stale signals are harmless because:
@@ -799,7 +801,7 @@ impl Hypervisor for HypervLinuxDriver {
799801
// - A signal meant for a different sandbox on the same thread
800802
// In these cases, we return Retry to continue execution.
801803
if cancel_requested {
802-
self.interrupt_handle.clear_cancel_requested();
804+
interrupt_handle_internal.clear_cancel_requested();
803805
HyperlightExit::Cancelled()
804806
} else {
805807
#[cfg(gdb)]
@@ -868,7 +870,7 @@ impl Hypervisor for HypervLinuxDriver {
868870
self as &mut dyn Hypervisor
869871
}
870872

871-
fn interrupt_handle(&self) -> Arc<dyn InterruptHandle> {
873+
fn interrupt_handle(&self) -> Arc<dyn super::InterruptHandleInternal> {
872874
self.interrupt_handle.clone()
873875
}
874876

src/hyperlight_host/src/hypervisor/hyperv_windows.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ use super::surrogate_process_manager::*;
4545
use super::windows_hypervisor_platform::{VMPartition, VMProcessor};
4646
use super::wrappers::HandleWrapper;
4747
use super::{HyperlightExit, Hypervisor, InterruptHandle, VirtualCPU};
48-
use crate::hypervisor::get_memory_access_violation;
4948
use crate::hypervisor::regs::{CommonFpu, CommonRegisters};
49+
use crate::hypervisor::{InterruptHandleInternal, get_memory_access_violation};
5050
use crate::mem::memory_region::{MemoryRegion, MemoryRegionFlags};
5151
use crate::mem::mgr::SandboxMemoryManager;
5252
use crate::mem::ptr::{GuestPtr, RawPtr};
@@ -550,8 +550,12 @@ impl Hypervisor for HypervWindowsDriver {
550550
&mut self,
551551
#[cfg(feature = "trace_guest")] tc: &mut crate::sandbox::trace::TraceContext,
552552
) -> Result<super::HyperlightExit> {
553+
// Cast to internal trait for access to internal methods
554+
let interrupt_handle_internal =
555+
self.interrupt_handle.as_ref() as &dyn super::InterruptHandleInternal;
556+
553557
// Get current generation and set running bit
554-
let generation = self.interrupt_handle.set_running_bit();
558+
let generation = interrupt_handle_internal.set_running_bit();
555559

556560
#[cfg(not(gdb))]
557561
let debug_interrupt = false;
@@ -562,8 +566,7 @@ impl Hypervisor for HypervWindowsDriver {
562566
.load(Ordering::Relaxed);
563567

564568
// Check if cancellation was requested for THIS generation
565-
let exit_context = if self
566-
.interrupt_handle
569+
let exit_context = if interrupt_handle_internal
567570
.is_cancel_requested_for_generation(generation)
568571
|| debug_interrupt
569572
{
@@ -581,18 +584,17 @@ impl Hypervisor for HypervWindowsDriver {
581584
};
582585

583586
// Clear running bit
584-
self.interrupt_handle.clear_running_bit();
587+
interrupt_handle_internal.clear_running_bit();
585588

586589
let is_canceled = exit_context.ExitReason == WHV_RUN_VP_EXIT_REASON(8193i32); // WHvRunVpExitReasonCanceled
587590

588591
// Check if this was a manual cancellation (vs internal Windows cancellation)
589-
let cancel_was_requested_manually = self
590-
.interrupt_handle
591-
.is_cancel_requested_for_generation(generation);
592+
let cancel_was_requested_manually =
593+
interrupt_handle_internal.is_cancel_requested_for_generation(generation);
592594

593595
// Only clear cancel_requested if we're actually processing a cancellation for this generation
594596
if is_canceled && cancel_was_requested_manually {
595-
self.interrupt_handle.clear_cancel_requested();
597+
interrupt_handle_internal.clear_cancel_requested();
596598
}
597599

598600
#[cfg(gdb)]
@@ -752,7 +754,7 @@ impl Hypervisor for HypervWindowsDriver {
752754
self.processor.set_sregs(sregs)
753755
}
754756

755-
fn interrupt_handle(&self) -> Arc<dyn InterruptHandle> {
757+
fn interrupt_handle(&self) -> Arc<dyn super::InterruptHandleInternal> {
756758
self.interrupt_handle.clone()
757759
}
758760

@@ -1045,19 +1047,22 @@ impl InterruptHandle for WindowsInterruptHandle {
10451047
// Only call WHvCancelRunVirtualProcessor if VCPU is actually running in guest mode
10461048
running && unsafe { WHvCancelRunVirtualProcessor(self.partition_handle, 0, 0).is_ok() }
10471049
}
1050+
10481051
#[cfg(gdb)]
10491052
fn kill_from_debugger(&self) -> bool {
10501053
self.debug_interrupt.store(true, Ordering::Relaxed);
10511054
let (running, _) = self.get_running_and_generation();
10521055
running && unsafe { WHvCancelRunVirtualProcessor(self.partition_handle, 0, 0).is_ok() }
10531056
}
10541057

1055-
fn get_call_active(&self) -> &AtomicBool {
1056-
&self.call_active
1058+
fn dropped(&self) -> bool {
1059+
self.dropped.load(Ordering::Relaxed)
10571060
}
1061+
}
10581062

1059-
fn get_dropped(&self) -> &AtomicBool {
1060-
&self.dropped
1063+
impl InterruptHandleInternal for WindowsInterruptHandle {
1064+
fn get_call_active(&self) -> &AtomicBool {
1065+
&self.call_active
10611066
}
10621067

10631068
fn get_running(&self) -> &AtomicU64 {

src/hyperlight_host/src/hypervisor/kvm.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use super::gdb::{
3333
DebugCommChannel, DebugMemoryAccess, DebugMsg, DebugResponse, GuestDebug, KvmDebug,
3434
VcpuStopReason,
3535
};
36-
use super::{HyperlightExit, Hypervisor, InterruptHandle, LinuxInterruptHandle, VirtualCPU};
36+
use super::{HyperlightExit, Hypervisor, LinuxInterruptHandle, VirtualCPU};
3737
#[cfg(gdb)]
3838
use crate::HyperlightError;
3939
use crate::hypervisor::get_memory_access_violation;
@@ -623,11 +623,15 @@ impl Hypervisor for KVMDriver {
623623
.tid
624624
.store(unsafe { libc::pthread_self() as u64 }, Ordering::Release);
625625
// Note: if `InterruptHandle::kill()` is called while this thread is **here**
626+
// Cast to internal trait for access to internal methods
627+
let interrupt_handle_internal =
628+
self.interrupt_handle.as_ref() as &dyn super::InterruptHandleInternal;
629+
626630
// (after set_running_bit but before checking cancel_requested):
627631
// - kill() will stamp cancel_requested with the current generation
628632
// - We will check cancel_requested below and skip the VcpuFd::run() call
629633
// - This is the desired behavior - the kill takes effect immediately
630-
let generation = self.interrupt_handle.set_running_bit();
634+
let generation = interrupt_handle_internal.set_running_bit();
631635

632636
#[cfg(not(gdb))]
633637
let debug_interrupt = false;
@@ -643,8 +647,7 @@ impl Hypervisor for KVMDriver {
643647
// - kill() will stamp cancel_requested with the current generation
644648
// - We will proceed with vcpu.run(), but signals will be sent to interrupt it
645649
// - The vcpu will be interrupted and return EINTR (handled below)
646-
let exit_reason = if self
647-
.interrupt_handle
650+
let exit_reason = if interrupt_handle_internal
648651
.is_cancel_requested_for_generation(generation)
649652
|| debug_interrupt
650653
{
@@ -666,9 +669,8 @@ impl Hypervisor for KVMDriver {
666669
// - kill() continues sending signals to this thread (running bit is still set)
667670
// - The signals are harmless (no-op handler), we just need to check cancel_requested
668671
// - We load cancel_requested below to determine if this run was cancelled
669-
let cancel_requested = self
670-
.interrupt_handle
671-
.is_cancel_requested_for_generation(generation);
672+
let cancel_requested =
673+
interrupt_handle_internal.is_cancel_requested_for_generation(generation);
672674
#[cfg(gdb)]
673675
let debug_interrupt = self
674676
.interrupt_handle
@@ -680,7 +682,7 @@ impl Hypervisor for KVMDriver {
680682
// - kill() continues sending signals until running bit is cleared
681683
// - The newly stamped cancel_requested will affect the NEXT vcpu.run() call
682684
// - Signals sent now are harmless (no-op handler)
683-
self.interrupt_handle.clear_running_bit();
685+
interrupt_handle_internal.clear_running_bit();
684686
// At this point, running bit is clear so kill() will stop sending signals.
685687
// However, we may still receive delayed signals that were sent before clear_running_bit.
686688
// These stale signals are harmless because:
@@ -744,7 +746,7 @@ impl Hypervisor for KVMDriver {
744746
// - A signal meant for a different sandbox on the same thread
745747
// In these cases, we return Retry to continue execution.
746748
if cancel_requested {
747-
self.interrupt_handle.clear_cancel_requested();
749+
interrupt_handle_internal.clear_cancel_requested();
748750
HyperlightExit::Cancelled()
749751
} else {
750752
#[cfg(gdb)]
@@ -818,7 +820,7 @@ impl Hypervisor for KVMDriver {
818820
self as &mut dyn Hypervisor
819821
}
820822

821-
fn interrupt_handle(&self) -> Arc<dyn InterruptHandle> {
823+
fn interrupt_handle(&self) -> Arc<dyn super::InterruptHandleInternal> {
822824
self.interrupt_handle.clone()
823825
}
824826

0 commit comments

Comments
 (0)