codekingpro/portable-devtools
114k
1// Define Py_NSIG constant for signal handling.2 3#ifndef Py_INTERNAL_SIGNAL_H4#define Py_INTERNAL_SIGNAL_H5#ifdef __cplusplus6extern "C" {7#endif8 9#ifndef Py_BUILD_CORE10# error "this header requires Py_BUILD_CORE define"11#endif12 13#include <signal.h> // NSIG14 15 16// Restore signals that the interpreter has called SIG_IGN on to SIG_DFL.17// Export for '_posixsubprocess' shared extension.18PyAPI_FUNC(void) _Py_RestoreSignals(void);19 20#ifdef _SIG_MAXSIG21 // gh-91145: On FreeBSD, <signal.h> defines NSIG as 32: it doesn't include22 // realtime signals: [SIGRTMIN,SIGRTMAX]. Use _SIG_MAXSIG instead. For23 // example on x86-64 FreeBSD 13, SIGRTMAX is 126 and _SIG_MAXSIG is 128.24# define Py_NSIG _SIG_MAXSIG25#elif defined(NSIG)26# define Py_NSIG NSIG27#elif defined(_NSIG)28# define Py_NSIG _NSIG // BSD/SysV29#elif defined(_SIGMAX)30# define Py_NSIG (_SIGMAX + 1) // QNX31#elif defined(SIGMAX)32# define Py_NSIG (SIGMAX + 1) // djgpp33#else34# define Py_NSIG 64 // Use a reasonable default value35#endif36 37#define INVALID_FD (-1)38 39struct _signals_runtime_state {40 struct {41 // tripped and func should be accessed using atomic ops.42 int tripped;43 PyObject* func;44 } handlers[Py_NSIG];45 46 volatile struct {47#ifdef MS_WINDOWS48 /* This would be "SOCKET fd" if <winsock2.h> were always included.49 It isn't so we must cast to SOCKET where appropriate. */50 volatile int fd;51#elif defined(__VXWORKS__)52 int fd;53#else54 sig_atomic_t fd;55#endif56 57 int warn_on_full_buffer;58#ifdef MS_WINDOWS59 int use_send;60#endif61 } wakeup;62 63 /* Speed up sigcheck() when none tripped.64 is_tripped should be accessed using atomic ops. */65 int is_tripped;66 67 /* These objects necessarily belong to the main interpreter. */68 PyObject *default_handler;69 PyObject *ignore_handler;70 71#ifdef MS_WINDOWS72 /* This would be "HANDLE sigint_event" if <windows.h> were always included.73 It isn't so we must cast to HANDLE everywhere "sigint_event" is used. */74 void *sigint_event;75#endif76 77 /* True if the main interpreter thread exited due to an unhandled78 * KeyboardInterrupt exception, suggesting the user pressed ^C. */79 int unhandled_keyboard_interrupt;80};81 82#ifdef MS_WINDOWS83# define _signals_WAKEUP_INIT \84 {.fd = INVALID_FD, .warn_on_full_buffer = 1, .use_send = 0}85#else86# define _signals_WAKEUP_INIT \87 {.fd = INVALID_FD, .warn_on_full_buffer = 1}88#endif89 90#define _signals_RUNTIME_INIT \91 { \92 .wakeup = _signals_WAKEUP_INIT, \93 }94 95 96// Export for '_multiprocessing' shared extension97PyAPI_FUNC(int) _PyOS_IsMainThread(void);98 99#ifdef MS_WINDOWS100// <windows.h> is not included by Python.h so use void* instead of HANDLE.101// Export for '_multiprocessing' shared extension102PyAPI_FUNC(void*) _PyOS_SigintEvent(void);103#endif104 105#ifdef __cplusplus106}107#endif108#endif // !Py_INTERNAL_SIGNAL_H109 