static void faulthandler_user(int signum) { user_signal_t *user; int save_errno = errno; user = &user_signals[signum]; if (!user->enabled) return; faulthandler_dump_traceback(user->fd, user->all_threads, user->interp); #ifdef HAVE_SIGACTION if (user->chain) { (void)sigaction(signum, &user->previous, NULL); errno = save_errno; /* call the previous signal handler */ raise(signum); save_errno = errno; (void)faulthandler_register(signum, user->chain, NULL); errno = save_errno; } #else if (user->chain) { errno = save_errno; /* call the previous signal handler */ user->previous(signum); } #endif }
static LONG WINAPI faulthandler_exc_handler(struct _EXCEPTION_POINTERS *exc_info) { const int fd = fatal_error.fd; DWORD code = exc_info->ExceptionRecord->ExceptionCode; DWORD flags = exc_info->ExceptionRecord->ExceptionFlags; /* only log fatal exceptions */ if (flags & EXCEPTION_NONCONTINUABLE) { /* call the next exception handler */ return EXCEPTION_CONTINUE_SEARCH; } PUTS(fd, "Windows fatal exception: "); switch (code) { /* only format most common errors */ case EXCEPTION_ACCESS_VIOLATION: PUTS(fd, "access violation"); break; case EXCEPTION_FLT_DIVIDE_BY_ZERO: PUTS(fd, "float divide by zero"); break; case EXCEPTION_FLT_OVERFLOW: PUTS(fd, "float overflow"); break; case EXCEPTION_INT_DIVIDE_BY_ZERO: PUTS(fd, "int divide by zero"); break; case EXCEPTION_INT_OVERFLOW: PUTS(fd, "integer overflow"); break; case EXCEPTION_IN_PAGE_ERROR: PUTS(fd, "page error"); break; case EXCEPTION_STACK_OVERFLOW: PUTS(fd, "stack overflow"); break; default: PUTS(fd, "code "); _Py_DumpDecimal(fd, code); } PUTS(fd, "\n\n"); if (code == EXCEPTION_ACCESS_VIOLATION) { /* disable signal handler for SIGSEGV */ size_t i; for (i=0; i < faulthandler_nsignals; i++) { fault_handler_t *handler = &faulthandler_handlers[i]; if (handler->signum == SIGSEGV) { faulthandler_disable_fatal_handler(handler); break; } } } faulthandler_dump_traceback(fd, fatal_error.all_threads, fatal_error.interp); /* call the next exception handler */ return EXCEPTION_CONTINUE_SEARCH; }
static void faulthandler_fatal_error(int signum) { const int fd = fatal_error.fd; unsigned int i; fault_handler_t *handler = NULL; int save_errno = errno; if (!fatal_error.enabled) return; for (i=0; i < faulthandler_nsignals; i++) { handler = &faulthandler_handlers[i]; if (handler->signum == signum) break; } if (handler == NULL) { /* faulthandler_nsignals == 0 (unlikely) */ return; } /* restore the previous handler */ #ifdef HAVE_SIGACTION (void)sigaction(signum, &handler->previous, NULL); #else (void)signal(signum, handler->previous); #endif handler->enabled = 0; PUTS(fd, "Fatal Python error: "); PUTS(fd, handler->name); PUTS(fd, "\n\n"); faulthandler_dump_traceback(fd, fatal_error.all_threads, fatal_error.interp); errno = save_errno; #ifdef MS_WINDOWS if (signum == SIGSEGV) { /* don't explicitly call the previous handler for SIGSEGV in this signal handler, because the Windows signal handler would not be called */ return; } #endif /* call the previous signal handler: it is called immediately if we use sigaction() thanks to SA_NODEFER flag, otherwise it is deferred */ raise(signum); }