A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Don't use native signals on Unix targets without signal context support (#14990)
aofusa65c224427136
diff --git a/.github/workflows/main.yml b/.github/workflows/main.ymlindex c228dd4b1f..ca0c59f4c4 100644--- a/.github/workflows/main.yml+++ b/.github/workflows/main.yml@@ -624,6 +624,11 @@ jobs:- target: x86_64-unknown-freebsdos: ubuntu-latesttest: cargo check+ # Use `cross` for NetBSD to have a C compiler available.+ - target: x86_64-unknown-netbsd+ os: ubuntu-latest+ cross: true+ test: cross check- target: aarch64-pc-windows-msvcos: windows-latesttest: cargo checkdiff --git a/crates/wasmtime/build.rs b/crates/wasmtime/build.rsindex 1248e64ae5..d3a118ed93 100644--- a/crates/wasmtime/build.rs+++ b/crates/wasmtime/build.rs@@ -36,8 +36,15 @@ fn main() {_ => false,};+ // Determine if native signals are implemented for the current platform.+ let has_platform_signals = if supported_os {+ windows || has_unix_signal_handler(&target_arch)+ } else {+ cfg!(feature = "custom-native-signals")+ };+let has_native_signals = !miri- && (supported_os || cfg!(feature = "custom-native-signals"))+ && has_platform_signals&& has_host_compiler_backend&& !is_buggy_s390x_qemu_emulation();let has_virtual_memory = supported_os || cfg!(feature = "custom-virtual-memory");@@ -91,6 +98,20 @@ fn is_buggy_s390x_qemu_emulation() -> bool {&& std::env::var("CARGO_CFG_TARGET_ARCH").unwrap() == "s390x"}+// Keep in sync with the platforms in `src/runtime/vm/sys/unix/signals.rs`.+fn has_unix_signal_handler(arch: &str) -> bool {+ if cfg_is("target_vendor", "apple") {+ return matches!(arch, "x86_64" | "aarch64");+ }+ let os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();+ match (os.as_str(), arch) {+ ("linux" | "android" | "illumos" | "freebsd" | "openbsd" | "redox", "x86_64") => true,+ ("linux" | "android" | "freebsd", "aarch64") => true,+ ("linux", "s390x" | "riscv64") => true,+ _ => false,+ }+}+fn cfg(key: &str) -> bool {std::env::var(&format!("CARGO_CFG_{}", key.to_uppercase())).is_ok()}diff --git a/docs/stability-platform-support.md b/docs/stability-platform-support.mdindex 82e1ddd4fb..6663b0fb74 100644--- a/docs/stability-platform-support.md+++ b/docs/stability-platform-support.md@@ -73,6 +73,11 @@ OSes such as iOS, Android, and Illumos are supported but less well tested.PRs to the Wasmtime repository are welcome for new OSes for better nativeplatform support of a runtime environment.+On Unix platforms where Wasmtime does not support native signal handling, for+example NetBSD, Wasmtime still builds but does not use signals to catch traps.+Compiled code then performs explicit checks instead, the same as with+`Config::signals_based_traps(false)`, which is slower.+## Support for `#![no_std]`The `wasmtime` crate supports being build on no\_std platforms in Rust, but