Skip to content

Commit 650064f

Browse files
colesburyseehwan80
authored andcommitted
pythongh-130396: Fix thread sanitizer crashes on stack overflow tests (pythongh-130966)
Thread sanitizer will often crash if a test uses more than half the stack.
1 parent 9bfe6e9 commit 650064f

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)