Skip to content

Commit 118ff1a

Browse files
committed
expose the interrup handler
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
1 parent 61d4c61 commit 118ff1a

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/hyperlight_wasm/src/sandbox/loaded_wasm_sandbox.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
use std::sync::Arc;
18+
1719
use hyperlight_host::func::{ParameterTuple, SupportedReturnType};
20+
// re-export the InterruptHandle trait as it's part of the public API
21+
pub use hyperlight_host::hypervisor::InterruptHandle;
1822
use hyperlight_host::sandbox::Callable;
1923
use hyperlight_host::sandbox_state::sandbox::{DevolvableSandbox, Sandbox};
2024
use hyperlight_host::sandbox_state::transition::Noop;
21-
use hyperlight_host::{MultiUseSandbox, Result, log_then_return};
25+
use hyperlight_host::{MultiUseSandbox, Result, log_then_return, new_error};
2226

2327
use super::metrics::METRIC_TOTAL_LOADED_WASM_SANDBOXES;
2428
use super::wasm_sandbox::WasmSandbox;
@@ -72,6 +76,18 @@ impl LoadedWasmSandbox {
7276
metrics::counter!(METRIC_TOTAL_LOADED_WASM_SANDBOXES).increment(1);
7377
Ok(LoadedWasmSandbox { inner: Some(inner) })
7478
}
79+
80+
/// Get a handle to the interrupt handler for this sandbox,
81+
/// capable of interrupting guest execution.
82+
pub fn interrupt_handle(&self) -> Result<Arc<dyn InterruptHandle>> {
83+
if let Some(inner) = &self.inner {
84+
Ok(inner.interrupt_handle())
85+
} else {
86+
Err(new_error!(
87+
"WasmSandbox is None, cannot get interrupt handle"
88+
))
89+
}
90+
}
7591
}
7692

7793
impl Callable for LoadedWasmSandbox {

src/hyperlight_wasm/src/sandbox/wasm_sandbox.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ mod tests {
148148

149149
let mut loaded = loaded.load_module(run_wasm)?;
150150

151+
let interrupt = loaded.interrupt_handle()?;
152+
153+
std::thread::spawn(move || {
154+
std::thread::sleep(std::time::Duration::from_millis(1000));
155+
interrupt.kill();
156+
});
157+
151158
let result = loaded.call_guest_function::<i32>("KeepCPUBusy", 10000i32);
152159

153160
match result {

0 commit comments

Comments
 (0)