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