@@ -28,23 +28,25 @@ use gdbstub::target::ext::breakpoints::{
2828use  gdbstub:: target:: ext:: section_offsets:: { Offsets ,  SectionOffsets } ; 
2929use  gdbstub:: target:: { Target ,  TargetError ,  TargetResult } ; 
3030use  gdbstub_arch:: x86:: X86_64_SSE  as  GdbTargetArch ; 
31+ use  std:: sync:: Arc ; 
32+ 
33+ use  crate :: hypervisor:: InterruptHandle ; 
3134
3235use  super :: { DebugCommChannel ,  DebugMsg ,  DebugResponse ,  GdbTargetError ,  X86_64Regs } ; 
3336
3437/// Gdbstub target used by the gdbstub crate to provide GDB protocol implementation 
3538pub ( crate )  struct  HyperlightSandboxTarget  { 
3639    /// Hypervisor communication channels 
3740hyp_conn :  DebugCommChannel < DebugMsg ,  DebugResponse > , 
38-     /// Thread ID 
39- #[ allow( dead_code) ]  
40-     thread_id :  u64 , 
41+     /// Interrupt handle for the vCPU thread 
42+ interrupt_handle :  Option < Arc < dyn  InterruptHandle > > , 
4143} 
4244
4345impl  HyperlightSandboxTarget  { 
44-     pub ( crate )  fn  new ( hyp_conn :  DebugCommChannel < DebugMsg ,  DebugResponse > ,   thread_id :   u64 )  -> Self  { 
46+     pub ( crate )  fn  new ( hyp_conn :  DebugCommChannel < DebugMsg ,  DebugResponse > )  -> Self  { 
4547        HyperlightSandboxTarget  { 
4648            hyp_conn, 
47-             thread_id , 
49+             interrupt_handle :   None , 
4850        } 
4951    } 
5052
@@ -61,10 +63,9 @@ impl HyperlightSandboxTarget {
6163        self . hyp_conn . send ( ev) 
6264    } 
6365
64-     /// Returns the thread ID 
65- #[ allow( dead_code) ]  
66-     pub ( crate )  fn  get_thread_id ( & self )  -> u64  { 
67-         self . thread_id 
66+     /// Set the interrupt handle for the vCPU thread 
67+ pub ( crate )  fn  set_interrupt_handle ( & mut  self ,  handle :  Arc < dyn  InterruptHandle > )  { 
68+         self . interrupt_handle  = Some ( handle) ; 
6869    } 
6970
7071    /// Waits for a response over the communication channel 
@@ -109,6 +110,17 @@ impl HyperlightSandboxTarget {
109110            } 
110111        } 
111112    } 
113+ 
114+     /// Interrupts the vCPU execution 
115+ pub ( crate )  fn  interrupt_vcpu ( & mut  self )  -> bool  { 
116+         if  let  Some ( handle)  = & self . interrupt_handle  { 
117+             handle. kill ( ) 
118+         }  else  { 
119+             log:: warn!( "No interrupt handle set, cannot interrupt vCPU" ) ; 
120+ 
121+             false 
122+         } 
123+     } 
112124} 
113125
114126impl  Target  for  HyperlightSandboxTarget  { 
@@ -418,7 +430,7 @@ mod tests {
418430    fn  test_gdb_target ( )  { 
419431        let  ( gdb_conn,  hyp_conn)  = DebugCommChannel :: unbounded ( ) ; 
420432
421-         let  mut  target = HyperlightSandboxTarget :: new ( hyp_conn,   0 ) ; 
433+         let  mut  target = HyperlightSandboxTarget :: new ( hyp_conn) ; 
422434
423435        // Check response to read registers - send the response first to not be blocked 
424436        // by the recv call in the target 
0 commit comments