Skip to content

Fix preservation of the sigaltstack on macOS#2676

Merged
alexcrichton merged 2 commits intobytecodealliance:mainfrom
alexcrichton:macos-sigaltstack
Feb 23, 2021
Merged

Fix preservation of the sigaltstack on macOS#2676
alexcrichton merged 2 commits intobytecodealliance:mainfrom
alexcrichton:macos-sigaltstack

Conversation

@alexcrichton
Copy link
Member

This commit fixes an issue discovered in the wasmtime-go bindings when
the Go runtime was crashing on macOS only when running wasm code that
trapped. It turns out that our switch to siglongjmp from longjmp
actually broke macOS! This breakage happens because all subsequent
signals after the first signal are all delivered on the main stack, not
the sigaltstack, even if the sigaltstack is configured. This causes the
Go runtime to crash since it expects to run on the sigaltstack.

The fix in this commit is to actually return from the signal handler to
trigger the kernel's updating of the sigaltstack no longer being in use.
Before we return, however, we configure the register context to return
to to call some custom code which immediately does the unwind we would
otherwise have done. This works around the issue on macOS hopefully
without adding too many portability problems. Ideally this will all go
away as well with #2632 as well.

This commit fixes an issue discovered in the wasmtime-go bindings when
the Go runtime was crashing on macOS only when running wasm code that
trapped. It turns out that our switch to `siglongjmp` from `longjmp`
actually broke macOS! This breakage happens because all subsequent
signals after the first signal are all delivered on the main stack, not
the sigaltstack, even if the sigaltstack is configured. This causes the
Go runtime to crash since it expects to run on the sigaltstack.

The fix in this commit is to actually return from the signal handler to
trigger the kernel's updating of the sigaltstack no longer being in use.
Before we return, however, we configure the register context to return
to to call some custom code which immediately does the unwind we would
otherwise have done. This works around the issue on macOS hopefully
without adding too many portability problems. Ideally this will all go
away as well with bytecodealliance#2632 as well.
@alexcrichton alexcrichton merged commit 707f83d into bytecodealliance:main Feb 23, 2021
@alexcrichton alexcrichton deleted the macos-sigaltstack branch February 23, 2021 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants