mirror of
https://github.com/python/cpython.git
synced 2025-11-24 20:30:18 +00:00
[3.14] gh-137185: Fix _Py_DumpStack() async signal safety (gh-137187) (gh-137206)
Call backtrace() once when installing the signal handler to ensure that
libgcc is dynamically loaded outside the signal handler.
This fixes a "signal-unsafe call inside of a signal" TSan error from
test_faulthandler.test_enable_fd.
(cherry picked from commit 11a8652e25)
Co-authored-by: Sam Gross <colesbury@gmail.com>
This commit is contained in:
parent
93ac6f3472
commit
75de39ba1b
4 changed files with 18 additions and 0 deletions
|
|
@ -100,6 +100,7 @@ extern int _Py_WriteIndentedMargin(int, const char*, PyObject *);
|
|||
extern int _Py_WriteIndent(int, PyObject *);
|
||||
|
||||
// Export for the faulthandler module
|
||||
PyAPI_FUNC(void) _Py_InitDumpStack(void);
|
||||
PyAPI_FUNC(void) _Py_DumpStack(int fd);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
Fix a potential async-signal-safety issue in :mod:`faulthandler` when
|
||||
printing C stack traces.
|
||||
|
|
@ -525,6 +525,11 @@ faulthandler_enable(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
// gh-137185: Initialize C stack trace dumping outside of the signal
|
||||
// handler. Specifically, we call backtrace() to ensure that libgcc is
|
||||
// dynamically loaded outside of the signal handler.
|
||||
_Py_InitDumpStack();
|
||||
|
||||
for (size_t i=0; i < faulthandler_nsignals; i++) {
|
||||
fault_handler_t *handler;
|
||||
int err;
|
||||
|
|
|
|||
|
|
@ -1327,3 +1327,13 @@ _Py_DumpStack(int fd)
|
|||
PUTS(fd, " <cannot get C stack on this system>\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
_Py_InitDumpStack(void)
|
||||
{
|
||||
#ifdef CAN_C_BACKTRACE
|
||||
// gh-137185: Call backtrace() once to force libgcc to be loaded early.
|
||||
void *callstack[1];
|
||||
(void)backtrace(callstack, 1);
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue