pub trait InterruptHandle:
Debug
+ Send
+ Sync {
// Required methods
fn kill(&self) -> bool;
fn dropped(&self) -> bool;
}Expand description
A trait for handling interrupts to a sandbox’s vcpu (public API)
Required Methods§
Sourcefn kill(&self) -> bool
fn kill(&self) -> bool
Interrupt the corresponding sandbox from running.
This method attempts to cancel a currently executing guest function call by sending a signal to the VCPU thread. It uses generation tracking and call_active flag to ensure the interruption is safe and precise.
§Behavior
-
Guest function running: If called while a guest function is executing (VCPU running or in a host function call), this stamps the current generation into cancel_requested and sends a signal to interrupt the VCPU. Returns
true. -
No active call: If called when no guest function call is in progress (call_active=false), this has no effect and returns
false. This prevents “kill-in-advance” where kill() is called before a guest function starts. -
During host function: If the guest call is currently executing a host function (VCPU not running but call_active=true), this stamps cancel_requested. When the host function returns and attempts to re-enter the guest, the cancellation will be detected and the call will abort. Returns
true.
§Generation Tracking
The method stamps the current generation number along with the cancellation request. This ensures that:
- Stale signals from previous calls are ignored (generation mismatch)
- Only the intended guest function call is affected
- Multiple rapid kill() calls on the same generation are idempotent
§Blocking Behavior
This function will block while attempting to deliver the signal to the VCPU thread, retrying until either:
- The signal is successfully delivered (VCPU transitions from running to not running)
- The VCPU stops running for another reason (e.g., call completes normally)
§Returns
true: Cancellation request was stamped (kill will take effect)false: No active call, cancellation request was not stamped (no effect)
§Note
To reliably interrupt a guest call, ensure kill() is called while the guest
function is actually executing. Calling kill() before call_guest_function() will
have no effect.