-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Implement default signal handlers #20257
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
Conversation
@sbc100 Are there any tests from POSIX test suite we could reuse here or do I need to implement my own? |
Except for the pthreads tests we have been writing out own. (we also write our own pthreads tests in addition to the posttest suite ones). |
I think you can/should just extend the existing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! lgtm with test
I don't think that will work since it's being executed as a core test and the program is expected to finish. Whereas here we want kinda the opposite - to test that it exits abnormally. |
OTOH... it does verify output, so maybe. |
You can also death tests using |
Yeah it just gets a bit more complicated if I want to test several signals (one for abort, one for terminate behaviour)... I could do that via argument parsing but I think I'd better add a separate test instead. |
Heh looks like it caught a test that assumed SIGUSR1 will do nothing. I'll change it to SIGCHLD which is ignored per spec. |
Just realised that this is not fully correct approach. It should instead implement WASI's I think I'll just wrap it into |
Hm |
Oh I see, looks like libc is not built separately for standalone Wasm as it expects that WASI will be implemented only in JS? I guess I can move this implementation into JS, but seems unfortunate... |
Why don't you ignore the standalone wasm stuff for now and just land this without that support. We can try to move to an external proc_raise as a followup maybe? |
I guess I could do that. It's just that when I noticed that CI error I decided to test my tests in standalone Wasm mode as well and it was a rabbit hole. That said, I'm almost done - but now noticed that Wasmtime doesn't support |
We use an old/pinned version of wasmtime in CI .. it might already be fixed. That being said, I'd prefer to land the smaller/simpler version of this change first, is possible. |
No, I already checked Github.
I could revert the JS change I guess... It just seemed better to do this the right way from the start rather than have to rewrite later. The only complicated addition is that I also added all the signal codes to generated struct info. I needed this for the |
Ah interesting... apparently they want to remove Or should we keep it? What do you think? |
One benefit of the new implementation is that it uses |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. lgtm!
I wonder if there is an open bug for wasmtime? Seems odd they wouldn't support it.
Run |
See the link above - apparently they didn't implement it because it didn't make sense and they want to remove it from WASI at some point in the future instead. But I don't get it - for this scenario (invoking default handler) it seems to make perfect sense IMO.
Oh, weird that it worked locally but fails on CI. Will try. |
I don't see |
Right, but you might as well implement it in wasm though, right? I don't see any advantage to having the host do it.. is there one?
|
Sorry |
In this particular case I wanted to do it in the host because Wasmtime prohibits from exiting with exit code >127. And signals are supposed to exit with I thought, okay, then I'll use proper WASI method for that, I assume Turned out to be waste of time, one way or another if we want to support Wasmtime, we'll have to change exit code just for them. |
But yeah, to your general question, if Wasmtime didn't prohibit such exit codes, I think implementing in Wasm would be fully analogous. |
558785d
to
8fba77e
Compare
I reverted to non-JS implementation to keep things simple; I'll submit the |
Awesome! Thanks |
This implements best-effort attempt to implement default signal handlers as per https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html: - Terminate action is mapped to `_Exit` aka `wasi_proc_exit` - variant of exit that doesn't run `atexit` handlers. - Abort action (terminate with core dump) is mapped to `__builtin_trap` aka Wasm `unreachable` instruction. - Process pause/continue actions are ignored as it's unclear what that would do in Wasm (maybe use Asyncify in the future?). Fixes #20254.
SIGTRAP is not available on Windows.
b6201e7
to
89166d1
Compare
Deleted during rebase?
Sigh, anotyer failing test. This was supposed to be a trivial PR 😂 |
The |
More unrelated tests failing. @sbc100 can you please force-merge it for me? |
Yup.. I have fixed for the current failures: #20263 |
Fix in flight here: #20272 |
Thanks for the quick fix! Any idea how this passed the initial chromium roll, btw? That's really mysterious... it's like chromium CI ran the wrong checkout for the tests. cc @dschuff |
Its very odd that the try job succeeded yes. Try job only runs 907 tests but the normal runner runs 909 tests in core0. Very odd |
The trybot does seem to sync the correct emscripten rev:
aab180a is |
This implements best-effort attempt to implement default signal handlers as per https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html:
_Exit
akawasi_proc_exit
- variant of exit that doesn't runatexit
handlers. Exit code is set to128 + sig
like it is on other platforms.__builtin_trap
aka Wasmunreachable
instruction.Fixes #20254.