Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/library_dylink.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,11 @@ var LibraryDylink = {
}
#if STACK_OVERFLOW_CHECK >= 2
if (moduleExports['__set_stack_limits']) {
#if USE_PTHREADS
// When we are on an uninitialized pthread we delay calling
// __set_stack_limits until $setDylinkStackLimits.
if (!ENVIRONMENT_IS_PTHREAD || runtimeInitialized)
#endif
moduleExports['__set_stack_limits'](_emscripten_stack_get_base(), _emscripten_stack_get_end())
}
#endif
Expand Down Expand Up @@ -646,7 +651,12 @@ var LibraryDylink = {
return loadModule();
},

#if STACK_OVERFLOW_CHECK >= 2
#if STACK_OVERFLOW_CHECK >= 2 && USE_PTHREADS
// With USE_PTHREADS we load libraries before we are running a pthread and
// therefore before we have a stack. Instead we delay calling
// `__set_stack_limits` until we start running a thread. We also need to call
// this again for each new thread that the runs on a worker (since each thread
// has is own sperate stack region).
$setDylinkStackLimits: function(stackTop, stackMax) {
for (var name in LDSO.loadedLibsByName) {
#if DYLINK_DEBUG
Expand Down
11 changes: 9 additions & 2 deletions src/postamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,16 @@ function stackCheckInit() {
// This is normally called automatically during __wasm_call_ctors but need to
// get these values before even running any of the ctors so we call it redundantly
// here.
// TODO(sbc): Move writeStackCookie to native to to avoid this.
#if ASSERTIONS && USE_PTHREADS
// See $establishStackSpace for the equivelent code that runs on a thread
assert(!ENVIRONMENT_IS_PTHREAD);
#endif
#if RELOCATABLE
_emscripten_stack_set_limits({{{ STACK_BASE }}} , {{{ STACK_MAX }}});
#else
_emscripten_stack_init();
#endif
// TODO(sbc): Move writeStackCookie to native to to avoid this.
writeStackCookie();
}
#endif
Expand All @@ -240,7 +244,10 @@ function run(args) {
}

#if STACK_OVERFLOW_CHECK
stackCheckInit();
#if USE_PTHREADS
if (!ENVIRONMENT_IS_PTHREAD)
#endif
stackCheckInit();
#endif

#if RELOCATABLE
Expand Down
7 changes: 4 additions & 3 deletions src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,6 @@ function preRun() {
}

function initRuntime() {
#if STACK_OVERFLOW_CHECK
checkStackCookie();
#endif
#if ASSERTIONS
assert(!runtimeInitialized);
#endif
Expand All @@ -391,6 +388,10 @@ function initRuntime() {
if (ENVIRONMENT_IS_PTHREAD) return;
#endif

#if STACK_OVERFLOW_CHECK
checkStackCookie();
#endif

#if STACK_OVERFLOW_CHECK >= 2
#if RUNTIME_LOGGING
err('__set_stack_limits: ' + _emscripten_stack_get_base() + ', ' + _emscripten_stack_get_end());
Expand Down
3 changes: 3 additions & 0 deletions src/runtime_stack_check.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
// Initializes the stack cookie. Called at the startup of main and at the startup of each thread in pthreads mode.
function writeStackCookie() {
var max = _emscripten_stack_get_end();
#if RUNTIME_DEBUG
err('writeStackCookie: ' + max.toString(16));
#endif
#if ASSERTIONS
assert((max & 3) == 0);
#endif
Expand Down