Skip to content

Commit 5dadae5

Browse files
committed
gh-130396: Fix thread sanitizer crashes on stack overflow tests
Thread sanitizer will often crash if a test uses more than half the stack.
1 parent b1b4f96 commit 5dadae5

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Python/ceval.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,12 @@ _Py_InitializeRecursionLimits(PyThreadState *tstate)
373373
if (err == 0) {
374374
uintptr_t base = ((uintptr_t)stack_addr) + guard_size;
375375
_tstate->c_stack_top = base + stack_size;
376+
#ifdef _Py_THREAD_SANITIZER
377+
// Thread sanitizer crashes if we use a bit more than half the stack.
378+
_tstate->c_stack_soft_limit = base + (stack_size / 2);
379+
#else
376380
_tstate->c_stack_soft_limit = base + PYOS_STACK_MARGIN_BYTES * 2;
381+
#endif
377382
_tstate->c_stack_hard_limit = base + PYOS_STACK_MARGIN_BYTES;
378383
assert(_tstate->c_stack_soft_limit < here_addr);
379384
assert(here_addr < _tstate->c_stack_top);

0 commit comments

Comments
 (0)