Debian Codegraph @

Include/internal/pycore_faulthandler.h

raw
1 #ifndef Py_INTERNAL_FAULTHANDLER_H
2 #define Py_INTERNAL_FAULTHANDLER_H
3 #ifdef __cplusplus
4 extern "C" {
5 #endif
6
7 #ifndef Py_BUILD_CORE
8 # error "this header requires Py_BUILD_CORE define"
9 #endif
10
11 #ifdef HAVE_SIGACTION
12 # include <signal.h> // sigaction
13 #endif
14
15
16 #ifndef MS_WINDOWS
17 /* register() is useless on Windows, because only SIGSEGV, SIGABRT and
18 SIGILL can be handled by the process, and these signals can only be used
19 with enable(), not using register() */
20 # define FAULTHANDLER_USER
21 #endif
22
23
24 #ifdef HAVE_SIGACTION
25 /* Using an alternative stack requires sigaltstack()
26 and sigaction() SA_ONSTACK */
27 # ifdef HAVE_SIGALTSTACK
28 # define FAULTHANDLER_USE_ALT_STACK
29 # endif
30 typedef struct sigaction _Py_sighandler_t;
31 #else
32 typedef PyOS_sighandler_t _Py_sighandler_t;
33 #endif // HAVE_SIGACTION
34
35
36 #ifdef FAULTHANDLER_USER
37 struct faulthandler_user_signal {
38 int enabled;
39 PyObject *file;
40 int fd;
41 int all_threads;
42 int chain;
43 _Py_sighandler_t previous;
44 PyInterpreterState *interp;
45 };
46 #endif /* FAULTHANDLER_USER */
47
48
49 struct _faulthandler_runtime_state {
50 struct {
51 int enabled;
52 PyObject *file;
53 int fd;
54 int all_threads;
55 PyInterpreterState *interp;
56 #ifdef MS_WINDOWS
57 void *exc_handler;
58 #endif
59 int c_stack;
60 } fatal_error;
61
62 struct {
63 PyObject *file;
64 int fd;
65 PY_TIMEOUT_T timeout_us; /* timeout in microseconds */
66 int repeat;
67 PyInterpreterState *interp;
68 int exit;
69 char *header;
70 size_t header_len;
71 /* The main thread always holds this lock. It is only released when
72 faulthandler_thread() is interrupted before this thread exits, or at
73 Python exit. */
74 PyThread_type_lock cancel_event;
75 /* released by child thread when joined */
76 PyThread_type_lock running;
77 } thread;
78
79 #ifdef FAULTHANDLER_USER
80 struct faulthandler_user_signal *user_signals;
81 #endif
82
83 #ifdef FAULTHANDLER_USE_ALT_STACK
84 stack_t stack;
85 stack_t old_stack;
86 #endif
87 };
88
89 #define _faulthandler_runtime_state_INIT \
90 { \
91 .fatal_error = { \
92 .fd = -1, \
93 }, \
94 }
95
96
97 #ifdef __cplusplus
98 }
99 #endif
100 #endif /* !Py_INTERNAL_FAULTHANDLER_H */