On Mon, Sep 8, 2025 at 3:40 AM John Dallman <jgdatsiem...@gmail.com> wrote:
> > 1. Wrap your calls in a JS try/catch and inspect the exception you > caught > > and then (somehow?) continue with the test suite. (This is what Brooke > > suggested already) > > I have a couple of questions about that: > > When the catch gets called, is it called by the same thread as did the > segmentation violation? > Yes, the try/catch stays in the same thread, it's just up the call stack. This means if you trap on a pthread, you would need a try/catch on the pthread setup, not in your test harness that calls things on the main thread. I don't know how to set this up offhand. Is that thread's stack still intact? Has it been unwound? > > If it is the same thread and the stack is intact, then I should be able to > call the function within the library that does signal handling on other > platforms, and have it do its longjmp()s. If those conditions don't apply, > then things are going to get more difficult. > The WASM code will stop at the point of the trap, and the WASM stack will be unwound back to the call point where the JS catch can grab it. However the *C stack* is not unwound, nor are C++ exception handlers called, because the WASM runtime knows nothing about these (they are creations of the C ABI and not inherent parts of WASM). So you can expect to end up with linear memory in an inconsistent state. You certainly can't recover execution from the next instruction or anything like that. You know an error took place during the call, and that the module is likely inconsistent and unusable now. > > > 2. Install a global `onerror` handler that will catch all exceptions > (much like the > > global signal handler on linux). See > https://nodejs.org/api/process.html#event-uncaughtexception. > > That says it's unsafe to resume, so that probably also applies to the case > above? > Correct. -- brooke -- You received this message because you are subscribed to the Google Groups "emscripten-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/emscripten-discuss/CAFnWYTnaF_KGwFLO8NU97%2B_k2TCgVit9KQjP8wvpq_B778Z9%3Dw%40mail.gmail.com.