signal.h 6.3 KB

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