shim_signal.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. #ifndef _SHIM_SIGNAL_H_
  4. #define _SHIM_SIGNAL_H_
  5. #include <shim_types.h>
  6. #include <shim_defs.h>
  7. #include <shim_thread.h>
  8. struct shim_signal_handle {
  9. /* sigaction */
  10. struct __kernel_sigaction * action;
  11. };
  12. #define NUM_SIGS 64
  13. #define NUM_KNOWN_SIGS 22
  14. # define BITS_PER_WORD sizeof(unsigned long)
  15. /* The standard def of this macro is dumb */
  16. #undef _SIGSET_NWORDS
  17. # define _SIGSET_NWORDS (NUM_SIGS / BITS_PER_WORD)
  18. /* Return a mask that includes the bit for SIG only. */
  19. # define __sigmask(sig) \
  20. (((unsigned long int) 1) << (((sig) - 1) % (8 * sizeof (unsigned long int))))
  21. /* Return the word index for SIG. */
  22. # define __sigword(sig) (((sig) - 1) / (8 * sizeof (unsigned long int)))
  23. /* Clear all signals from SET. */
  24. # define __sigemptyset(set) \
  25. (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
  26. sigset_t *__set = (set); \
  27. while (--__cnt >= 0) __set->__val[__cnt] = 0; \
  28. 0; }))
  29. /* Set all signals in SET. */
  30. # define __sigfillset(set) \
  31. (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
  32. sigset_t *__set = (set); \
  33. while (--__cnt >= 0) __set->__val[__cnt] = ~0UL; \
  34. 0; }))
  35. # define __sigisemptyset(set) \
  36. (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
  37. const sigset_t *__set = (set); \
  38. int __ret = __set->__val[--__cnt]; \
  39. while (!__ret && --__cnt >= 0) \
  40. __ret = __set->__val[__cnt]; \
  41. __ret == 0; }))
  42. # define __sigandset(dest, left, right) \
  43. (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
  44. sigset_t *__dest = (dest); \
  45. const sigset_t *__left = (left); \
  46. const sigset_t *__right = (right); \
  47. while (--__cnt >= 0) \
  48. __dest->__val[__cnt] = (__left->__val[__cnt] \
  49. & __right->__val[__cnt]); \
  50. 0; }))
  51. # define __sigorset(dest, left, right) \
  52. (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
  53. sigset_t *__dest = (dest); \
  54. const sigset_t *__left = (left); \
  55. const sigset_t *__right = (right); \
  56. while (--__cnt >= 0) \
  57. __dest->__val[__cnt] = (__left->__val[__cnt] \
  58. | __right->__val[__cnt]); \
  59. 0; }))
  60. # define __signotset(dest, left, right) \
  61. (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
  62. sigset_t *__dest = (dest); \
  63. const sigset_t *__left = (left); \
  64. const sigset_t *__right = (right); \
  65. while (--__cnt >= 0) \
  66. __dest->__val[__cnt] = (__left->__val[__cnt] \
  67. & ~__right->__val[__cnt]); \
  68. 0; }))
  69. # define __SIGSETFN(NAME, BODY, CONST) \
  70. static inline int \
  71. NAME (CONST __sigset_t *__set, int __sig) \
  72. { \
  73. unsigned long int __mask = __sigmask (__sig); \
  74. unsigned long int __word = __sigword (__sig); \
  75. return BODY; \
  76. }
  77. __SIGSETFN (shim_sigismember, (__set->__val[__word] & __mask) ? 1 : 0, __const)
  78. __SIGSETFN (shim_sigaddset, ((__set->__val[__word] |= __mask), 0), )
  79. __SIGSETFN (shim_sigdelset, ((__set->__val[__word] &= ~__mask), 0), )
  80. #define __sigismember shim_sigismember
  81. #define __sigaddset shim_sigaddset
  82. #define __sigdelset shim_sigdelset
  83. /* NB: Check shim_signal.c if this changes. Some memset(0) elision*/
  84. struct shim_signal {
  85. siginfo_t info;
  86. bool context_stored;
  87. ucontext_t context;
  88. };
  89. #define MAX_SIGNAL_LOG 32
  90. struct shim_signal_log {
  91. struct shim_atomic head, tail;
  92. struct shim_signal * logs[MAX_SIGNAL_LOG];
  93. };
  94. struct shim_thread;
  95. int init_signal (void);
  96. void __store_context (shim_tcb_t * tcb, PAL_CONTEXT * pal_context,
  97. struct shim_signal * signal);
  98. void append_signal (struct shim_thread * thread, int sig, siginfo_t * info);
  99. void deliver_signal (siginfo_t * info, PAL_CONTEXT * context);
  100. sigset_t * get_sig_mask (struct shim_thread * thread);
  101. sigset_t * set_sig_mask (struct shim_thread * thread, sigset_t * new_set);
  102. extern const char * const siglist[NUM_KNOWN_SIGS + 1];
  103. int do_kill_thread (IDTYPE sender, IDTYPE tgid, IDTYPE tid, int sig,
  104. bool use_ipc);
  105. int do_kill_proc (IDTYPE sender, IDTYPE tgid, int sig, bool use_ipc);
  106. int do_kill_pgroup (IDTYPE sender, IDTYPE pgid, int sig, bool use_ipc);
  107. int broadcast_signal (IDTYPE sender, int sig);
  108. int kill_all_threads (struct shim_thread * cur, IDTYPE sender, int sig);
  109. #endif /* _SHIM_SIGNAL_H_ */