Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-19 09:50:50

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 <signal.h>               // NSIG
0014 
0015 
0016 // Restore signals that the interpreter has called SIG_IGN on to SIG_DFL.
0017 // Export for '_posixsubprocess' shared extension.
0018 PyAPI_FUNC(void) _Py_RestoreSignals(void);
0019 
0020 #ifdef _SIG_MAXSIG
0021    // gh-91145: On FreeBSD, <signal.h> defines NSIG as 32: it doesn't include
0022    // realtime signals: [SIGRTMIN,SIGRTMAX]. Use _SIG_MAXSIG instead. For
0023    // example on x86-64 FreeBSD 13, SIGRTMAX is 126 and _SIG_MAXSIG is 128.
0024 #  define Py_NSIG _SIG_MAXSIG
0025 #elif defined(NSIG)
0026 #  define Py_NSIG NSIG
0027 #elif defined(_NSIG)
0028 #  define Py_NSIG _NSIG            // BSD/SysV
0029 #elif defined(_SIGMAX)
0030 #  define Py_NSIG (_SIGMAX + 1)    // QNX
0031 #elif defined(SIGMAX)
0032 #  define Py_NSIG (SIGMAX + 1)     // djgpp
0033 #else
0034 #  define Py_NSIG 64               // Use a reasonable default value
0035 #endif
0036 
0037 #define INVALID_FD (-1)
0038 
0039 struct _signals_runtime_state {
0040     struct {
0041         // tripped and func should be accessed using atomic ops.
0042         int tripped;
0043         PyObject* 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        is_tripped should be accessed using atomic ops. */
0065     int is_tripped;
0066 
0067     /* These objects necessarily belong to the main interpreter. */
0068     PyObject *default_handler;
0069     PyObject *ignore_handler;
0070 
0071 #ifdef MS_WINDOWS
0072     /* This would be "HANDLE sigint_event" if <windows.h> were always included.
0073        It isn't so we must cast to HANDLE everywhere "sigint_event" is used. */
0074     void *sigint_event;
0075 #endif
0076 
0077     /* True if the main interpreter thread exited due to an unhandled
0078      * KeyboardInterrupt exception, suggesting the user pressed ^C. */
0079     int unhandled_keyboard_interrupt;
0080 };
0081 
0082 #ifdef MS_WINDOWS
0083 # define _signals_WAKEUP_INIT \
0084     {.fd = INVALID_FD, .warn_on_full_buffer = 1, .use_send = 0}
0085 #else
0086 # define _signals_WAKEUP_INIT \
0087     {.fd = INVALID_FD, .warn_on_full_buffer = 1}
0088 #endif
0089 
0090 #define _signals_RUNTIME_INIT \
0091     { \
0092         .wakeup = _signals_WAKEUP_INIT, \
0093     }
0094 
0095 
0096 // Export for '_multiprocessing' shared extension
0097 PyAPI_FUNC(int) _PyOS_IsMainThread(void);
0098 
0099 #ifdef MS_WINDOWS
0100 // <windows.h> is not included by Python.h so use void* instead of HANDLE.
0101 // Export for '_multiprocessing' shared extension
0102 PyAPI_FUNC(void*) _PyOS_SigintEvent(void);
0103 #endif
0104 
0105 #ifdef __cplusplus
0106 }
0107 #endif
0108 #endif  // !Py_INTERNAL_SIGNAL_H