File Modules/faulthandler.c changed (mode: 100644) (index fc9490d0d4..dcfebf2781) |
... |
... |
static struct { |
55 |
55 |
int fd; |
int fd; |
56 |
56 |
int all_threads; |
int all_threads; |
57 |
57 |
PyInterpreterState *interp; |
PyInterpreterState *interp; |
|
58 |
|
#ifdef MS_WINDOWS |
|
59 |
|
void *exc_handler; |
|
60 |
|
#endif |
58 |
61 |
} fatal_error = {0, NULL, -1, 0}; |
} fatal_error = {0, NULL, -1, 0}; |
59 |
62 |
|
|
60 |
63 |
#ifdef FAULTHANDLER_LATER |
#ifdef FAULTHANDLER_LATER |
|
... |
... |
faulthandler_exc_handler(struct _EXCEPTION_POINTERS *exc_info) |
395 |
398 |
|
|
396 |
399 |
if (code == EXCEPTION_ACCESS_VIOLATION) { |
if (code == EXCEPTION_ACCESS_VIOLATION) { |
397 |
400 |
/* disable signal handler for SIGSEGV */ |
/* disable signal handler for SIGSEGV */ |
398 |
|
size_t i; |
|
399 |
|
for (i=0; i < faulthandler_nsignals; i++) { |
|
|
401 |
|
for (size_t i=0; i < faulthandler_nsignals; i++) { |
400 |
402 |
fault_handler_t *handler = &faulthandler_handlers[i]; |
fault_handler_t *handler = &faulthandler_handlers[i]; |
401 |
403 |
if (handler->signum == SIGSEGV) { |
if (handler->signum == SIGSEGV) { |
402 |
404 |
faulthandler_disable_fatal_handler(handler); |
faulthandler_disable_fatal_handler(handler); |
|
... |
... |
faulthandler_exc_handler(struct _EXCEPTION_POINTERS *exc_info) |
418 |
420 |
static int |
static int |
419 |
421 |
faulthandler_enable(void) |
faulthandler_enable(void) |
420 |
422 |
{ |
{ |
421 |
|
size_t i; |
|
422 |
|
|
|
423 |
423 |
if (fatal_error.enabled) { |
if (fatal_error.enabled) { |
424 |
424 |
return 0; |
return 0; |
425 |
425 |
} |
} |
426 |
426 |
fatal_error.enabled = 1; |
fatal_error.enabled = 1; |
427 |
427 |
|
|
428 |
|
for (i=0; i < faulthandler_nsignals; i++) { |
|
|
428 |
|
for (size_t i=0; i < faulthandler_nsignals; i++) { |
429 |
429 |
fault_handler_t *handler; |
fault_handler_t *handler; |
430 |
430 |
#ifdef HAVE_SIGACTION |
#ifdef HAVE_SIGACTION |
431 |
431 |
struct sigaction action; |
struct sigaction action; |
|
... |
... |
faulthandler_enable(void) |
462 |
462 |
} |
} |
463 |
463 |
|
|
464 |
464 |
#ifdef MS_WINDOWS |
#ifdef MS_WINDOWS |
465 |
|
AddVectoredExceptionHandler(1, faulthandler_exc_handler); |
|
|
465 |
|
assert(fatal_error.exc_handler == NULL); |
|
466 |
|
fatal_error.exc_handler = AddVectoredExceptionHandler(1, faulthandler_exc_handler); |
466 |
467 |
#endif |
#endif |
467 |
468 |
return 0; |
return 0; |
468 |
469 |
} |
} |
|
... |
... |
faulthandler_py_enable(PyObject *self, PyObject *args, PyObject *kwargs) |
504 |
505 |
static void |
static void |
505 |
506 |
faulthandler_disable(void) |
faulthandler_disable(void) |
506 |
507 |
{ |
{ |
507 |
|
unsigned int i; |
|
508 |
|
fault_handler_t *handler; |
|
509 |
|
|
|
510 |
508 |
if (fatal_error.enabled) { |
if (fatal_error.enabled) { |
511 |
509 |
fatal_error.enabled = 0; |
fatal_error.enabled = 0; |
512 |
|
for (i=0; i < faulthandler_nsignals; i++) { |
|
|
510 |
|
for (size_t i=0; i < faulthandler_nsignals; i++) { |
|
511 |
|
fault_handler_t *handler; |
513 |
512 |
handler = &faulthandler_handlers[i]; |
handler = &faulthandler_handlers[i]; |
514 |
513 |
faulthandler_disable_fatal_handler(handler); |
faulthandler_disable_fatal_handler(handler); |
515 |
514 |
} |
} |
516 |
515 |
} |
} |
517 |
|
|
|
|
516 |
|
#ifdef MS_WINDOWS |
|
517 |
|
if (fatal_error.exc_handler != NULL) { |
|
518 |
|
RemoveVectoredExceptionHandler(fatal_error.exc_handler); |
|
519 |
|
fatal_error.exc_handler = NULL; |
|
520 |
|
} |
|
521 |
|
#endif |
518 |
522 |
Py_CLEAR(fatal_error.file); |
Py_CLEAR(fatal_error.file); |
519 |
523 |
} |
} |
520 |
524 |
|
|
|
... |
... |
faulthandler_user(int signum) |
777 |
781 |
static int |
static int |
778 |
782 |
check_signum(int signum) |
check_signum(int signum) |
779 |
783 |
{ |
{ |
780 |
|
unsigned int i; |
|
781 |
|
|
|
782 |
|
for (i=0; i < faulthandler_nsignals; i++) { |
|
|
784 |
|
for (size_t i=0; i < faulthandler_nsignals; i++) { |
783 |
785 |
if (faulthandler_handlers[i].signum == signum) { |
if (faulthandler_handlers[i].signum == signum) { |
784 |
786 |
PyErr_Format(PyExc_RuntimeError, |
PyErr_Format(PyExc_RuntimeError, |
785 |
787 |
"signal %i cannot be registered, " |
"signal %i cannot be registered, " |
|
... |
... |
faulthandler_stack_overflow(PyObject *self) |
1122 |
1124 |
static int |
static int |
1123 |
1125 |
faulthandler_traverse(PyObject *module, visitproc visit, void *arg) |
faulthandler_traverse(PyObject *module, visitproc visit, void *arg) |
1124 |
1126 |
{ |
{ |
1125 |
|
#ifdef FAULTHANDLER_USER |
|
1126 |
|
unsigned int signum; |
|
1127 |
|
#endif |
|
1128 |
|
|
|
1129 |
1127 |
#ifdef FAULTHANDLER_LATER |
#ifdef FAULTHANDLER_LATER |
1130 |
1128 |
Py_VISIT(thread.file); |
Py_VISIT(thread.file); |
1131 |
1129 |
#endif |
#endif |
1132 |
1130 |
#ifdef FAULTHANDLER_USER |
#ifdef FAULTHANDLER_USER |
1133 |
1131 |
if (user_signals != NULL) { |
if (user_signals != NULL) { |
1134 |
|
for (signum=0; signum < NSIG; signum++) |
|
|
1132 |
|
for (size_t signum=0; signum < NSIG; signum++) |
1135 |
1133 |
Py_VISIT(user_signals[signum].file); |
Py_VISIT(user_signals[signum].file); |
1136 |
1134 |
} |
} |
1137 |
1135 |
#endif |
#endif |
|
... |
... |
int _PyFaulthandler_Init(void) |
1342 |
1340 |
|
|
1343 |
1341 |
void _PyFaulthandler_Fini(void) |
void _PyFaulthandler_Fini(void) |
1344 |
1342 |
{ |
{ |
1345 |
|
#ifdef FAULTHANDLER_USER |
|
1346 |
|
unsigned int signum; |
|
1347 |
|
#endif |
|
1348 |
|
|
|
1349 |
1343 |
#ifdef FAULTHANDLER_LATER |
#ifdef FAULTHANDLER_LATER |
1350 |
1344 |
/* later */ |
/* later */ |
1351 |
1345 |
if (thread.cancel_event) { |
if (thread.cancel_event) { |
|
... |
... |
void _PyFaulthandler_Fini(void) |
1363 |
1357 |
#ifdef FAULTHANDLER_USER |
#ifdef FAULTHANDLER_USER |
1364 |
1358 |
/* user */ |
/* user */ |
1365 |
1359 |
if (user_signals != NULL) { |
if (user_signals != NULL) { |
1366 |
|
for (signum=0; signum < NSIG; signum++) |
|
|
1360 |
|
for (size_t signum=0; signum < NSIG; signum++) { |
1367 |
1361 |
faulthandler_unregister(&user_signals[signum], signum); |
faulthandler_unregister(&user_signals[signum], signum); |
|
1362 |
|
} |
1368 |
1363 |
PyMem_Free(user_signals); |
PyMem_Free(user_signals); |
1369 |
1364 |
user_signals = NULL; |
user_signals = NULL; |
1370 |
1365 |
} |
} |