File tree 4 files changed +27
-6
lines changed
4 files changed +27
-6
lines changed Original file line number Diff line number Diff line change @@ -588,6 +588,11 @@ var LibraryDylink = {
588
588
}
589
589
#if STACK_OVERFLOW_CHECK >= 2
590
590
if ( moduleExports [ '__set_stack_limits' ] ) {
591
+ #if USE_PTHREADS
592
+ // When we are on an uninitialized pthread we delay calling
593
+ // __set_stack_limits until $setDylinkStackLimits.
594
+ if ( ! ENVIRONMENT_IS_PTHREAD || runtimeInitialized )
595
+ #endif
591
596
moduleExports [ '__set_stack_limits' ] ( _emscripten_stack_get_base ( ) , _emscripten_stack_get_end ( ) )
592
597
}
593
598
#endif
@@ -646,7 +651,12 @@ var LibraryDylink = {
646
651
return loadModule ( ) ;
647
652
} ,
648
653
649
- #if STACK_OVERFLOW_CHECK >= 2
654
+ #if STACK_OVERFLOW_CHECK >= 2 && USE_PTHREADS
655
+ // With USE_PTHREADS we load libraries before we are running a pthread and
656
+ // therefore before we have a stack. Instead we delay calling
657
+ // `__set_stack_limits` until we start running a thread. We also need to call
658
+ // this again for each new thread that the runs on a worker (since each thread
659
+ // has its own separate stack region).
650
660
$setDylinkStackLimits: function ( stackTop , stackMax ) {
651
661
for ( var name in LDSO . loadedLibsByName ) {
652
662
#if DYLINK_DEBUG
Original file line number Diff line number Diff line change @@ -214,12 +214,16 @@ function stackCheckInit() {
214
214
// This is normally called automatically during __wasm_call_ctors but need to
215
215
// get these values before even running any of the ctors so we call it redundantly
216
216
// here.
217
- // TODO(sbc): Move writeStackCookie to native to to avoid this.
217
+ #if ASSERTIONS && USE_PTHREADS
218
+ // See $establishStackSpace for the equivelent code that runs on a thread
219
+ assert ( ! ENVIRONMENT_IS_PTHREAD ) ;
220
+ #endif
218
221
#if RELOCATABLE
219
222
_emscripten_stack_set_limits ( { { { STACK_BASE } } } , { { { STACK_MAX } } } ) ;
220
223
#else
221
224
_emscripten_stack_init ( ) ;
222
225
#endif
226
+ // TODO(sbc): Move writeStackCookie to native to to avoid this.
223
227
writeStackCookie ( ) ;
224
228
}
225
229
#endif
@@ -240,7 +244,10 @@ function run(args) {
240
244
}
241
245
242
246
#if STACK_OVERFLOW_CHECK
243
- stackCheckInit ( ) ;
247
+ #if USE_PTHREADS
248
+ if ( ! ENVIRONMENT_IS_PTHREAD )
249
+ #endif
250
+ stackCheckInit ( ) ;
244
251
#endif
245
252
246
253
#if RELOCATABLE
Original file line number Diff line number Diff line change @@ -371,9 +371,6 @@ function preRun() {
371
371
}
372
372
373
373
function initRuntime ( ) {
374
- #if STACK_OVERFLOW_CHECK
375
- checkStackCookie ( ) ;
376
- #endif
377
374
#if ASSERTIONS
378
375
assert ( ! runtimeInitialized ) ;
379
376
#endif
@@ -387,6 +384,10 @@ function initRuntime() {
387
384
if ( ENVIRONMENT_IS_PTHREAD ) return ;
388
385
#endif
389
386
387
+ #if STACK_OVERFLOW_CHECK
388
+ checkStackCookie ( ) ;
389
+ #endif
390
+
390
391
#if STACK_OVERFLOW_CHECK >= 2
391
392
#if RUNTIME_LOGGING
392
393
err ( '__set_stack_limits: ' + _emscripten_stack_get_base ( ) + ', ' + _emscripten_stack_get_end ( ) ) ;
Original file line number Diff line number Diff line change 8
8
// Initializes the stack cookie. Called at the startup of main and at the startup of each thread in pthreads mode.
9
9
function writeStackCookie ( ) {
10
10
var max = _emscripten_stack_get_end ( ) ;
11
+ #if RUNTIME_DEBUG
12
+ err ( 'writeStackCookie: ' + max . toString ( 16 ) ) ;
13
+ #endif
11
14
#if ASSERTIONS
12
15
assert ( ( max & 3 ) == 0 ) ;
13
16
#endif
You can’t perform that action at this time.
0 commit comments