Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:06:47

0001 // Define Py_NSIG constant for signal handling.
0002 
0003 #ifndef Py_INTERNAL_SIGNAL_H
0004 #define Py_INTERNAL_SIGNAL_H
0005 #ifdef __cplusplus
0006 extern "C" {
0007 #endif
0008 
0009 #ifndef Py_BUILD_CORE
0010 #  error "this header requires Py_BUILD_CORE define"
0011 #endif
0012 
0013 #include "pycore_atomic.h"         // _Py_atomic_address
0014 
0015 #include <signal.h>                // NSIG
0016 
0017 
0018 #ifdef _SIG_MAXSIG
0019    // gh-91145: On FreeBSD, <signal.h> defines NSIG as 32: it doesn't include
0020    // realtime signals: [SIGRTMIN,SIGRTMAX]. Use _SIG_MAXSIG instead. For
0021    // example on x86-64 FreeBSD 13, SIGRTMAX is 126 and _SIG_MAXSIG is 128.
0022 #  define Py_NSIG _SIG_MAXSIG
0023 #elif defined(NSIG)
0024 #  define Py_NSIG NSIG
0025 #elif defined(_NSIG)
0026 #  define Py_NSIG _NSIG            // BSD/SysV
0027 #elif defined(_SIGMAX)
0028 #  define Py_NSIG (_SIGMAX + 1)    // QNX
0029 #elif defined(SIGMAX)
0030 #  define Py_NSIG (SIGMAX + 1)     // djgpp
0031 #else
0032 #  define Py_NSIG 64               // Use a reasonable default value
0033 #endif
0034 
0035 #define INVALID_FD (-1)
0036 
0037 struct _signals_runtime_state {
0038     volatile struct {
0039         _Py_atomic_int tripped;
0040         /* func is atomic to ensure that PyErr_SetInterrupt is async-signal-safe
0041          * (even though it would probably be otherwise, anyway).
0042          */
0043         _Py_atomic_address func;
0044     } handlers[Py_NSIG];
0045 
0046     volatile struct {
0047 #ifdef MS_WINDOWS
0048         /* This would be "SOCKET fd" if <winsock2.h> were always included.
0049            It isn't so we must cast to SOCKET where appropriate. */
0050         volatile int fd;
0051 #elif defined(__VXWORKS__)
0052         int fd;
0053 #else
0054         sig_atomic_t fd;
0055 #endif
0056 
0057         int warn_on_full_buffer;
0058 #ifdef MS_WINDOWS
0059         int use_send;
0060 #endif
0061     } wakeup;
0062 
0063     /* Speed up sigcheck() when none tripped */
0064     _Py_atomic_int is_tripped;
0065 
0066     /* These objects necessarily belong to the main interpreter. */
0067     PyObject *default_handler;
0068     PyObject *ignore_handler;
0069 
0070 #ifdef MS_WINDOWS
0071     /* This would be "HANDLE sigint_event" if <windows.h> were always included.
0072        It isn't so we must cast to HANDLE everywhere "sigint_event" is used. */
0073     void *sigint_event;
0074 #endif
0075 
0076     /* True if the main interpreter thread exited due to an unhandled
0077      * KeyboardInterrupt exception, suggesting the user pressed ^C. */
0078     int unhandled_keyboard_interrupt;
0079 };
0080 
0081 #ifdef MS_WINDOWS
0082 # define _signals_WAKEUP_INIT \
0083     {.fd = INVALID_FD, .warn_on_full_buffer = 1, .use_send = 0}
0084 #else
0085 # define _signals_WAKEUP_INIT \
0086     {.fd = INVALID_FD, .warn_on_full_buffer = 1}
0087 #endif
0088 
0089 #define _signals_RUNTIME_INIT \
0090     { \
0091         .wakeup = _signals_WAKEUP_INIT, \
0092     }
0093 
0094 
0095 #ifdef __cplusplus
0096 }
0097 #endif
0098 #endif  // !Py_INTERNAL_SIGNAL_H