codekingpro/portable-devtools
114k
1#ifndef Py_INTERNAL_FAULTHANDLER_H2#define Py_INTERNAL_FAULTHANDLER_H3#ifdef __cplusplus4extern "C" {5#endif6 7#ifndef Py_BUILD_CORE8# error "this header requires Py_BUILD_CORE define"9#endif10 11#ifdef HAVE_SIGACTION12# include <signal.h> // sigaction13#endif14 15 16#ifndef MS_WINDOWS17 /* register() is useless on Windows, because only SIGSEGV, SIGABRT and18 SIGILL can be handled by the process, and these signals can only be used19 with enable(), not using register() */20# define FAULTHANDLER_USER21#endif22 23 24#ifdef HAVE_SIGACTION25/* Using an alternative stack requires sigaltstack()26 and sigaction() SA_ONSTACK */27# ifdef HAVE_SIGALTSTACK28# define FAULTHANDLER_USE_ALT_STACK29# endif30typedef struct sigaction _Py_sighandler_t;31#else32typedef PyOS_sighandler_t _Py_sighandler_t;33#endif // HAVE_SIGACTION34 35 36#ifdef FAULTHANDLER_USER37struct 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 49struct _faulthandler_runtime_state {50 struct {51 int enabled;52 PyObject *file;53 int fd;54 int all_threads;55 PyInterpreterState *interp;56#ifdef MS_WINDOWS57 void *exc_handler;58#endif59 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 when72 faulthandler_thread() is interrupted before this thread exits, or at73 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_USER80 struct faulthandler_user_signal *user_signals;81#endif82 83#ifdef FAULTHANDLER_USE_ALT_STACK84 stack_t stack;85 stack_t old_stack;86#endif87};88 89#define _faulthandler_runtime_state_INIT \90 { \91 .fatal_error = { \92 .fd = -1, \93 }, \94 }95 96 97#ifdef __cplusplus98}99#endif100#endif /* !Py_INTERNAL_FAULTHANDLER_H */101 