Skip to content
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

wasm2c: use signal handler to detect stack exhaustion #1875

Merged

Conversation

keithw
Copy link
Member

@keithw keithw commented Mar 31, 2022

Use the signal-handler method to detect and recover from stack exhaustion, in addition to OOB accesses. This eliminates the global wasm_rt_call_stack_depth and the need to increment/decrement it on function entries and exits. Eliminating this global variable is helpful for module instancing and for running parallel invocations in a thread-safe manner.

(The catch is that MacOS doesn't seem to make it easy to distinguish OOB vs. exhaustion, so these trap codes have to be merged on MacOS and perhaps other BSDs. On Linux, it's possible to tell them apart based on the si_code of the SIGSEGV.)

keithw added 2 commits March 30, 2022 22:39
(Linux distinguishes these as SEGV_ACCERR vs. SEGV_MAPERR in the
si_code, but MacOS seems to deliver a SEGV_ACCERR for both.)
@keithw keithw requested a review from sbc100 March 31, 2022 05:53
…constant

On glibc 2.34+ with the _GNU_SOURCE macro, SIGSTKSZ is no longer a constant
(https://sourceware.org/pipermail/libc-alpha/2021-August/129718.html).

Convert the "alt stack" to a runtime-allocated array, and add wasm_rt_init()
and wasm_rt_free() endpoints to wasm-rt.h that the embedder must call to
set up and clean up the runtime state. (If the embedder doesn't call these,
OOB and exhaustion will result in an uncaught segfault.)
Copy link
Member

@binji binji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm w/ a few comments

@keithw keithw merged commit 26ce1ca into WebAssembly:main Apr 5, 2022
@keithw keithw deleted the signal-handler-for-stack-exhaustion branch April 5, 2022 04:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants