-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
WebAssembly OOB Signal Handlers + Node #14927
Comments
@bnoordhuis @trevnorris @indutny @ofrobots @jasnell adding a few people who might know, or who might know someone who might know. |
Some of the comments here and following are also relevant. The trap handler feature requires some more support from the array buffer allocator. |
I believe cc @nodejs/v8 just in case. |
I looked at the trap handler code earlier this week and I believe the idea is to catch SIGSEGV on out-of-bounds loads and stores? Node.js core itself doesn't touch that signal handler but there is a popular module called segfault-handler that does what its name suggests. Out of curiosity, wouldn't you also need to intercept SIGBUS for unaligned loads and stores? |
Correct, we catch SIGSEGV to detect out of bounds loads and stores in WebAssembly. It's up to the embedder to opt in because chaining signal handlers can be tricky to get right. We provide a default signal handler that you can install using The segfault-handler package should be able to work with us if they are willing to call So far we are only enabling this feature on Linux x86-64, so SIGSEGV is all we need there. |
Oh, given that there is an existing API for this it shouldn't be a big deal to just call it from Node.js core. |
Should we reach out to the maintainers of segfault-handler? |
It doesn't seem like there is anything left to discuss so I'll go ahead and close this out. Reopen if that is mistaken. |
It's been a while that this issue is closed, but I'm just curious if node (v12.0.0-pre) is benefitting from the trap handling feature in v8. I am currently experimenting with WebAssembly load/store while enabling --print-wasm-code I can see the bound check happening in the generated x86.
While in chromium (trap handling enabled), --print-wasm-code reports the following:
Also while debugging Finally, browsing the segfault-handler library, I couldn't find the code which integrates the v8 feature API. Question: Is it possible to enable trap handling in Node? If so, is it possible to post the PR link? Thank you for your time -- Amir FYI, here's the dummy code executed in
|
we could enable this but there is a serious issue of someone overriding the SIGSEGV handler. although i wouldn't normally recommend this, it might make sense to just make your own native module to enable this. #include <node.h>
#include <v8.h>
void Init(v8::Local<v8::Object> exports) {
v8::V8::EnableWebAssemblyTrapHandler(true);
}
NODE_MODULE(the_module, Init) just node-gyp this up and require() it and you should be good to go. |
@devsnek thank you for your answer and example. I tested your code and it works :) |
I guess we could make that the default and require addons that provide segfault handlers to make the necessary calls into V8? |
@addaleax I'm just concerned about what kind of cascading issues could happen from wasm not properly reporting oob. there is a reason it's a trap after all. |
IMO we should optimize for the common/expected case rather than the edge cases. We shouldn't make everyone's code run slow just because there may be the possiblity that someone is overriding the SIGSEGV signal handler. There is a lot of precedent here. For example, I can link a JNI library into my JVM application that overrides the signal handers that the JIT depends on. All sorts of cascading failures may occur as a result. The expected way users are supposed to use signal handlers in native code is via the officially supported way to chain signal handlers. IMO, we should offer a chaining signal handler API in node, and switch the default to use trap handlers for wasm code – and not necessarily in that order. |
This uses SIGSEGV handlers to catch WASM out of bound (OOB) memory accesses instead of inserting OOB checks inline, resulting in a 25%-30% speed increase. Note that installing a custom SIGSEGV handler will break this, resulting in potentially scary behaviour. Refs: nodejs#14927 PR-URL: nodejs#27246 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This uses SIGSEGV handlers to catch WASM out of bound (OOB) memory accesses instead of inserting OOB checks inline, resulting in a 25%-30% speed increase. Note that installing a custom SIGSEGV handler will break this, resulting in potentially scary behaviour. Refs: nodejs#14927 PR-URL: nodejs#27246 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
We're rolling out use of signal handlers for WebAssembly Out-of-Bounds checks in V8 6.2.
We've intentionally left the feature off by default in V8, and will be turning it on Chrome side via features.
The reason is that embedders (for instance node.js), may have their own signal handlers which may interact poorly.
The feature is a big win for WebAssembly performance on 64-bit systems 25%-30% speed-up.
To work in node.js, we need someone knowledgeable about the signal handlers in the system to help us.
If node has a signal handler of its own, it's not too much harder than adding:
--wrap-trap-handler
And then be sure to use the implementation we we provide with V8:
v8::V8::RegisterDefaultSignalHandler()
(Eric CC'ed can help with the particulars)
If there's already a handler (or if some modules have them?), things might be more complex, but not too bad.
Eric Holk is a good contact for this feature on the WebAssembly side.
The text was updated successfully, but these errors were encountered: