Skip to content

Commit 1fac29a

Browse files
gh-141044: Raise TSan stack_size floor to 12 margins
TSan only uses half the stack in tstate_set_stack(), so the 6-margin minimum that is enough for ASan/debug still leaked Thread objects at the floor under ThreadSanitizer (refcount delta ~355). Require 12 margins for TSan. Update tests that assumed 256 KiB is always accepted.
1 parent 7f942ca commit 1fac29a

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

‎Include/internal/pycore_pythonrun.h‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,15 @@ extern PyObject* _PyRun_SimpleString(
6262
# define _PyOS_STACK_MARGIN_SHIFT (_PyOS_LOG2_STACK_MARGIN + 2)
6363
#endif
6464

65-
#if (defined(Py_DEBUG) \
65+
#ifdef _Py_THREAD_SANITIZER
66+
/* TSan: tstate_set_stack() only uses half the stack, so the 6-margin
67+
* floor that is enough for ASan/debug still leaves Thread bootstrap
68+
* without working space (gh-141044). Require 12 margins. */
69+
# define _PyOS_MIN_STACK_SIZE (_PyOS_STACK_MARGIN_BYTES * 12)
70+
#elif (defined(Py_DEBUG) \
6671
|| defined(_Py_ADDRESS_SANITIZER) \
67-
|| defined(_Py_THREAD_SANITIZER) \
6872
|| defined(_Py_UNDEFINED_BEHAVIOR_SANITIZER))
69-
/* Debug and sanitizer builds need more than the default 3 margins:
70-
* - TSan: tstate_set_stack() only uses half the stack.
73+
/* Debug/ASan/UBSan need more than the default 3 margins:
7174
* - ASan (gh-141044): instrumentation consumes extra C stack.
7275
* - Py_DEBUG / UBSan: larger C frames leave threading.Thread bootstrap
7376
* with no working space above the soft recursion limit at 3 margins,

0 commit comments

Comments
 (0)