signal.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. #define sigmask(sig) (1UL << ((sig) - 1))
  83. #ifndef __HAVE_ARCH_SIG_SETOPS
  84. #include <linux/string.h>
  85. #define _SIG_SET_BINOP(name, op) \
  86. static inline void name(sigset_t *r, const sigset_t *a, const sigset_t *b) \
  87. { \
  88. extern void _NSIG_WORDS_is_unsupported_size(void); \
  89. unsigned long a0, a1, a2, a3, b0, b1, b2, b3; \
  90. \
  91. switch (_NSIG_WORDS) { \
  92. case 4: \
  93. a3 = a->sig[3]; a2 = a->sig[2]; \
  94. b3 = b->sig[3]; b2 = b->sig[2]; \
  95. r->sig[3] = op(a3, b3); \
  96. r->sig[2] = op(a2, b2); \
  97. case 2: \
  98. a1 = a->sig[1]; b1 = b->sig[1]; \
  99. r->sig[1] = op(a1, b1); \
  100. case 1: \
  101. a0 = a->sig[0]; b0 = b->sig[0]; \
  102. r->sig[0] = op(a0, b0); \
  103. break; \
  104. default: \
  105. _NSIG_WORDS_is_unsupported_size(); \
  106. } \
  107. }
  108. #define _sig_or(x,y) ((x) | (y))
  109. _SIG_SET_BINOP(sigorsets, _sig_or)
  110. #define _sig_and(x,y) ((x) & (y))
  111. _SIG_SET_BINOP(sigandsets, _sig_and)
  112. #define _sig_nand(x,y) ((x) & ~(y))
  113. _SIG_SET_BINOP(signandsets, _sig_nand)
  114. #undef _SIG_SET_BINOP
  115. #undef _sig_or
  116. #undef _sig_and
  117. #undef _sig_nand
  118. #define _SIG_SET_OP(name, op) \
  119. static inline void name(sigset_t *set) \
  120. { \
  121. extern void _NSIG_WORDS_is_unsupported_size(void); \
  122. \
  123. switch (_NSIG_WORDS) { \
  124. case 4: set->sig[3] = op(set->sig[3]); \
  125. set->sig[2] = op(set->sig[2]); \
  126. case 2: set->sig[1] = op(set->sig[1]); \
  127. case 1: set->sig[0] = op(set->sig[0]); \
  128. break; \
  129. default: \
  130. _NSIG_WORDS_is_unsupported_size(); \
  131. } \
  132. }
  133. #define _sig_not(x) (~(x))
  134. _SIG_SET_OP(signotset, _sig_not)
  135. #undef _SIG_SET_OP
  136. #undef _sig_not
  137. static inline void sigemptyset(sigset_t *set)
  138. {
  139. switch (_NSIG_WORDS) {
  140. default:
  141. memset(set, 0, sizeof(sigset_t));
  142. break;
  143. case 2: set->sig[1] = 0;
  144. case 1: set->sig[0] = 0;
  145. break;
  146. }
  147. }
  148. static inline void sigfillset(sigset_t *set)
  149. {
  150. switch (_NSIG_WORDS) {
  151. default:
  152. memset(set, -1, sizeof(sigset_t));
  153. break;
  154. case 2: set->sig[1] = -1;
  155. case 1: set->sig[0] = -1;
  156. break;
  157. }
  158. }
  159. /* Some extensions for manipulating the low 32 signals in particular. */
  160. static inline void sigaddsetmask(sigset_t *set, unsigned long mask)
  161. {
  162. set->sig[0] |= mask;
  163. }
  164. static inline void sigdelsetmask(sigset_t *set, unsigned long mask)
  165. {
  166. set->sig[0] &= ~mask;
  167. }
  168. static inline int sigtestsetmask(sigset_t *set, unsigned long mask)
  169. {
  170. return (set->sig[0] & mask) != 0;
  171. }
  172. static inline void siginitset(sigset_t *set, unsigned long mask)
  173. {
  174. set->sig[0] = mask;
  175. switch (_NSIG_WORDS) {
  176. default:
  177. memset(&set->sig[1], 0, sizeof(long)*(_NSIG_WORDS-1));
  178. break;
  179. case 2: set->sig[1] = 0;
  180. case 1: ;
  181. }
  182. }
  183. static inline void siginitsetinv(sigset_t *set, unsigned long mask)
  184. {
  185. set->sig[0] = ~mask;
  186. switch (_NSIG_WORDS) {
  187. default:
  188. memset(&set->sig[1], -1, sizeof(long)*(_NSIG_WORDS-1));
  189. break;
  190. case 2: set->sig[1] = -1;
  191. case 1: ;
  192. }
  193. }
  194. #endif /* __HAVE_ARCH_SIG_SETOPS */
  195. static inline void init_sigpending(struct sigpending *sig)
  196. {
  197. sigemptyset(&sig->signal);
  198. INIT_LIST_HEAD(&sig->list);
  199. }
  200. /* Test if 'sig' is valid signal. Use this instead of testing _NSIG directly */
  201. static inline int valid_signal(unsigned long sig)
  202. {
  203. return sig <= _NSIG ? 1 : 0;
  204. }
  205. extern int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p);
  206. extern int __group_send_sig_info(int, struct siginfo *, struct task_struct *);
  207. extern long do_sigpending(void __user *, unsigned long);
  208. extern int sigprocmask(int, sigset_t *, sigset_t *);
  209. struct pt_regs;
  210. extern int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka, struct pt_regs *regs, void *cookie);
  211. #endif /* __KERNEL__ */
  212. #endif /* _LINUX_SIGNAL_H */