signal.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. * As above, these correspond to the IORESOURCE_IRQ_* defines in
  20. * linux/ioport.h to select the interrupt line behaviour. When
  21. * requesting an interrupt without specifying a SA_TRIGGER, the
  22. * setting should be assumed to be "as already configured", which
  23. * may be as per machine or firmware initialisation.
  24. */
  25. #define SA_TRIGGER_LOW 0x00000008
  26. #define SA_TRIGGER_HIGH 0x00000004
  27. #define SA_TRIGGER_FALLING 0x00000002
  28. #define SA_TRIGGER_RISING 0x00000001
  29. #define SA_TRIGGER_MASK (SA_TRIGGER_HIGH|SA_TRIGGER_LOW|\
  30. SA_TRIGGER_RISING|SA_TRIGGER_FALLING)
  31. /*
  32. * Real Time signals may be queued.
  33. */
  34. struct sigqueue {
  35. struct list_head list;
  36. int flags;
  37. siginfo_t info;
  38. struct user_struct *user;
  39. };
  40. /* flags values. */
  41. #define SIGQUEUE_PREALLOC 1
  42. struct sigpending {
  43. struct list_head list;
  44. sigset_t signal;
  45. };
  46. /*
  47. * Define some primitives to manipulate sigset_t.
  48. */
  49. #ifndef __HAVE_ARCH_SIG_BITOPS
  50. #include <linux/bitops.h>
  51. /* We don't use <linux/bitops.h> for these because there is no need to
  52. be atomic. */
  53. static inline void sigaddset(sigset_t *set, int _sig)
  54. {
  55. unsigned long sig = _sig - 1;
  56. if (_NSIG_WORDS == 1)
  57. set->sig[0] |= 1UL << sig;
  58. else
  59. set->sig[sig / _NSIG_BPW] |= 1UL << (sig % _NSIG_BPW);
  60. }
  61. static inline void sigdelset(sigset_t *set, int _sig)
  62. {
  63. unsigned long sig = _sig - 1;
  64. if (_NSIG_WORDS == 1)
  65. set->sig[0] &= ~(1UL << sig);
  66. else
  67. set->sig[sig / _NSIG_BPW] &= ~(1UL << (sig % _NSIG_BPW));
  68. }
  69. static inline int sigismember(sigset_t *set, int _sig)
  70. {
  71. unsigned long sig = _sig - 1;
  72. if (_NSIG_WORDS == 1)
  73. return 1 & (set->sig[0] >> sig);
  74. else
  75. return 1 & (set->sig[sig / _NSIG_BPW] >> (sig % _NSIG_BPW));
  76. }
  77. static inline int sigfindinword(unsigned long word)
  78. {
  79. return ffz(~word);
  80. }
  81. #endif /* __HAVE_ARCH_SIG_BITOPS */
  82. static inline int sigisemptyset(sigset_t *set)
  83. {
  84. extern void _NSIG_WORDS_is_unsupported_size(void);
  85. switch (_NSIG_WORDS) {
  86. case 4:
  87. return (set->sig[3] | set->sig[2] |
  88. set->sig[1] | set->sig[0]) == 0;
  89. case 2:
  90. return (set->sig[1] | set->sig[0]) == 0;
  91. case 1:
  92. return set->sig[0] == 0;
  93. default:
  94. _NSIG_WORDS_is_unsupported_size();
  95. return 0;
  96. }
  97. }
  98. #define sigmask(sig) (1UL << ((sig) - 1))
  99. #ifndef __HAVE_ARCH_SIG_SETOPS
  100. #include <linux/string.h>
  101. #define _SIG_SET_BINOP(name, op) \
  102. static inline void name(sigset_t *r, const sigset_t *a, const sigset_t *b) \
  103. { \
  104. extern void _NSIG_WORDS_is_unsupported_size(void); \
  105. unsigned long a0, a1, a2, a3, b0, b1, b2, b3; \
  106. \
  107. switch (_NSIG_WORDS) { \
  108. case 4: \
  109. a3 = a->sig[3]; a2 = a->sig[2]; \
  110. b3 = b->sig[3]; b2 = b->sig[2]; \
  111. r->sig[3] = op(a3, b3); \
  112. r->sig[2] = op(a2, b2); \
  113. case 2: \
  114. a1 = a->sig[1]; b1 = b->sig[1]; \
  115. r->sig[1] = op(a1, b1); \
  116. case 1: \
  117. a0 = a->sig[0]; b0 = b->sig[0]; \
  118. r->sig[0] = op(a0, b0); \
  119. break; \
  120. default: \
  121. _NSIG_WORDS_is_unsupported_size(); \
  122. } \
  123. }
  124. #define _sig_or(x,y) ((x) | (y))
  125. _SIG_SET_BINOP(sigorsets, _sig_or)
  126. #define _sig_and(x,y) ((x) & (y))
  127. _SIG_SET_BINOP(sigandsets, _sig_and)
  128. #define _sig_nand(x,y) ((x) & ~(y))
  129. _SIG_SET_BINOP(signandsets, _sig_nand)
  130. #undef _SIG_SET_BINOP
  131. #undef _sig_or
  132. #undef _sig_and
  133. #undef _sig_nand
  134. #define _SIG_SET_OP(name, op) \
  135. static inline void name(sigset_t *set) \
  136. { \
  137. extern void _NSIG_WORDS_is_unsupported_size(void); \
  138. \
  139. switch (_NSIG_WORDS) { \
  140. case 4: set->sig[3] = op(set->sig[3]); \
  141. set->sig[2] = op(set->sig[2]); \
  142. case 2: set->sig[1] = op(set->sig[1]); \
  143. case 1: set->sig[0] = op(set->sig[0]); \
  144. break; \
  145. default: \
  146. _NSIG_WORDS_is_unsupported_size(); \
  147. } \
  148. }
  149. #define _sig_not(x) (~(x))
  150. _SIG_SET_OP(signotset, _sig_not)
  151. #undef _SIG_SET_OP
  152. #undef _sig_not
  153. static inline void sigemptyset(sigset_t *set)
  154. {
  155. switch (_NSIG_WORDS) {
  156. default:
  157. memset(set, 0, sizeof(sigset_t));
  158. break;
  159. case 2: set->sig[1] = 0;
  160. case 1: set->sig[0] = 0;
  161. break;
  162. }
  163. }
  164. static inline void sigfillset(sigset_t *set)
  165. {
  166. switch (_NSIG_WORDS) {
  167. default:
  168. memset(set, -1, sizeof(sigset_t));
  169. break;
  170. case 2: set->sig[1] = -1;
  171. case 1: set->sig[0] = -1;
  172. break;
  173. }
  174. }
  175. /* Some extensions for manipulating the low 32 signals in particular. */
  176. static inline void sigaddsetmask(sigset_t *set, unsigned long mask)
  177. {
  178. set->sig[0] |= mask;
  179. }
  180. static inline void sigdelsetmask(sigset_t *set, unsigned long mask)
  181. {
  182. set->sig[0] &= ~mask;
  183. }
  184. static inline int sigtestsetmask(sigset_t *set, unsigned long mask)
  185. {
  186. return (set->sig[0] & mask) != 0;
  187. }
  188. static inline void siginitset(sigset_t *set, unsigned long mask)
  189. {
  190. set->sig[0] = mask;
  191. switch (_NSIG_WORDS) {
  192. default:
  193. memset(&set->sig[1], 0, sizeof(long)*(_NSIG_WORDS-1));
  194. break;
  195. case 2: set->sig[1] = 0;
  196. case 1: ;
  197. }
  198. }
  199. static inline void siginitsetinv(sigset_t *set, unsigned long mask)
  200. {
  201. set->sig[0] = ~mask;
  202. switch (_NSIG_WORDS) {
  203. default:
  204. memset(&set->sig[1], -1, sizeof(long)*(_NSIG_WORDS-1));
  205. break;
  206. case 2: set->sig[1] = -1;
  207. case 1: ;
  208. }
  209. }
  210. #endif /* __HAVE_ARCH_SIG_SETOPS */
  211. static inline void init_sigpending(struct sigpending *sig)
  212. {
  213. sigemptyset(&sig->signal);
  214. INIT_LIST_HEAD(&sig->list);
  215. }
  216. /* Test if 'sig' is valid signal. Use this instead of testing _NSIG directly */
  217. static inline int valid_signal(unsigned long sig)
  218. {
  219. return sig <= _NSIG ? 1 : 0;
  220. }
  221. extern int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p);
  222. extern int __group_send_sig_info(int, struct siginfo *, struct task_struct *);
  223. extern long do_sigpending(void __user *, unsigned long);
  224. extern int sigprocmask(int, sigset_t *, sigset_t *);
  225. struct pt_regs;
  226. extern int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka, struct pt_regs *regs, void *cookie);
  227. #endif /* __KERNEL__ */
  228. #endif /* _LINUX_SIGNAL_H */