zend_signal.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Zend Signal Handling |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 2008-2018 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. #ifndef ZEND_SIGNAL_H
  20. #define ZEND_SIGNAL_H
  21. #ifdef ZEND_SIGNALS
  22. # ifdef HAVE_SIGNAL_H
  23. # include <signal.h>
  24. # endif
  25. #ifndef NSIG
  26. #define NSIG 65
  27. #endif
  28. #ifndef ZEND_SIGNAL_QUEUE_SIZE
  29. #define ZEND_SIGNAL_QUEUE_SIZE 64
  30. #endif
  31. /* Signal structs */
  32. typedef struct _zend_signal_entry_t {
  33. int flags; /* sigaction style flags */
  34. void* handler; /* signal handler or context */
  35. } zend_signal_entry_t;
  36. typedef struct _zend_signal_t {
  37. int signo;
  38. siginfo_t *siginfo;
  39. void* context;
  40. } zend_signal_t;
  41. typedef struct _zend_signal_queue_t {
  42. zend_signal_t zend_signal;
  43. struct _zend_signal_queue_t *next;
  44. } zend_signal_queue_t;
  45. /* Signal Globals */
  46. typedef struct _zend_signal_globals_t {
  47. int depth;
  48. int blocked; /* 1==TRUE, 0==FALSE */
  49. int running; /* in signal handler execution */
  50. int active; /* internal signal handling is enabled */
  51. zend_bool check; /* check for replaced handlers on shutdown */
  52. zend_signal_entry_t handlers[NSIG];
  53. zend_signal_queue_t pstorage[ZEND_SIGNAL_QUEUE_SIZE], *phead, *ptail, *pavail; /* pending queue */
  54. } zend_signal_globals_t;
  55. # ifdef ZTS
  56. # define SIGG(v) ZEND_TSRMG(zend_signal_globals_id, zend_signal_globals_t *, v)
  57. BEGIN_EXTERN_C()
  58. ZEND_API extern int zend_signal_globals_id;
  59. END_EXTERN_C()
  60. # else
  61. # define SIGG(v) (zend_signal_globals.v)
  62. BEGIN_EXTERN_C()
  63. ZEND_API extern zend_signal_globals_t zend_signal_globals;
  64. END_EXTERN_C()
  65. # endif /* not ZTS */
  66. # ifdef ZTS
  67. # define ZEND_SIGNAL_BLOCK_INTERRUPTIONS() if (EXPECTED(zend_signal_globals_id)) { SIGG(depth)++; }
  68. # define ZEND_SIGNAL_UNBLOCK_INTERRUPTIONS() if (EXPECTED(zend_signal_globals_id) && UNEXPECTED(((SIGG(depth)--) == SIGG(blocked)))) { zend_signal_handler_unblock(); }
  69. # else /* ZTS */
  70. # define ZEND_SIGNAL_BLOCK_INTERRUPTIONS() SIGG(depth)++;
  71. # define ZEND_SIGNAL_UNBLOCK_INTERRUPTIONS() if (((SIGG(depth)--) == SIGG(blocked))) { zend_signal_handler_unblock(); }
  72. # endif /* not ZTS */
  73. ZEND_API void zend_signal_handler_unblock(void);
  74. void zend_signal_activate(void);
  75. void zend_signal_deactivate(void);
  76. BEGIN_EXTERN_C()
  77. ZEND_API void zend_signal_startup(void);
  78. END_EXTERN_C()
  79. void zend_signal_init(void);
  80. ZEND_API int zend_signal(int signo, void (*handler)(int));
  81. ZEND_API int zend_sigaction(int signo, const struct sigaction *act, struct sigaction *oldact);
  82. #else /* ZEND_SIGNALS */
  83. # define ZEND_SIGNAL_BLOCK_INTERRUPTIONS()
  84. # define ZEND_SIGNAL_UNBLOCK_INTERRUPTIONS()
  85. # define zend_signal_activate()
  86. # define zend_signal_deactivate()
  87. # define zend_signal_startup()
  88. # define zend_signal_init()
  89. # define zend_signal(signo, handler) signal(signo, handler)
  90. # define zend_sigaction(signo, act, oldact) sigaction(signo, act, oldact)
  91. #endif /* ZEND_SIGNALS */
  92. #endif /* ZEND_SIGNAL_H */
  93. /*
  94. * Local variables:
  95. * tab-width: 4
  96. * c-basic-offset: 4
  97. * indent-tabs-mode: t
  98. * End:
  99. * vim600: sw=4 ts=4 fdm=marker
  100. * vim<600: sw=4 ts=4
  101. */