wasmer_vm/interrupt_registry/
mod.rs

1//! Implements the necessary infrastructure for interrupting running WASM code
2//! via OS signals.
3//!
4//! This module is meant to be used from within the wasmer crate. Embedders
5//! should not call any of the functions here; instead, they should go
6//! through [`wasmer::Store::get_interrupter`].
7
8// TODO: Windows support
9
10use thiserror::Error;
11use wasmer_types::StoreId;
12
13#[cfg(unix)]
14mod unix;
15#[cfg(unix)]
16pub use unix::*;
17
18// The unsupported module implements no-op functions instead of panicking;
19// this lets us avoid a bunch of #[cfg]'s everywhere in the runtime code.
20#[cfg(not(unix))]
21mod unsupported;
22#[cfg(not(unix))]
23pub use unsupported::*;
24
25#[derive(Debug, Error)]
26#[allow(missing_docs)]
27pub enum InstallError {
28    #[error("This store was already interrupted and can't be entered again")]
29    AlreadyInterrupted,
30}
31
32#[derive(Debug, Error)]
33#[allow(missing_docs)]
34pub enum InterruptError {
35    #[error("Store not running")]
36    StoreNotRunning,
37    #[error("Another interrupt is already in progress on the target thread")]
38    OtherInterruptInProgress,
39    #[error("Failed to send interrupt signal due to OS error: {0}")]
40    FailedToSendSignal(&'static str),
41}
42
43/// Uninstalls interrupt state when dropped
44pub struct InterruptInstallGuard {
45    store_id: StoreId,
46}
47
48impl Drop for InterruptInstallGuard {
49    fn drop(&mut self) {
50        let store_id = self.store_id;
51        uninstall(store_id);
52    }
53}