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 runtime: refactor handling of alternate stack (NFC) #2338

Merged
merged 3 commits into from
Nov 28, 2023

Conversation

keithw
Copy link
Member

@keithw keithw commented Nov 28, 2023

Split out from #2332.

This makes the g_alt_stack variable thread-local and splits out the internal routines that handle allocation/installation. This will make it a smaller change to add the per-thread initialization API in #2332.

@keithw keithw requested a review from sbc100 November 28, 2023 16:02
@keithw keithw force-pushed the w2c-rt-altstack branch 2 times, most recently from 13b51d2 to 1744164 Compare November 28, 2023 16:25
stderr,
"wasm-rt error: tried to re-allocate thread-local alternate stack\n");
abort();
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure what the convention is within this file, but would it make sense to write these 6 lines as assert(!g_alt_stack && "wasm-rt error: tried to re-allocate thread-local alternate stack")?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, done.

#ifndef NDEBUG
fprintf(stderr,
"wasm-rt warning: alternate stack was modified unexpectedly\n");
#endif
Copy link
Member

Choose a reason for hiding this comment

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

And this could just be assert(false && ..?

Copy link
Member Author

@keithw keithw Nov 28, 2023

Choose a reason for hiding this comment

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

I'd rather not make this one abort() on failure, since it seems plausible the application would install its own altstack at some point, and that shouldn't be (in my view) an abort-style fatal error...

wasm2c/wasm-rt-impl.c Outdated Show resolved Hide resolved
wasm2c/wasm-rt-impl.c Show resolved Hide resolved
The runtime installs an alternate stack to handle SIGSEGV
from stack exhaustion. Make this variable thread-local
and refactor implementation that touches it.
Copy link
Member

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

lgtm % final nit/comment

sa.sa_flags = SA_SIGINFO | SA_ONSTACK;
#endif
Copy link
Member

Choose a reason for hiding this comment

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

How about:

sa.sa_flags = SA_SIGINFO;
#if !WASM_RT_USE_STACK_DEPTH_COUNT
sa.sa_flags |=  SA_ONSTACK;
#endif

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, done.

@keithw keithw enabled auto-merge (squash) November 28, 2023 19:04
@keithw keithw merged commit 9944d92 into main Nov 28, 2023
@keithw keithw deleted the w2c-rt-altstack branch November 28, 2023 19:13
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