xref: /PHP-5.6/Zend/zend_signal.h (revision b31c1243)
1 /*
2   +----------------------------------------------------------------------+
3   | Zend Signal Handling                                                 |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 2008 The PHP Group                                     |
6   +----------------------------------------------------------------------+
7   | This source file is subject to version 3.01 of the PHP license,      |
8   | that is bundled with this package in the file LICENSE, and is        |
9   | available through the world-wide-web at the following url:           |
10   | http://www.php.net/license/3_01.txt                                  |
11   | If you did not receive a copy of the PHP license and are unable to   |
12   | obtain it through the world-wide-web, please send a note to          |
13   | license@php.net so we can mail you a copy immediately.               |
14   +----------------------------------------------------------------------+
15   | Authors: Lucas Nealan <lucas@php.net>                                |
16   |          Arnaud Le Blanc <lbarnaud@php.net>                          |
17   +----------------------------------------------------------------------+
18 
19  */
20 
21 /* $Id$ */
22 
23 #ifndef ZEND_SIGNAL_H
24 #define ZEND_SIGNAL_H
25 
26 #ifdef HAVE_SIGNAL_H
27 #include <signal.h>
28 #endif
29 
30 #ifndef NSIG
31 #define NSIG 65
32 #endif
33 
34 #ifndef ZEND_SIGNAL_QUEUE_SIZE
35 #define ZEND_SIGNAL_QUEUE_SIZE 32
36 #endif
37 
38 /* Signal structs */
39 typedef struct _zend_signal_entry_t {
40 	int   flags;          /* sigaction style flags */
41 	void* handler;      /* signal handler or context */
42 } zend_signal_entry_t;
43 
44 typedef struct _zend_signal_t {
45 	int signo;
46 	siginfo_t *siginfo;
47 	void* context;
48 } zend_signal_t;
49 
50 typedef struct _zend_signal_queue_t {
51 	zend_signal_t zend_signal;
52 	struct _zend_signal_queue_t *next;
53 } zend_signal_queue_t;
54 
55 /* Signal Globals */
56 typedef struct _zend_signal_globals_t {
57 	int depth;
58 	int blocked;            /* 0==TRUE, -1==FALSE */
59 	int running;            /* in signal handler execution */
60 	int active;             /* internal signal handling is enabled */
61 	int initialized;        /* memory initialized */
62 	zend_bool check;        /* check for replaced handlers on shutdown */
63 	zend_signal_entry_t handlers[NSIG];
64 	zend_signal_queue_t pstorage[ZEND_SIGNAL_QUEUE_SIZE], *phead, *ptail, *pavail; /* pending queue */
65 } zend_signal_globals_t;
66 
67 #ifdef ZTS
68 # define SIGG(v) TSRMG(zend_signal_globals_id, zend_signal_globals_t *, v)
69 BEGIN_EXTERN_C()
70 ZEND_API extern int zend_signal_globals_id;
71 END_EXTERN_C()
72 # define ZEND_SIGNAL_BLOCK_INTERRUPUTIONS() if (EXPECTED(zend_signal_globals_id)) { SIGG(depth)++; }
73 # define ZEND_SIGNAL_UNBLOCK_INTERRUPTIONS() if (EXPECTED(zend_signal_globals_id) && UNEXPECTED((--SIGG(depth))==SIGG(blocked))) { zend_signal_handler_unblock(TSRMLS_C); }
74 #else /* ZTS */
75 # define SIGG(v) (zend_signal_globals.v)
76 extern ZEND_API zend_signal_globals_t zend_signal_globals;
77 # define ZEND_SIGNAL_BLOCK_INTERRUPUTIONS()  SIGG(depth)++;
78 # define ZEND_SIGNAL_UNBLOCK_INTERRUPTIONS() if (UNEXPECTED((--SIGG(depth))==SIGG(blocked))) { zend_signal_handler_unblock(TSRMLS_C); }
79 #endif /* not ZTS */
80 
81 # define SIGNAL_BEGIN_CRITICAL() 	sigset_t oldmask; \
82 	zend_sigprocmask(SIG_BLOCK, &global_sigmask, &oldmask);
83 # define SIGNAL_END_CRITICAL()		zend_sigprocmask(SIG_SETMASK, &oldmask, NULL);
84 
85 void zend_signal_handler_defer(int signo, siginfo_t *siginfo, void *context);
86 ZEND_API void zend_signal_handler_unblock();
87 void zend_signal_activate(TSRMLS_D);
88 void zend_signal_deactivate(TSRMLS_D);
89 void zend_signal_startup();
90 void zend_signal_shutdown(TSRMLS_D);
91 ZEND_API int zend_signal(int signo, void (*handler)(int) TSRMLS_DC);
92 ZEND_API int zend_sigaction(int signo, const struct sigaction *act, struct sigaction *oldact TSRMLS_DC);
93 
94 #ifdef ZTS
95 #define zend_sigprocmask(signo, set, oldset) tsrm_sigmask((signo), (set), (oldset))
96 #else
97 #define zend_sigprocmask(signo, set, oldset) sigprocmask((signo), (set), (oldset))
98 #endif
99 
100 #endif /* ZEND_SIGNAL_H */
101 
102 /*
103  * Local variables:
104  * tab-width: 4
105  * c-basic-offset: 4
106  * indent-tabs-mode: t
107  * End:
108  */
109