wasmtime/runtime/
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
12#[cfg(has_native_signals)]
13use crate::prelude::*;
14#[cfg(has_native_signals)]
15use crate::AsContextMut;
16use crate::Store;
17
18/// Extensions for the [`Store`] type only available on Unix.
19pub trait StoreExt {
20    // TODO: needs more docs?
21    /// The signal handler must be
22    /// [async-signal-safe](http://man7.org/linux/man-pages/man7/signal-safety.7.html).
23    #[cfg(has_native_signals)]
24    unsafe fn set_signal_handler<H>(&mut self, handler: H)
25    where
26        H: 'static
27            + Fn(libc::c_int, *const libc::siginfo_t, *const libc::c_void) -> bool
28            + Send
29            + Sync;
30}
31
32impl<T> StoreExt for Store<T> {
33    #[cfg(has_native_signals)]
34    unsafe fn set_signal_handler<H>(&mut self, handler: H)
35    where
36        H: 'static
37            + Fn(libc::c_int, *const libc::siginfo_t, *const libc::c_void) -> bool
38            + Send
39            + Sync,
40    {
41        self.as_context_mut()
42            .0
43            .set_signal_handler(Some(Box::new(handler)));
44    }
45}