signal.h 5.3 KB

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