Skip to content

Commit 059a2db

Browse files
committed
GH-130397: use __stack_high and __stack_low LLVM WASM attributes
Signed-off-by: Filipe Laíns <lains@riseup.net>
1 parent d260631 commit 059a2db

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Python/ceval.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,10 @@ int pthread_attr_destroy(pthread_attr_t *a)
429429

430430
#endif
431431

432+
#if defined(__wasi__) & _Py__has_attribute(weak)
433+
extern __attribute__((weak)) unsigned char __stack_high;
434+
extern __attribute__((weak)) unsigned char __stack_low;
435+
#endif
432436

433437
void
434438
_Py_InitializeRecursionLimits(PyThreadState *tstate)
@@ -469,6 +473,14 @@ _Py_InitializeRecursionLimits(PyThreadState *tstate)
469473
return;
470474
}
471475
# endif
476+
#if defined(__wasi__) & _Py__has_attribute(weak)
477+
if (__stack_high) {
478+
_tstate->c_stack_top = &__stack_high;
479+
_tstate->c_stack_soft_limit = &__stack_low + PYOS_STACK_MARGIN_BYTES * 2;
480+
_tstate->c_stack_hard_limit = &__stack_low + PYOS_STACK_MARGIN_BYTES;
481+
return;
482+
}
483+
#endif
472484
_tstate->c_stack_top = _Py_SIZE_ROUND_UP(here_addr, 4096);
473485
_tstate->c_stack_soft_limit = _tstate->c_stack_top - Py_C_STACK_SIZE;
474486
_tstate->c_stack_hard_limit = _tstate->c_stack_top - (Py_C_STACK_SIZE + PYOS_STACK_MARGIN_BYTES);

0 commit comments

Comments
 (0)