Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Expose signals_based_traps config option to C API (#11879)

Vladimir Cherkasovd6dbcd29a205
diff --git a/crates/c-api/include/wasmtime/config.h b/crates/c-api/include/wasmtime/config.h
index ab104e95f7..67414f79db 100644
--- a/crates/c-api/include/wasmtime/config.h
+++ b/crates/c-api/include/wasmtime/config.h
@@ -451,6 +451,19 @@ WASM_API_EXTERN void wasmtime_config_cranelift_flag_set(wasm_config_t *,
*/
WASMTIME_CONFIG_PROP(void, macos_use_mach_ports, bool)
+/**
+ * \brief Configures Wasmtime to not use signals-based trap handlers, for
+ * example disables `SIGILL` and `SIGSEGV` handler registration on Unix
+ * platforms.
+ *
+ * This option defaults to `true`: signals-based trap handlers are enabled
+ * by default.
+ *
+ * For more information see the Rust documentation at
+ * https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.signals_based_traps
+ */
+WASMTIME_CONFIG_PROP(void, signals_based_traps, bool)
+
/**
* Return the data from a LinearMemory instance.
*
diff --git a/crates/c-api/include/wasmtime/config.hh b/crates/c-api/include/wasmtime/config.hh
index 6c72942610..491e17eb4f 100644
--- a/crates/c-api/include/wasmtime/config.hh
+++ b/crates/c-api/include/wasmtime/config.hh
@@ -523,6 +523,12 @@ public:
wasmtime_config_macos_use_mach_ports_set(ptr.get(), enable);
}
+ /// \brief Configures Wasmtime to not use signals-based trap handlers
+ /// https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.signals_based_traps
+ void signals_based_traps(bool enable) {
+ wasmtime_config_signals_based_traps_set(ptr.get(), enable);
+ }
+
#ifdef WASMTIME_FEATURE_CACHE
/// \brief Loads the default cache configuration present on the system.
///
diff --git a/crates/c-api/src/config.rs b/crates/c-api/src/config.rs
index 0f215cc9c2..887ddbc35f 100644
--- a/crates/c-api/src/config.rs
+++ b/crates/c-api/src/config.rs
@@ -277,6 +277,11 @@ pub extern "C" fn wasmtime_config_macos_use_mach_ports_set(c: &mut wasm_config_t
c.config.macos_use_mach_ports(enabled);
}
+#[unsafe(no_mangle)]
+pub extern "C" fn wasmtime_config_signals_based_traps_set(c: &mut wasm_config_t, enable: bool) {
+ c.config.signals_based_traps(enable);
+}
+
#[unsafe(no_mangle)]
#[cfg(any(feature = "cranelift", feature = "winch"))]
pub unsafe extern "C" fn wasmtime_config_cranelift_flag_enable(