wasmtime/
unix.rs

1//! Unix-specific extension for the `wasmtime` crate.
2//!
3//! This module is only available on Unix targets, for example Linux. Note that
4//! this module is notably not available on macOS or Windows.  Note that the
5//! import path for this module is `wasmtime::unix::...`, which is intended to
6//! emphasize that it is platform-specific.
7//!
8//! The traits contained in this module are intended to extend various types
9//! throughout the `wasmtime` crate with extra functionality that's only
10//! available on Unix.
11
12use crate::{AsContextMut, Store};
13
14/// Extensions for the [`Store`] type only available on Unix.
15pub trait StoreExt {
16    // TODO: needs more docs?
17    /// The signal handler must be
18    /// [async-signal-safe](http://man7.org/linux/man-pages/man7/signal-safety.7.html).
19    unsafe fn set_signal_handler<H>(&mut self, handler: H)
20    where
21        H: 'static
22            + Fn(libc::c_int, *const libc::siginfo_t, *const libc::c_void) -> bool
23            + Send
24            + Sync;
25}
26
27impl<T> StoreExt for Store<T> {
28    unsafe fn set_signal_handler<H>(&mut self, handler: H)
29    where
30        H: 'static
31            + Fn(libc::c_int, *const libc::siginfo_t, *const libc::c_void) -> bool
32            + Send
33            + Sync,
34    {
35        self.as_context_mut()
36            .0
37            .set_signal_handler(Some(Box::new(handler)));
38    }
39}