pycore_faulthandler.h 2.2 KB

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