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