Skip to content

Commit 446cca2

Browse files
authored
Remove preamble function Module['applyStackValues']() (#10042)
* Remove preamble function Module['applyStackValues']() that was introduced in #9569. That is same as JS library function establishStackSpaceInJsModule(). * Fix establishStackSpace() for wasm backend
1 parent 8732c92 commit 446cca2

File tree

5 files changed

+20
-42
lines changed

5 files changed

+20
-42
lines changed

emcc.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,17 +1448,17 @@ def is_supported_link_flag(f):
14481448
# To ensure allocated thread stacks are aligned:
14491449
shared.Settings.EXPORTED_FUNCTIONS += ['_memalign']
14501450

1451+
# pthread stack setup:
1452+
shared.Settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$establishStackSpaceInJsModule']
1453+
shared.Settings.EXPORTED_FUNCTIONS += ['establishStackSpaceInJsModule']
1454+
14511455
if shared.Settings.MODULARIZE:
14521456
# MODULARIZE+USE_PTHREADS mode requires extra exports out to Module so that worker.js
14531457
# can access them:
14541458

14551459
# general threading variables:
14561460
shared.Settings.EXPORTED_RUNTIME_METHODS += ['PThread', 'ExitStatus']
14571461

1458-
# pthread stack setup:
1459-
shared.Settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$establishStackSpaceInJsModule']
1460-
shared.Settings.EXPORTED_FUNCTIONS += ['establishStackSpaceInJsModule']
1461-
14621462
# stack check:
14631463
if shared.Settings.STACK_OVERFLOW_CHECK:
14641464
shared.Settings.EXPORTED_RUNTIME_METHODS += ['writeStackCookie', 'checkStackCookie']

src/library_pthread.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,19 +1329,18 @@ var LibraryPThread = {
13291329
return func.apply(null, _emscripten_receive_on_main_thread_js_callArgs);
13301330
},
13311331

1332-
#if MODULARIZE
1333-
$establishStackSpaceInJsModule: function(stackBase, stackMax) {
1334-
STACK_BASE = stackBase;
1335-
#if WASM_BACKEND
1336-
// The stack grows downwards
1337-
STACKTOP = stackMax;
1338-
STACK_MAX = stackBase;
1339-
#else
1340-
STACKTOP = stackBase;
1332+
$establishStackSpaceInJsModule: function(stackTop, stackMax) {
1333+
STACK_BASE = STACKTOP = stackTop;
13411334
STACK_MAX = stackMax;
1335+
#if SAFE_STACK
1336+
___set_stack_limit(STACK_MAX);
13421337
#endif
1343-
},
1338+
#if STACK_OVERFLOW_CHECK
1339+
writeStackCookie();
13441340
#endif
1341+
// Call inside asm.js/wasm module to set up the stack frame for this pthread in asm.js/wasm module scope
1342+
establishStackSpace(stackTop, stackMax);
1343+
},
13451344
};
13461345

13471346
autoAddDeps(LibraryPThread, '$PThread');

src/preamble.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -376,20 +376,10 @@ if (ENVIRONMENT_IS_PTHREAD) {
376376
// At the 'load' stage of Worker startup, we are just loading this script
377377
// but not ready to run yet. At 'run' we receive proper values for the stack
378378
// etc. and can launch a pthread. Set some fake values there meanwhile to
379-
// catch bugs, then set the real values in applyStackValues later.
379+
// catch bugs, then set the real values in establishStackSpaceInJsModule later.
380380
#if ASSERTIONS || SAFE_STACK
381381
STACK_MAX = STACKTOP = STACK_MAX = 0x7FFFFFFF;
382382
#endif
383-
384-
Module['applyStackValues'] = function(stackBase, stackTop, stackMax) {
385-
STACK_BASE = stackBase;
386-
STACKTOP = stackTop;
387-
STACK_MAX = stackMax;
388-
#if SAFE_STACK
389-
Module['___set_stack_limit'](STACK_MAX);
390-
#endif
391-
};
392-
393383
// TODO DYNAMIC_BASE = Module['DYNAMIC_BASE'];
394384
// TODO DYNAMICTOP_PTR = Module['DYNAMICTOP_PTR'];
395385
// TODO tempDoublePtr = Module['tempDoublePtr'];

src/support.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,10 +1007,10 @@ GLOBAL_BASE = alignMemory(GLOBAL_BASE, {{{ MAX_GLOBAL_ALIGN || 1 }}});
10071007
#endif
10081008

10091009
#if WASM_BACKEND && USE_PTHREADS
1010-
// The wasm backend path does not have a way to set the stack max, so we can
1011-
// just implement this function in a trivial way
1012-
function establishStackSpace(base, max) {
1013-
stackRestore(max);
1010+
// The wasm backend path does not have a way to set the stack max, so ignore
1011+
// the stack max parameter, this function only resets the stack base.
1012+
function establishStackSpace(base/*, max*/) {
1013+
stackRestore(base);
10141014
}
10151015

10161016
// JS library code refers to Atomics in the manner used from asm.js, provide

src/worker.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -170,34 +170,23 @@ this.onmessage = function(e) {
170170
var max = e.data.stackBase + e.data.stackSize;
171171
var top = e.data.stackBase;
172172
#endif
173-
Module['applyStackValues'](top, top, max);
174173
#if ASSERTIONS
175174
assert(threadInfoStruct);
176175
assert(selfThreadId);
177176
assert(parentThreadId);
178177
assert(top != 0);
178+
assert(e.data.stackSize > 0);
179179
#if WASM_BACKEND
180-
assert(max === e.data.stackBase);
181180
assert(top > max);
182181
#else
183-
assert(max > e.data.stackBase);
184182
assert(max > top);
185-
assert(e.data.stackBase === top);
186183
#endif
187184
#endif
188-
// Call inside asm.js/wasm module to set up the stack frame for this pthread in asm.js/wasm module scope
189-
Module['establishStackSpace'](e.data.stackBase, e.data.stackBase + e.data.stackSize);
190-
#if MODULARIZE
191185
// Also call inside JS module to set up the stack frame for this pthread in JS module scope
192-
Module['establishStackSpaceInJsModule'](e.data.stackBase, e.data.stackBase + e.data.stackSize);
193-
#endif
186+
Module['establishStackSpaceInJsModule'](top, max);
194187
#if WASM_BACKEND
195188
Module['_emscripten_tls_init']();
196189
#endif
197-
#if STACK_OVERFLOW_CHECK
198-
Module['writeStackCookie']();
199-
#endif
200-
201190
PThread.receiveObjectTransfer(e.data);
202191
PThread.setThreadStatus(Module['_pthread_self'](), 1/*EM_THREAD_STATUS_RUNNING*/);
203192

0 commit comments

Comments
 (0)