substrate_wasmtime/unix.rs
1//! Unix-specific extension for the `wasmtime` crate.
2//!
3//! This module is only available on Unix targets, for example Linux and macOS.
4//! It is not available on Windows, for example. Note that the import path for
5//! this module is `wasmtime::unix::...`, which is intended to emphasize that it
6//! 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::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>(&self, handler: H)
20 where
21 H: 'static + Fn(libc::c_int, *const libc::siginfo_t, *const libc::c_void) -> bool;
22}
23
24impl StoreExt for Store {
25 unsafe fn set_signal_handler<H>(&self, handler: H)
26 where
27 H: 'static + Fn(libc::c_int, *const libc::siginfo_t, *const libc::c_void) -> bool,
28 {
29 *self.signal_handler_mut() = Some(Box::new(handler));
30 }
31}