Skip to content

Commit

Permalink
Fix STACK_OVERFLOW_CHECK + WASM_WORKERS
Browse files Browse the repository at this point in the history
We we not calling `writeStackCookie()` in the right place which means
that `checkStackCookie()` would always fail in wasm workers.
  • Loading branch information
sbc100 committed Oct 16, 2024
1 parent 814ec05 commit 936667d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/library_wasm_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ addToLibrary({
___set_stack_limits(_emscripten_stack_get_base(), _emscripten_stack_get_end());
#endif

#if STACK_OVERFLOW_CHECK
// Write the stack cookie last, after we have set up the proper bounds and
// current position of the stack.
writeStackCookie();
#endif

#if AUDIO_WORKLET
// Audio Worklets do not have postMessage()ing capabilities.
if (typeof AudioWorkletGlobalScope === 'undefined') {
Expand Down
11 changes: 4 additions & 7 deletions src/postamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,6 @@ function run() {
return;
}
#if STACK_OVERFLOW_CHECK
#if PTHREADS
if (!ENVIRONMENT_IS_PTHREAD)
#endif
stackCheckInit();
#endif
#if WASM_WORKERS
if (ENVIRONMENT_IS_WASM_WORKER) {
#if MODULARIZE
Expand All @@ -192,6 +185,10 @@ function run() {
}
#endif
#if STACK_OVERFLOW_CHECK
stackCheckInit();
#endif
if (!calledPrerun) {
calledPrerun = 1;
preRun();
Expand Down
1 change: 1 addition & 0 deletions test/wasm_worker/hello_wasm_worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

void run_in_worker() {
emscripten_console_log("Hello from wasm worker!\n");
EM_ASM(checkStackCookie());
#ifdef REPORT_RESULT
REPORT_RESULT(0);
#endif
Expand Down

0 comments on commit 936667d

Please sign in to comment.