@@ -209,18 +209,20 @@ pub trait InterruptHandle: Send + Sync + Debug {
209209 /// Interrupt the corresponding sandbox from running.
210210 ///
211211 /// This method sets a cancellation flag that prevents or stops the execution of guest code.
212- /// The effectiveness of this call depends on timing relative to the guest function call lifecycle:
213212 ///
214- /// - **Before guest call starts** (before `clear_cancel()` in `MultiUseSandbox::call()`):
215- /// The cancellation request will be cleared and ignored.
216- /// - **After guest call starts but before entering guest code** (after `clear_cancel()`, before `run_vcpu()`):
217- /// Will prevent the guest from executing.
218- /// - **While executing guest code**: Will interrupt the vCPU.
219- /// - **After guest call completes**: Has no effect (cancellation is cleared at the start of the next call).
213+ /// # Return Value
214+ ///
215+ /// The return value indicates whether a signal was sent to interrupt a running vCPU:
216+ /// - On Linux: Returns `true` if a signal was sent to the vCPU thread, `false` if the vCPU was not running.
217+ /// - On Windows: Returns `true` if `WHvCancelRunVirtualProcessor` was called successfully, `false` otherwise.
218+ ///
219+ /// **Important**: A return value of `false` does not mean the cancellation failed. The cancellation flag is
220+ /// always set, which will prevent or stop execution. A `false` return simply means no signal was sent because
221+ /// the vCPU was not actively running at that moment.
220222 ///
221223 /// # Note
222224 /// This function will block for the duration of the time it takes for the vcpu thread to be interrupted.
223- fn kill ( & self ) ;
225+ fn kill ( & self ) -> bool ;
224226
225227 /// Used by a debugger to interrupt the corresponding sandbox from running.
226228 ///
@@ -381,13 +383,13 @@ impl InterruptHandleImpl for LinuxInterruptHandle {
381383
382384#[ cfg( any( kvm, mshv3) ) ]
383385impl InterruptHandle for LinuxInterruptHandle {
384- fn kill ( & self ) {
386+ fn kill ( & self ) -> bool {
385387 // Release ordering ensures that any writes before kill() are visible to the vcpu thread
386388 // when it checks is_cancelled() with Acquire ordering
387389 self . state . fetch_or ( Self :: CANCEL_BIT , Ordering :: Release ) ;
388390
389391 // Send signals to interrupt the vcpu if it's currently running
390- self . send_signal ( ) ;
392+ self . send_signal ( )
391393 }
392394
393395 #[ cfg( gdb) ]
@@ -520,7 +522,7 @@ impl InterruptHandleImpl for WindowsInterruptHandle {
520522
521523#[ cfg( target_os = "windows" ) ]
522524impl InterruptHandle for WindowsInterruptHandle {
523- fn kill ( & self ) {
525+ fn kill ( & self ) -> bool {
524526 use windows:: Win32 :: System :: Hypervisor :: WHvCancelRunVirtualProcessor ;
525527
526528 // Release ordering ensures that any writes before kill() are visible to the vcpu thread
@@ -531,7 +533,7 @@ impl InterruptHandle for WindowsInterruptHandle {
531533 // This ensures we see the running state set by the vcpu thread
532534 let state = self . state . load ( Ordering :: Acquire ) ;
533535 if state & Self :: RUNNING_BIT == 0 {
534- return ;
536+ return false ;
535537 }
536538
537539 // Take read lock to prevent race with WHvDeletePartition in set_dropped().
@@ -541,19 +543,23 @@ impl InterruptHandle for WindowsInterruptHandle {
541543 Ok ( guard) => guard,
542544 Err ( e) => {
543545 log:: error!( "Failed to acquire partition_state read lock: {}" , e) ;
544- return ;
546+ return false ;
545547 }
546548 } ;
547549
548550 if guard. dropped {
549- return ;
551+ return false ;
550552 }
551553
552554 unsafe {
553- if let Err ( e) = WHvCancelRunVirtualProcessor ( guard. handle , 0 , 0 ) {
554- log:: error!( "Failed to cancel running virtual processor: {}" , e) ;
555+ match WHvCancelRunVirtualProcessor ( guard. handle , 0 , 0 ) {
556+ Ok ( _) => true ,
557+ Err ( e) => {
558+ log:: error!( "Failed to cancel running virtual processor: {}" , e) ;
559+ false
560+ }
555561 }
556- } ;
562+ }
557563 }
558564 #[ cfg( gdb) ]
559565 fn kill_from_debugger ( & self ) -> bool {
0 commit comments