Skip to content
Closed
13 changes: 11 additions & 2 deletions src/hyperlight_host/src/hypervisor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,17 @@ pub(crate) trait InterruptHandleImpl: InterruptHandle {
pub trait InterruptHandle: Send + Sync + Debug {
/// Interrupt the corresponding sandbox from running.
///
/// - If this is called while the the sandbox currently executing a guest function call, it will interrupt the sandbox and return `true`.
/// - If this is called while the sandbox is not running (for example before or after calling a guest function), it will do nothing and return `false`.
/// This method sets a cancellation flag that prevents or stops the execution of guest code.
///
/// # Return Value
///
/// The return value indicates whether a signal was sent to interrupt a running vCPU:
/// - On Linux: Returns `true` if a signal was sent to the vCPU thread, `false` if the vCPU was not running.
/// - On Windows: Returns `true` if `WHvCancelRunVirtualProcessor` was called successfully, `false` otherwise.
///
/// **Important**: A return value of `false` does not mean the cancellation failed. The cancellation flag is
/// always set, which will prevent or stop execution. A `false` return simply means no signal was sent because
/// the vCPU was not actively running at that moment.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think something like

/// Cancel guest execution in the corresponding sandbox.
///
/// If a guest call is in progress, it will be cancelled and the guest function call
/// will return an error. If called before a guest call is made, it has no effect on
/// future guest calls.
///
/// # Returns
/// - `true` if a guest call was in progress and the vcpu was actively running.
/// - `false` otherwise (no guest call in progress, or guest call in progress but vcpu
///   not yet running). Any in-progress guest call will still be cancelled.
///
/// # Platform behavior
/// - **Linux**: If the vcpu is running, this function will block for the duration of
///   the time it takes for the vcpu thread to be interrupted.
/// - **Windows**: This function returns immediately after requesting cancellation.
fn kill(&self) -> bool;

would be better @copilot

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the documentation in commit 533f3a8. The new format is clearer and more user-focused, with separate sections for the return value and platform-specific behavior.

///
/// # Note
/// This function will block for the duration of the time it takes for the vcpu thread to be interrupted.
Expand Down