Skip to content

Commit 0054150

Browse files
authored
Fix STACK_OVERFLOW_CHECK + WASM_WORKERS (emscripten-core#22756)
We we not calling `writeStackCookie()` in the right place which means that `checkStackCookie()` would always fail in wasm workers. Required for emscripten-core#22721
1 parent 814ec05 commit 0054150

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/library_wasm_worker.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ addToLibrary({
110110
___set_stack_limits(_emscripten_stack_get_base(), _emscripten_stack_get_end());
111111
#endif
112112

113+
#if STACK_OVERFLOW_CHECK
114+
// Write the stack cookie last, after we have set up the proper bounds and
115+
// current position of the stack.
116+
writeStackCookie();
117+
#endif
118+
113119
#if AUDIO_WORKLET
114120
// Audio Worklets do not have postMessage()ing capabilities.
115121
if (typeof AudioWorkletGlobalScope === 'undefined') {

src/postamble.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,6 @@ function run() {
162162
return;
163163
}
164164

165-
#if STACK_OVERFLOW_CHECK
166-
#if PTHREADS
167-
if (!ENVIRONMENT_IS_PTHREAD)
168-
#endif
169-
stackCheckInit();
170-
#endif
171-
172165
#if WASM_WORKERS
173166
if (ENVIRONMENT_IS_WASM_WORKER) {
174167
#if MODULARIZE
@@ -192,6 +185,10 @@ function run() {
192185
}
193186
#endif
194187

188+
#if STACK_OVERFLOW_CHECK
189+
stackCheckInit();
190+
#endif
191+
195192
if (!calledPrerun) {
196193
calledPrerun = 1;
197194
preRun();

test/wasm_worker/hello_wasm_worker.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
void run_in_worker() {
99
emscripten_console_log("Hello from wasm worker!\n");
10+
EM_ASM(typeof checkStackCookie == 'function' && checkStackCookie());
1011
#ifdef REPORT_RESULT
1112
REPORT_RESULT(0);
1213
#endif

0 commit comments

Comments
 (0)