Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore POSIX signal handling on MacOS behind a feature flag #3063

Merged
merged 3 commits into from
Jul 12, 2021
Merged

Restore POSIX signal handling on MacOS behind a feature flag #3063

merged 3 commits into from
Jul 12, 2021

Conversation

ulan
Copy link
Contributor

@ulan ulan commented Jul 5, 2021

As described in Issue #3052, the switch to Mach Exception handling
removed unix::StoreExt from the public API of the crate on MacOS.
That is a breaking change and makes it difficult for some
application to upgrade to the current stable Wasmtime.

As a workaround this PR introduces a feature flag called
posix-signals-on-macos that when enabled restores the old behaviour
on MacOS. The flag is disabled by default.

The only non-trivial changes in this PR are in traphandlers/unix.rs that
restore MacOS-related code removed from traphandlers.rs in PR #2723.

As described in Issue #3052, the switch to Mach Exception handling
removed `unix::StoreExt` from the public API of crate on MacOS.
That is a breaking change and makes it difficult for some
application to upgrade to the current stable Wasmtime.

As a workaround this PR introduces a feature flag called
`posix-signals-on-macos` that restores the old behaviour on MacOS.
The flag is disabled by default.
@ulan ulan marked this pull request as ready for review July 5, 2021 16:37
@@ -90,6 +90,7 @@ wasi-crypto = ["wasmtime-wasi-crypto"]
wasi-nn = ["wasmtime-wasi-nn"]
uffd = ["wasmtime/uffd"]
all-arch = ["wasmtime/all-arch"]
posix-signals-on-macos = ["wasmtime/posix-signals-on-macos"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the name. Bikeshedding is welcome. Possible alternatives: macos-signals, macos-posix-signals.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's probably fine to skip this feature on the wasmtime-cli crate since it's mostly the wasmtime embedding crate that wants this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is useful for conditionally enabling tests/all/custom_signal_handler.rs on MacOS and running the tests with cargo test --features=posix-signals-on-macos custom_signal_handler
But indeed it's not needed for production. Should I remove it?

@@ -99,6 +100,42 @@ unsafe extern "C" fn trap_handler(
return true;
}
info.capture_backtrace(pc);
// On macOS this is a bit special, unfortunately. If we were to
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is taken from https://github.com/bytecodealliance/wasmtime/pull/2723/files#diff-560b66f5eac16eef20c78bcaf2c66582dbc6cf76fa1cc72faf6bca7b736cd660L124 after renaming Unwind to wasmtime_longjmp. The comment is also adjusted accordingly.

@@ -155,6 +192,15 @@ unsafe fn get_pc(cx: *mut libc::c_void, _signum: libc::c_int) -> *const u8 {
};
let cx = &*(cx as *const libc::ucontext_t);
(cx.uc_mcontext.psw.addr - trap_offset) as *const u8
} else if #[cfg(all(target_os = "macos", target_arch = "x86_64"))] {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -164,6 +210,41 @@ unsafe fn get_pc(cx: *mut libc::c_void, _signum: libc::c_int) -> *const u8 {
}
}

// This is only used on macOS targets for calling an unwinding shim
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ulan
Copy link
Contributor Author

ulan commented Jul 5, 2021

@alexcrichton: please take a look

@github-actions github-actions bot added the wasmtime:api Related to the API of the `wasmtime` crate itself label Jul 5, 2021
@github-actions
Copy link

github-actions bot commented Jul 5, 2021

Subscribe to Label Action

cc @peterhuene

This issue or pull request has been labeled: "wasmtime:api"

Thus the following users have been cc'd because of the following labels:

  • peterhuene: wasmtime:api

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks! This won't get tested on CI but I think it might be pretty expensive to test on CI, so that's probably ok for now. I don't think that this is changing much to cause many regressions hopefully.

@@ -90,6 +90,7 @@ wasi-crypto = ["wasmtime-wasi-crypto"]
wasi-nn = ["wasmtime-wasi-nn"]
uffd = ["wasmtime/uffd"]
all-arch = ["wasmtime/all-arch"]
posix-signals-on-macos = ["wasmtime/posix-signals-on-macos"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's probably fine to skip this feature on the wasmtime-cli crate since it's mostly the wasmtime embedding crate that wants this.

@ulan
Copy link
Contributor Author

ulan commented Jul 12, 2021

Looks good to me, thanks! This won't get tested on CI but I think it might be pretty expensive to test on CI, so that's probably ok for now. I don't think that this is changing much to cause many regressions hopefully.

Thanks! I agree. We will also keep an eye on it on our side and let you know if it breaks.

@alexcrichton
Copy link
Member

That all sounds reasonable to me, thanks again for the PR!

@alexcrichton alexcrichton merged commit f08491e into bytecodealliance:main Jul 12, 2021
ulan added a commit to dfinity-lab/wasmtime that referenced this pull request Jul 15, 2021
This patch is taken from
bytecodealliance#3079
which in turn a cherry-pick of bytecodealliance#3063 adjusted for v0.26:
bytecodealliance#3063

- Restore POSIX signal handling on MacOS behind a feature flag

As described in Issue bytecodealliance#3052, the switch to Mach Exception handling
removed unix::StoreExt from the public API of crate on MacOS.
That is a breaking change and makes it difficult for some
application to upgrade to the current stable Wasmtime.

As a workaround this PR introduces a feature flag called
posix-signals-on-macos that restores the old behaviour on MacOS.
The flag is disabled by default.

- Fix test guard

- Fix formatting in the test
ulan added a commit to dfinity-lab/wasmtime that referenced this pull request Aug 4, 2021
This patch is taken from bytecodealliance#3063 adjusted for v0.27:

- Restore POSIX signal handling on MacOS behind a feature flag

As described in Issue bytecodealliance#3052, the switch to Mach Exception handling
removed unix::StoreExt from the public API of crate on MacOS.
That is a breaking change and makes it difficult for some
application to upgrade to the current stable Wasmtime.

As a workaround this PR introduces a feature flag called
posix-signals-on-macos that restores the old behaviour on MacOS.
The flag is disabled by default.

- Fix test guard

- Fix formatting in the test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasmtime:api Related to the API of the `wasmtime` crate itself
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants