Skip to content

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

Merged
alexcrichton merged 3 commits intobytecodealliance:mainfrom
ulan:posix-signals-on-macos
Jul 12, 2021
Merged

Restore POSIX signal handling on MacOS behind a feature flag#3063
alexcrichton merged 3 commits intobytecodealliance:mainfrom
ulan:posix-signals-on-macos

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
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?

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.

};
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.

}
}

// 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

Details 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.

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