From 059a2db494407c7654b9dd34005ba5c7a3ba93a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20La=C3=ADns?= Date: Fri, 28 Mar 2025 16:46:04 +0000 Subject: [PATCH] GH-130397: use __stack_high and __stack_low LLVM WASM attributes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filipe LaĆ­ns --- Python/ceval.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Python/ceval.c b/Python/ceval.c index 363f263ad2a083..422032151096b9 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -429,6 +429,10 @@ int pthread_attr_destroy(pthread_attr_t *a) #endif +#if defined(__wasi__) & _Py__has_attribute(weak) +extern __attribute__((weak)) unsigned char __stack_high; +extern __attribute__((weak)) unsigned char __stack_low; +#endif void _Py_InitializeRecursionLimits(PyThreadState *tstate) @@ -469,6 +473,14 @@ _Py_InitializeRecursionLimits(PyThreadState *tstate) return; } # endif +#if defined(__wasi__) & _Py__has_attribute(weak) + if (__stack_high) { + _tstate->c_stack_top = &__stack_high; + _tstate->c_stack_soft_limit = &__stack_low + PYOS_STACK_MARGIN_BYTES * 2; + _tstate->c_stack_hard_limit = &__stack_low + PYOS_STACK_MARGIN_BYTES; + return; + } +#endif _tstate->c_stack_top = _Py_SIZE_ROUND_UP(here_addr, 4096); _tstate->c_stack_soft_limit = _tstate->c_stack_top - Py_C_STACK_SIZE; _tstate->c_stack_hard_limit = _tstate->c_stack_top - (Py_C_STACK_SIZE + PYOS_STACK_MARGIN_BYTES);