signal.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. #ifndef _LINUX_SIGNAL_H
  2. #define _LINUX_SIGNAL_H
  3. #include <linux/list.h>
  4. #include <linux/spinlock.h>
  5. #include <asm/signal.h>
  6. #include <asm/siginfo.h>
  7. #ifdef __KERNEL__
  8. /*
  9. * Real Time signals may be queued.
  10. */
  11. struct sigqueue {
  12. struct list_head list;
  13. spinlock_t *lock;
  14. int flags;
  15. siginfo_t info;
  16. struct user_struct *user;
  17. };
  18. /* flags values. */
  19. #define SIGQUEUE_PREALLOC 1
  20. struct sigpending {
  21. struct list_head list;
  22. sigset_t signal;
  23. };
  24. /*
  25. * Define some primitives to manipulate sigset_t.
  26. */
  27. #ifndef __HAVE_ARCH_SIG_BITOPS
  28. #include <linux/bitops.h>
  29. /* We don't use <linux/bitops.h> for these because there is no need to
  30. be atomic. */
  31. static inline void sigaddset(sigset_t *set, int _sig)
  32. {
  33. unsigned long sig = _sig - 1;
  34. if (_NSIG_WORDS == 1)
  35. set->sig[0] |= 1UL << sig;
  36. else
  37. set->sig[sig / _NSIG_BPW] |= 1UL << (sig % _NSIG_BPW);
  38. }
  39. static inline void sigdelset(sigset_t *set, int _sig)
  40. {
  41. unsigned long sig = _sig - 1;
  42. if (_NSIG_WORDS == 1)
  43. set->sig[0] &= ~(1UL << sig);
  44. else
  45. set->sig[sig / _NSIG_BPW] &= ~(1UL << (sig % _NSIG_BPW));
  46. }
  47. static inline int sigismember(sigset_t *set, int _sig)
  48. {
  49. unsigned long sig = _sig - 1;
  50. if (_NSIG_WORDS == 1)
  51. return 1 & (set->sig[0] >> sig);
  52. else
  53. return 1 & (set->sig[sig / _NSIG_BPW] >> (sig % _NSIG_BPW));
  54. }
  55. static inline int sigfindinword(unsigned long word)
  56. {
  57. return ffz(~word);
  58. }
  59. #endif /* __HAVE_ARCH_SIG_BITOPS */
  60. #define sigmask(sig) (1UL << ((sig) - 1))
  61. #ifndef __HAVE_ARCH_SIG_SETOPS
  62. #include <linux/string.h>
  63. #define _SIG_SET_BINOP(name, op) \
  64. static inline void name(sigset_t *r, const sigset_t *a, const sigset_t *b) \
  65. { \
  66. extern void _NSIG_WORDS_is_unsupported_size(void); \
  67. unsigned long a0, a1, a2, a3, b0, b1, b2, b3; \
  68. \
  69. switch (_NSIG_WORDS) { \
  70. case 4: \
  71. a3 = a->sig[3]; a2 = a->sig[2]; \
  72. b3 = b->sig[3]; b2 = b->sig[2]; \
  73. r->sig[3] = op(a3, b3); \
  74. r->sig[2] = op(a2, b2); \
  75. case 2: \
  76. a1 = a->sig[1]; b1 = b->sig[1]; \
  77. r->sig[1] = op(a1, b1); \
  78. case 1: \
  79. a0 = a->sig[0]; b0 = b->sig[0]; \
  80. r->sig[0] = op(a0, b0); \
  81. break; \
  82. default: \
  83. _NSIG_WORDS_is_unsupported_size(); \
  84. } \
  85. }
  86. #define _sig_or(x,y) ((x) | (y))
  87. _SIG_SET_BINOP(sigorsets, _sig_or)
  88. #define _sig_and(x,y) ((x) & (y))
  89. _SIG_SET_BINOP(sigandsets, _sig_and)
  90. #define _sig_nand(x,y) ((x) & ~(y))
  91. _SIG_SET_BINOP(signandsets, _sig_nand)
  92. #undef _SIG_SET_BINOP
  93. #undef _sig_or
  94. #undef _sig_and
  95. #undef _sig_nand
  96. #define _SIG_SET_OP(name, op) \
  97. static inline void name(sigset_t *set) \
  98. { \
  99. extern void _NSIG_WORDS_is_unsupported_size(void); \
  100. \
  101. switch (_NSIG_WORDS) { \
  102. case 4: set->sig[3] = op(set->sig[3]); \
  103. set->sig[2] = op(set->sig[2]); \
  104. case 2: set->sig[1] = op(set->sig[1]); \
  105. case 1: set->sig[0] = op(set->sig[0]); \
  106. break; \
  107. default: \
  108. _NSIG_WORDS_is_unsupported_size(); \
  109. } \
  110. }
  111. #define _sig_not(x) (~(x))
  112. _SIG_SET_OP(signotset, _sig_not)
  113. #undef _SIG_SET_OP
  114. #undef _sig_not
  115. static inline void sigemptyset(sigset_t *set)
  116. {
  117. switch (_NSIG_WORDS) {
  118. default:
  119. memset(set, 0, sizeof(sigset_t));
  120. break;
  121. case 2: set->sig[1] = 0;
  122. case 1: set->sig[0] = 0;
  123. break;
  124. }
  125. }
  126. static inline void sigfillset(sigset_t *set)
  127. {
  128. switch (_NSIG_WORDS) {
  129. default:
  130. memset(set, -1, sizeof(sigset_t));
  131. break;
  132. case 2: set->sig[1] = -1;
  133. case 1: set->sig[0] = -1;
  134. break;
  135. }
  136. }
  137. /* Some extensions for manipulating the low 32 signals in particular. */
  138. static inline void sigaddsetmask(sigset_t *set, unsigned long mask)
  139. {
  140. set->sig[0] |= mask;
  141. }
  142. static inline void sigdelsetmask(sigset_t *set, unsigned long mask)
  143. {
  144. set->sig[0] &= ~mask;
  145. }
  146. static inline int sigtestsetmask(sigset_t *set, unsigned long mask)
  147. {
  148. return (set->sig[0] & mask) != 0;
  149. }
  150. static inline void siginitset(sigset_t *set, unsigned long mask)
  151. {
  152. set->sig[0] = mask;
  153. switch (_NSIG_WORDS) {
  154. default:
  155. memset(&set->sig[1], 0, sizeof(long)*(_NSIG_WORDS-1));
  156. break;
  157. case 2: set->sig[1] = 0;
  158. case 1: ;
  159. }
  160. }
  161. static inline void siginitsetinv(sigset_t *set, unsigned long mask)
  162. {
  163. set->sig[0] = ~mask;
  164. switch (_NSIG_WORDS) {
  165. default:
  166. memset(&set->sig[1], -1, sizeof(long)*(_NSIG_WORDS-1));
  167. break;
  168. case 2: set->sig[1] = -1;
  169. case 1: ;
  170. }
  171. }
  172. #endif /* __HAVE_ARCH_SIG_SETOPS */
  173. static inline void init_sigpending(struct sigpending *sig)
  174. {
  175. sigemptyset(&sig->signal);
  176. INIT_LIST_HEAD(&sig->list);
  177. }
  178. extern int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p);
  179. extern int __group_send_sig_info(int, struct siginfo *, struct task_struct *);
  180. extern long do_sigpending(void __user *, unsigned long);
  181. extern int sigprocmask(int, sigset_t *, sigset_t *);
  182. #ifndef HAVE_ARCH_GET_SIGNAL_TO_DELIVER
  183. struct pt_regs;
  184. extern int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka, struct pt_regs *regs, void *cookie);
  185. #endif
  186. #endif /* __KERNEL__ */
  187. #endif /* _LINUX_SIGNAL_H */