On Wed, Sep 3, 2025 at 6:09 AM John Dallman <jgdatsiem...@gmail.com> wrote:

> I'm aware that WASI doesn't support traditional signals
> <https://github.com/WebAssembly/WASI/issues/166>. At present, when I
> intentionally set off an access violation, I get "RuntimeError: memory
> access out of bounds" and a traceback as Node.js exits.
>
> Is there a way to catch these errors and prevent Node.js exiting? Ideally,
> I'd be able to notify the test harness in some way that this had happened.
> If this involves JavaScript, please explain slowly and gently: I'm from the
> C world and new to web applications.
>

These can be caught like a standard JavaScript exception by the surrounding
test harness JS, something like:

try {
  Module.run_my_c_code();
} catch (e) {
  // Probably out of bounds access, or divide by zero etc
  console.log("Error while running run_my_c_code: " + e);
}

The stack trace attached to the exception may not be very useful, but this
gives your test harness a chance to process the failure at least. :D

Note that this will only catch WebAssembly accesses outside of linear
memory -- a NULL dereference, read or write, will *not* trigger a runtime
error -- but any actually out-of-bounds accesses, or other operations like
divide by zero that trap, can be caught this way even on a fully optimized
production build.


You might also look into the SAFE_HEAP build option in emscripten, which
runs all memory accesses through a double-check for out-of-bounds or NULL
dereference and logs it. Check emscripten's src/settings.js for comments
documenting this and other build-time options.

-- 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/CAFnWYTm-3FbJgrnN7CEWX4Fh0e9%3Dc1y7a99B%2BcdEa9zQwpD4yA%40mail.gmail.com.

Reply via email to