Skip to content

Commit

Permalink
pythongh-130396: Fix thread sanitizer crashes on stack overflow tests
Browse files Browse the repository at this point in the history
Thread sanitizer will often crash if a test uses more than half the
stack.
  • Loading branch information
colesbury committed Mar 7, 2025
1 parent b1b4f96 commit 5dadae5
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,12 @@ _Py_InitializeRecursionLimits(PyThreadState *tstate)
if (err == 0) {
uintptr_t base = ((uintptr_t)stack_addr) + guard_size;
_tstate->c_stack_top = base + stack_size;
#ifdef _Py_THREAD_SANITIZER
// Thread sanitizer crashes if we use a bit more than half the stack.
_tstate->c_stack_soft_limit = base + (stack_size / 2);
#else
_tstate->c_stack_soft_limit = base + PYOS_STACK_MARGIN_BYTES * 2;
#endif
_tstate->c_stack_hard_limit = base + PYOS_STACK_MARGIN_BYTES;
assert(_tstate->c_stack_soft_limit < here_addr);
assert(here_addr < _tstate->c_stack_top);
Expand Down

0 comments on commit 5dadae5

Please sign in to comment.