Skip to content

GH-130397: use __stack_high and __stack_low LLVM WASM attributes #131855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
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: 12 additions & 0 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be size_t, not char right?

extern __attribute__((weak)) unsigned char __stack_low;
#endif

void
_Py_InitializeRecursionLimits(PyThreadState *tstate)
Expand Down Expand Up @@ -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);
Expand Down
Loading