signalvar.h revision 114754
1/* 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by the University of 16 * California, Berkeley and its contributors. 17 * 4. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)signalvar.h 8.6 (Berkeley) 2/19/95 34 * $FreeBSD: head/sys/sys/signalvar.h 114754 2003-05-05 21:16:28Z jhb $ 35 */ 36 37#ifndef _SYS_SIGNALVAR_H_ 38#define _SYS_SIGNALVAR_H_ 39 40#include <sys/signal.h> 41 42/* 43 * Kernel signal definitions and data structures, 44 * not exported to user programs. 45 */ 46 47/* 48 * Process signal actions and state, needed only within the process 49 * (not necessarily resident). 50 */ 51struct sigacts { 52 sig_t ps_sigact[_SIG_MAXSIG]; /* Disposition of signals. */ 53 sigset_t ps_catchmask[_SIG_MAXSIG]; /* Signals to be blocked. */ 54 sigset_t ps_sigonstack; /* Signals to take on sigstack. */ 55 sigset_t ps_sigintr; /* Signals that interrupt syscalls. */ 56 sigset_t ps_sigreset; /* Signals that reset when caught. */ 57 sigset_t ps_signodefer; /* Signals not masked while handled. */ 58 sigset_t ps_siginfo; /* Signals that want SA_SIGINFO args. */ 59 sigset_t ps_freebsd4; /* Signals using freebsd4 ucontext. */ 60 sigset_t ps_osigset; /* Signals using <= 3.x osigset_t. */ 61 sigset_t ps_usertramp; /* SunOS compat; libc sigtramp XXX. */ 62}; 63 64#if defined(_KERNEL) && defined(COMPAT_43) 65/* 66 * Compatibility. 67 */ 68typedef struct { 69 struct osigcontext si_sc; 70 int si_signo; 71 int si_code; 72 union sigval si_value; 73} osiginfo_t; 74 75struct osigaction { 76 union { 77 void (*__sa_handler)(int); 78 void (*__sa_sigaction)(int, osiginfo_t *, void *); 79 } __sigaction_u; /* signal handler */ 80 osigset_t sa_mask; /* signal mask to apply */ 81 int sa_flags; /* see signal options below */ 82}; 83 84typedef void __osiginfohandler_t(int, osiginfo_t *, void *); 85#endif /* _KERNEL && COMPAT_43 */ 86 87/* additional signal action values, used only temporarily/internally */ 88#define SIG_CATCH ((__sighandler_t *)2) 89#define SIG_HOLD ((__sighandler_t *)3) 90 91/* 92 * get signal action for process and signal; currently only for current process 93 */ 94#define SIGACTION(p, sig) (p->p_sigacts->ps_sigact[_SIG_IDX(sig)]) 95 96/* 97 * sigset_t manipulation macros 98 */ 99#define SIGADDSET(set, signo) \ 100 ((set).__bits[_SIG_WORD(signo)] |= _SIG_BIT(signo)) 101 102#define SIGDELSET(set, signo) \ 103 ((set).__bits[_SIG_WORD(signo)] &= ~_SIG_BIT(signo)) 104 105#define SIGEMPTYSET(set) \ 106 do { \ 107 int __i; \ 108 for (__i = 0; __i < _SIG_WORDS; __i++) \ 109 (set).__bits[__i] = 0; \ 110 } while (0) 111 112#define SIGFILLSET(set) \ 113 do { \ 114 int __i; \ 115 for (__i = 0; __i < _SIG_WORDS; __i++) \ 116 (set).__bits[__i] = ~0U; \ 117 } while (0) 118 119#define SIGISMEMBER(set, signo) \ 120 ((set).__bits[_SIG_WORD(signo)] & _SIG_BIT(signo)) 121 122#define SIGISEMPTY(set) (__sigisempty(&(set))) 123#define SIGNOTEMPTY(set) (!__sigisempty(&(set))) 124 125#define SIGSETEQ(set1, set2) (__sigseteq(&(set1), &(set2))) 126#define SIGSETNEQ(set1, set2) (!__sigseteq(&(set1), &(set2))) 127 128#define SIGSETOR(set1, set2) \ 129 do { \ 130 int __i; \ 131 for (__i = 0; __i < _SIG_WORDS; __i++) \ 132 (set1).__bits[__i] |= (set2).__bits[__i]; \ 133 } while (0) 134 135#define SIGSETAND(set1, set2) \ 136 do { \ 137 int __i; \ 138 for (__i = 0; __i < _SIG_WORDS; __i++) \ 139 (set1).__bits[__i] &= (set2).__bits[__i]; \ 140 } while (0) 141 142#define SIGSETNAND(set1, set2) \ 143 do { \ 144 int __i; \ 145 for (__i = 0; __i < _SIG_WORDS; __i++) \ 146 (set1).__bits[__i] &= ~(set2).__bits[__i]; \ 147 } while (0) 148 149#define SIGSETLO(set1, set2) ((set1).__bits[0] = (set2).__bits[0]) 150#define SIGSETOLD(set, oset) ((set).__bits[0] = (oset)) 151 152#define SIG_CANTMASK(set) \ 153 SIGDELSET(set, SIGKILL), SIGDELSET(set, SIGSTOP) 154 155#define SIG_STOPSIGMASK(set) \ 156 SIGDELSET(set, SIGSTOP), SIGDELSET(set, SIGTSTP), \ 157 SIGDELSET(set, SIGTTIN), SIGDELSET(set, SIGTTOU) 158 159#define SIG_CONTSIGMASK(set) \ 160 SIGDELSET(set, SIGCONT) 161 162#define sigcantmask (sigmask(SIGKILL) | sigmask(SIGSTOP)) 163 164#define SIG2OSIG(sig, osig) (osig = (sig).__bits[0]) 165#define OSIG2SIG(osig, sig) SIGEMPTYSET(sig); (sig).__bits[0] = osig 166 167static __inline int 168__sigisempty(sigset_t *set) 169{ 170 int i; 171 172 for (i = 0; i < _SIG_WORDS; i++) { 173 if (set->__bits[i]) 174 return (0); 175 } 176 return (1); 177} 178 179static __inline int 180__sigseteq(sigset_t *set1, sigset_t *set2) 181{ 182 int i; 183 184 for (i = 0; i < _SIG_WORDS; i++) { 185 if (set1->__bits[i] != set2->__bits[i]) 186 return (0); 187 } 188 return (1); 189} 190 191#ifdef _KERNEL 192 193/* Return nonzero if process p has an unmasked pending signal. */ 194#define SIGPENDING(td) \ 195 (!SIGISEMPTY((td)->td_siglist) && \ 196 (!sigsetmasked(&(td)->td_siglist, &(td)->td_sigmask) || \ 197 (td)->td_proc->p_flag & P_TRACED)) 198 199/* 200 * Return the value of the pseudo-expression ((*set & ~*mask) != 0). This 201 * is an optimized version of SIGISEMPTY() on a temporary variable 202 * containing SIGSETNAND(*set, *mask). 203 */ 204static __inline int 205sigsetmasked(sigset_t *set, sigset_t *mask) 206{ 207 int i; 208 209 for (i = 0; i < _SIG_WORDS; i++) { 210 if (set->__bits[i] & ~mask->__bits[i]) 211 return (0); 212 } 213 return (1); 214} 215 216struct pgrp; 217struct thread; 218struct proc; 219struct sigio; 220struct mtx; 221 222extern int sugid_coredump; /* Sysctl variable kern.sugid_coredump */ 223extern struct mtx sigio_lock; 224 225/* 226 * Lock the pointers for a sigio object in the underlying objects of 227 * a file descriptor. 228 */ 229#define SIGIO_LOCK() mtx_lock(&sigio_lock) 230#define SIGIO_TRYLOCK() mtx_trylock(&sigio_lock) 231#define SIGIO_UNLOCK() mtx_unlock(&sigio_lock) 232#define SIGIO_LOCKED() mtx_owned(&sigio_lock) 233#define SIGIO_ASSERT(type) mtx_assert(&sigio_lock, type) 234 235/* 236 * Machine-independent functions: 237 */ 238int cursig(struct thread *td); 239void execsigs(struct proc *p); 240void gsignal(int pgid, int sig); 241void killproc(struct proc *p, char *why); 242void pgsigio(struct sigio **, int signum, int checkctty); 243void pgsignal(struct pgrp *pgrp, int sig, int checkctty); 244void postsig(int sig); 245void psignal(struct proc *p, int sig); 246void sigexit(struct thread *td, int signum) __dead2; 247int sig_ffs(sigset_t *set); 248void siginit(struct proc *p); 249void signotify(struct thread *td); 250void tdsignal(struct thread *td, int sig); 251void trapsignal(struct thread *td, int sig, u_long code); 252 253/* 254 * Machine-dependent functions: 255 */ 256void sendsig(sig_t action, int sig, sigset_t *retmask, u_long code); 257 258#endif /* _KERNEL */ 259 260#endif /* !_SYS_SIGNALVAR_H_ */ 261