Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move user_signals to _PyRuntimeState.
  • Loading branch information
ericsnowcurrently committed Dec 12, 2022
commit 820ebf1fdaed76182b30fdc39a4683308bde933a
37 changes: 37 additions & 0 deletions Include/internal/pycore_faulthandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,39 @@ extern "C" {
#endif


#ifdef HAVE_SIGACTION
#include <signal.h>
#endif


#ifndef MS_WINDOWS
/* register() is useless on Windows, because only SIGSEGV, SIGABRT and
SIGILL can be handled by the process, and these signals can only be used
with enable(), not using register() */
# define FAULTHANDLER_USER
#endif


#ifdef HAVE_SIGACTION
typedef struct sigaction _Py_sighandler_t;
#else
typedef PyOS_sighandler_t _Py_sighandler_t;
#endif


#ifdef FAULTHANDLER_USER
struct faulthandler_user_signal {
int enabled;
PyObject *file;
int fd;
int all_threads;
int chain;
_Py_sighandler_t previous;
PyInterpreterState *interp;
};
#endif /* FAULTHANDLER_USER */


struct _faulthandler_runtime_state {
struct {
int enabled;
Expand Down Expand Up @@ -37,6 +70,10 @@ struct _faulthandler_runtime_state {
/* released by child thread when joined */
PyThread_type_lock running;
} thread;

#ifdef FAULTHANDLER_USER
struct faulthandler_user_signal *user_signals;
#endif
};

#define _faulthandler_runtime_state_INIT \
Expand Down
27 changes: 2 additions & 25 deletions Modules/faulthandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@
/* Allocate at maximum 100 MiB of the stack to raise the stack overflow */
#define STACK_OVERFLOW_MAX_SIZE (100 * 1024 * 1024)

#ifndef MS_WINDOWS
/* register() is useless on Windows, because only SIGSEGV, SIGABRT and
SIGILL can be handled by the process, and these signals can only be used
with enable(), not using register() */
# define FAULTHANDLER_USER
#endif

#define PUTS(fd, str) _Py_write_noraise(fd, str, strlen(str))


Expand All @@ -58,12 +51,6 @@
#endif


#ifdef HAVE_SIGACTION
typedef struct sigaction _Py_sighandler_t;
#else
typedef PyOS_sighandler_t _Py_sighandler_t;
#endif

typedef struct {
int signum;
int enabled;
Expand All @@ -76,18 +63,8 @@ typedef struct {
#define thread _PyRuntime.faulthandler.thread

#ifdef FAULTHANDLER_USER
typedef struct {
int enabled;
PyObject *file;
int fd;
int all_threads;
int chain;
_Py_sighandler_t previous;
PyInterpreterState *interp;
} user_signal_t;

static user_signal_t *user_signals;

#define user_signals _PyRuntime.faulthandler.user_signals
typedef struct faulthandler_user_signal user_signal_t;
static void faulthandler_user(int signum);
#endif /* FAULTHANDLER_USER */

Expand Down
1 change: 0 additions & 1 deletion Tools/c-analyzer/cpython/globals-to-fix.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ Modules/itertoolsmodule.c - ziplongest_type -
##-----------------------
## state

Modules/faulthandler.c - user_signals -
Modules/faulthandler.c - stack -
Modules/faulthandler.c - old_stack -

Expand Down