Skip to content

Commit d815525

Browse files
committed
gh-143108: Don't TSan instrument faulthandler.c
The dumping of tracebacks has data races and that's okay (it's best effort).
1 parent f783cc3 commit d815525

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

Include/internal/pycore_interpframe.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static inline PyCodeObject *_PyFrame_GetCode(_PyInterpreterFrame *f) {
2727
// Similar to _PyFrame_GetCode(), but return NULL if the frame is invalid or
2828
// freed. Used by dump_frame() in Python/traceback.c. The function uses
2929
// heuristics to detect freed memory, it's not 100% reliable.
30-
static inline PyCodeObject*
30+
static inline PyCodeObject* _Py_NO_SANITIZE_THREAD
3131
_PyFrame_SafeGetCode(_PyInterpreterFrame *f)
3232
{
3333
// globals and builtins may be NULL on a legit frame, but it's unlikely.
@@ -70,7 +70,7 @@ _PyFrame_GetBytecode(_PyInterpreterFrame *f)
7070
// Similar to PyUnstable_InterpreterFrame_GetLasti(), but return NULL if the
7171
// frame is invalid or freed. Used by dump_frame() in Python/traceback.c. The
7272
// function uses heuristics to detect freed memory, it's not 100% reliable.
73-
static inline int
73+
static inline int _Py_NO_SANITIZE_THREAD
7474
_PyFrame_SafeGetLasti(struct _PyInterpreterFrame *f)
7575
{
7676
// Code based on _PyFrame_GetBytecode() but replace _PyFrame_GetCode()

Python/traceback.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ _Py_DumpWideString(int fd, wchar_t *str)
10351035
10361036
Return 0 on success. Return -1 if the frame is invalid. */
10371037

1038-
static int
1038+
static int _Py_NO_SANITIZE_THREAD
10391039
dump_frame(int fd, _PyInterpreterFrame *frame)
10401040
{
10411041
if (frame->owner == FRAME_OWNED_BY_INTERPRETER) {
@@ -1088,7 +1088,7 @@ dump_frame(int fd, _PyInterpreterFrame *frame)
10881088
return res;
10891089
}
10901090

1091-
static int
1091+
static int _Py_NO_SANITIZE_THREAD
10921092
tstate_is_freed(PyThreadState *tstate)
10931093
{
10941094
if (_PyMem_IsPtrFreed(tstate)) {
@@ -1104,14 +1104,14 @@ tstate_is_freed(PyThreadState *tstate)
11041104
}
11051105

11061106

1107-
static int
1107+
static int _Py_NO_SANITIZE_THREAD
11081108
interp_is_freed(PyInterpreterState *interp)
11091109
{
11101110
return _PyMem_IsPtrFreed(interp);
11111111
}
11121112

11131113

1114-
static void
1114+
static void _Py_NO_SANITIZE_THREAD
11151115
dump_traceback(int fd, PyThreadState *tstate, int write_header)
11161116
{
11171117
if (write_header) {
@@ -1263,7 +1263,7 @@ write_thread_id(int fd, PyThreadState *tstate, int is_current)
12631263
12641264
The caller is responsible to call PyErr_CheckSignals() to call Python signal
12651265
handlers if signals were received. */
1266-
const char*
1266+
const char* _Py_NO_SANITIZE_THREAD
12671267
_Py_DumpTracebackThreads(int fd, PyInterpreterState *interp,
12681268
PyThreadState *current_tstate)
12691269
{
@@ -1332,7 +1332,7 @@ _Py_DumpTracebackThreads(int fd, PyInterpreterState *interp,
13321332
}
13331333
dump_traceback(fd, tstate, 0);
13341334

1335-
tstate = PyThreadState_Next(tstate);
1335+
tstate = tstate->next;
13361336
nthreads++;
13371337
} while (tstate != NULL);
13381338
_Py_END_SUPPRESS_IPH

Tools/tsan/suppressions_free_threading.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,7 @@
1212

1313
# These warnings trigger directly in a CPython function.
1414

15-
race_top:dump_traceback
16-
race_top:fatal_error
17-
race_top:_PyFrame_GetCode
18-
race_top:_PyFrame_Initialize
1915
race_top:_PyObject_TryGetInstanceAttribute
20-
race_top:PyUnstable_InterpreterFrame_GetLine
21-
race_top:write_thread_id
2216

2317
# https://gist.github.com/mpage/6962e8870606cfc960e159b407a0cb40
2418
thread:pthread_create

0 commit comments

Comments
 (0)