zend_signal.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Zend Signal Handling |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 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. | https://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. #include <signal.h>
  23. #ifndef NSIG
  24. #define NSIG 65
  25. #endif
  26. #ifndef ZEND_SIGNAL_QUEUE_SIZE
  27. #define ZEND_SIGNAL_QUEUE_SIZE 64
  28. #endif
  29. /* Signal structs */
  30. typedef struct _zend_signal_entry_t {
  31. int flags; /* sigaction style flags */
  32. void* handler; /* signal handler or context */
  33. } zend_signal_entry_t;
  34. typedef struct _zend_signal_t {
  35. int signo;
  36. siginfo_t *siginfo;
  37. void* context;
  38. } zend_signal_t;
  39. typedef struct _zend_signal_queue_t {
  40. zend_signal_t zend_signal;
  41. struct _zend_signal_queue_t *next;
  42. } zend_signal_queue_t;
  43. /* Signal Globals */
  44. typedef struct _zend_signal_globals_t {
  45. int depth;
  46. int blocked; /* 1==TRUE, 0==FALSE */
  47. int running; /* in signal handler execution */
  48. int active; /* internal signal handling is enabled */
  49. bool check; /* check for replaced handlers on shutdown */
  50. bool reset; /* reset signal handlers on each request */
  51. zend_signal_entry_t handlers[NSIG];
  52. zend_signal_queue_t pstorage[ZEND_SIGNAL_QUEUE_SIZE], *phead, *ptail, *pavail; /* pending queue */
  53. } zend_signal_globals_t;
  54. # ifdef ZTS
  55. # define SIGG(v) ZEND_TSRMG_FAST(zend_signal_globals_offset, zend_signal_globals_t *, v)
  56. BEGIN_EXTERN_C()
  57. ZEND_API extern int zend_signal_globals_id;
  58. ZEND_API extern size_t zend_signal_globals_offset;
  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 void zend_signal(int signo, void (*handler)(int));
  81. ZEND_API void 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 */