1818# include <sys/resource.h>
1919#endif
2020
21- /* Using an alternative stack requires sigaltstack()
22- and sigaction() SA_ONSTACK */
23- #if defined(HAVE_SIGALTSTACK ) && defined(HAVE_SIGACTION )
24- # define FAULTHANDLER_USE_ALT_STACK
25- #endif
26-
2721#if defined(FAULTHANDLER_USE_ALT_STACK ) && defined(HAVE_LINUX_AUXVEC_H ) && defined(HAVE_SYS_AUXV_H )
2822# include <linux/auxvec.h> // AT_MINSIGSTKSZ
2923# include <sys/auxv.h> // getauxval()
3226/* Allocate at maximum 100 MiB of the stack to raise the stack overflow */
3327#define STACK_OVERFLOW_MAX_SIZE (100 * 1024 * 1024)
3428
35- #ifndef MS_WINDOWS
36- /* register() is useless on Windows, because only SIGSEGV, SIGABRT and
37- SIGILL can be handled by the process, and these signals can only be used
38- with enable(), not using register() */
39- # define FAULTHANDLER_USER
40- #endif
41-
4229#define PUTS (fd , str ) _Py_write_noraise(fd, str, strlen(str))
4330
4431
5845#endif
5946
6047
61- #ifdef HAVE_SIGACTION
62- typedef struct sigaction _Py_sighandler_t ;
63- #else
64- typedef PyOS_sighandler_t _Py_sighandler_t ;
65- #endif
66-
6748typedef struct {
6849 int signum ;
6950 int enabled ;
@@ -72,47 +53,12 @@ typedef struct {
7253 int all_threads ;
7354} fault_handler_t ;
7455
75- static struct {
76- int enabled ;
77- PyObject * file ;
78- int fd ;
79- int all_threads ;
80- PyInterpreterState * interp ;
81- #ifdef MS_WINDOWS
82- void * exc_handler ;
83- #endif
84- } fatal_error = {0 , NULL , -1 , 0 };
85-
86- static struct {
87- PyObject * file ;
88- int fd ;
89- PY_TIMEOUT_T timeout_us ; /* timeout in microseconds */
90- int repeat ;
91- PyInterpreterState * interp ;
92- int exit ;
93- char * header ;
94- size_t header_len ;
95- /* The main thread always holds this lock. It is only released when
96- faulthandler_thread() is interrupted before this thread exits, or at
97- Python exit. */
98- PyThread_type_lock cancel_event ;
99- /* released by child thread when joined */
100- PyThread_type_lock running ;
101- } thread ;
56+ #define fatal_error _PyRuntime.faulthandler.fatal_error
57+ #define thread _PyRuntime.faulthandler.thread
10258
10359#ifdef FAULTHANDLER_USER
104- typedef struct {
105- int enabled ;
106- PyObject * file ;
107- int fd ;
108- int all_threads ;
109- int chain ;
110- _Py_sighandler_t previous ;
111- PyInterpreterState * interp ;
112- } user_signal_t ;
113-
114- static user_signal_t * user_signals ;
115-
60+ #define user_signals _PyRuntime.faulthandler.user_signals
61+ typedef struct faulthandler_user_signal user_signal_t ;
11662static void faulthandler_user (int signum );
11763#endif /* FAULTHANDLER_USER */
11864
@@ -134,8 +80,8 @@ static const size_t faulthandler_nsignals = \
13480 Py_ARRAY_LENGTH (faulthandler_handlers );
13581
13682#ifdef FAULTHANDLER_USE_ALT_STACK
137- static stack_t stack ;
138- static stack_t old_stack ;
83+ # define stack _PyRuntime.faulthandler.stack
84+ # define old_stack _PyRuntime.faulthandler.old_stack
13985#endif
14086
14187
@@ -1094,7 +1040,7 @@ faulthandler_fatal_error_thread(void *plock)
10941040static PyObject *
10951041faulthandler_fatal_error_c_thread (PyObject * self , PyObject * args )
10961042{
1097- long thread ;
1043+ long tid ;
10981044 PyThread_type_lock lock ;
10991045
11001046 faulthandler_suppress_crash_report ();
@@ -1105,8 +1051,8 @@ faulthandler_fatal_error_c_thread(PyObject *self, PyObject *args)
11051051
11061052 PyThread_acquire_lock (lock , WAIT_LOCK );
11071053
1108- thread = PyThread_start_new_thread (faulthandler_fatal_error_thread , lock );
1109- if (thread == -1 ) {
1054+ tid = PyThread_start_new_thread (faulthandler_fatal_error_thread , lock );
1055+ if (tid == -1 ) {
11101056 PyThread_free_lock (lock );
11111057 PyErr_SetString (PyExc_RuntimeError , "unable to start the thread" );
11121058 return NULL ;
0 commit comments