18
18
# include <sys/resource.h>
19
19
#endif
20
20
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
-
27
21
#if defined(FAULTHANDLER_USE_ALT_STACK ) && defined(HAVE_LINUX_AUXVEC_H ) && defined(HAVE_SYS_AUXV_H )
28
22
# include <linux/auxvec.h> // AT_MINSIGSTKSZ
29
23
# include <sys/auxv.h> // getauxval()
32
26
/* Allocate at maximum 100 MiB of the stack to raise the stack overflow */
33
27
#define STACK_OVERFLOW_MAX_SIZE (100 * 1024 * 1024)
34
28
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
-
42
29
#define PUTS (fd , str ) _Py_write_noraise(fd, str, strlen(str))
43
30
44
31
58
45
#endif
59
46
60
47
61
- #ifdef HAVE_SIGACTION
62
- typedef struct sigaction _Py_sighandler_t ;
63
- #else
64
- typedef PyOS_sighandler_t _Py_sighandler_t ;
65
- #endif
66
-
67
48
typedef struct {
68
49
int signum ;
69
50
int enabled ;
@@ -72,47 +53,12 @@ typedef struct {
72
53
int all_threads ;
73
54
} fault_handler_t ;
74
55
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
102
58
103
59
#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 ;
116
62
static void faulthandler_user (int signum );
117
63
#endif /* FAULTHANDLER_USER */
118
64
@@ -134,8 +80,8 @@ static const size_t faulthandler_nsignals = \
134
80
Py_ARRAY_LENGTH (faulthandler_handlers );
135
81
136
82
#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
139
85
#endif
140
86
141
87
@@ -1094,7 +1040,7 @@ faulthandler_fatal_error_thread(void *plock)
1094
1040
static PyObject *
1095
1041
faulthandler_fatal_error_c_thread (PyObject * self , PyObject * args )
1096
1042
{
1097
- long thread ;
1043
+ long tid ;
1098
1044
PyThread_type_lock lock ;
1099
1045
1100
1046
faulthandler_suppress_crash_report ();
@@ -1105,8 +1051,8 @@ faulthandler_fatal_error_c_thread(PyObject *self, PyObject *args)
1105
1051
1106
1052
PyThread_acquire_lock (lock , WAIT_LOCK );
1107
1053
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 ) {
1110
1056
PyThread_free_lock (lock );
1111
1057
PyErr_SetString (PyExc_RuntimeError , "unable to start the thread" );
1112
1058
return NULL ;
0 commit comments