Skip to content

Commit 4162bc1

Browse files
authored
gh-130396: Fix thread sanitizer crashes on stack overflow tests (gh-130966)
Thread sanitizer will often crash if a test uses more than half the stack.
1 parent 1908115 commit 4162bc1

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Python/ceval.c

+5
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,12 @@ _Py_InitializeRecursionLimits(PyThreadState *tstate)
392392
if (err == 0) {
393393
uintptr_t base = ((uintptr_t)stack_addr) + guard_size;
394394
_tstate->c_stack_top = base + stack_size;
395+
#ifdef _Py_THREAD_SANITIZER
396+
// Thread sanitizer crashes if we use a bit more than half the stack.
397+
_tstate->c_stack_soft_limit = base + (stack_size / 2);
398+
#else
395399
_tstate->c_stack_soft_limit = base + PYOS_STACK_MARGIN_BYTES * 2;
400+
#endif
396401
_tstate->c_stack_hard_limit = base + PYOS_STACK_MARGIN_BYTES;
397402
assert(_tstate->c_stack_soft_limit < here_addr);
398403
assert(here_addr < _tstate->c_stack_top);

0 commit comments

Comments
 (0)