Skip to content

Commit 376f3c7

Browse files
committed
Switch macOS to using mach ports for trap handling
This commit moves macOS to using mach ports instead of signals for handling traps. The motivation for this is listed in #2456, namely that once mach ports are used in a process that means traditional UNIX signal handlers won't get used. This means that if Wasmtime is integrated with Breakpad, for example, then Wasmtime's trap handler never fires and traps don't work. The `traphandlers` module is refactored as part of this commit to split the platform-specific bits into their own files (it was growing quite a lot for one inline `cfg_if!`). The `unix.rs` and `windows.rs` files remain the same as they were before with a few minor tweaks for some refactored interfaces. The `macos.rs` file is brand new and lifts almost its entire implementation from SpiderMonkey, adapted for Wasmtime though. The main gotcha with mach ports is that a separate thread is what services the exception. Some unsafe magic allows this separate thread to read non-`Send` and temporary state from other threads, but is hoped to be safe in this context. The unfortunate downside is that calling wasm on macOS now involves taking a global lock and modifying a global hash map twice-per-call. I'm not entirely sure how to get out of this cost for now, but hopefully for any embeddings on macOS it's not the end of the world. Closes #2456
1 parent 256cc8a commit 376f3c7

10 files changed

Lines changed: 832 additions & 372 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/runtime/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ backtrace = "0.3.55"
2525
lazy_static = "1.3.0"
2626
psm = "0.1.11"
2727

28+
[target.'cfg(target_os = "macos")'.dependencies]
29+
mach = "0.3.2"
30+
2831
[target.'cfg(target_os = "windows")'.dependencies]
2932
winapi = { version = "0.3.7", features = ["winbase", "memoryapi", "errhandlingapi"] }
3033

crates/runtime/src/traphandlers.rs

Lines changed: 28 additions & 366 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)