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. Neither the name of the University nor the names of its contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * @(#)signalvar.h 8.6 (Berkeley) 2/19/95 30 * $FreeBSD: src/sys/sys/signalvar.h,v 1.34.2.1 2000/05/16 06:58:05 dillon Exp $ 31 */ 32 33 #ifndef _SYS_SIGNALVAR_H_ /* tmp for user.h */ 34 #define _SYS_SIGNALVAR_H_ 35 36 /* 37 * Don't bring in the entire bleeding include set if we aren't the kernel. 38 * Userland is not allowed to bring in sys/proc.h except under special 39 * circumstances (e.g. sys/user.h) 40 */ 41 #include <sys/signal.h> 42 #ifdef _KERNEL 43 #include <sys/proc.h> 44 #include <machine/lock.h> 45 #endif 46 47 /* 48 * Kernel signal definitions and data structures, 49 * not exported to user programs. 50 */ 51 52 /* 53 * Process signal actions and state, needed only within the process 54 * (not necessarily resident). 55 */ 56 struct sigacts { 57 sig_t ps_sigact[_SIG_MAXSIG]; /* disposition of signals */ 58 sigset_t ps_catchmask[_SIG_MAXSIG]; /* signals to be blocked */ 59 sigset_t ps_sigignore; /* Signals being ignored. */ 60 sigset_t ps_sigcatch; /* Signals being caught by user. */ 61 sigset_t ps_sigonstack; /* signals to take on sigstack */ 62 sigset_t ps_sigintr; /* signals that interrupt syscalls */ 63 sigset_t ps_sigreset; /* signals that reset when caught */ 64 sigset_t ps_signodefer; /* signals not masked while handled */ 65 sigset_t ps_siginfo; /* signals that want SA_SIGINFO args */ 66 sigset_t ps_usertramp; /* SunOS compat; libc sigtramp XXX */ 67 unsigned int ps_refcnt; 68 int ps_flag; 69 }; 70 71 /* additional signal action values, used only temporarily/internally */ 72 #define SIG_CATCH ((__sighandler_t *)2) 73 #define SIG_HOLD ((__sighandler_t *)3) 74 75 #ifdef _KERNEL 76 77 /* 78 * get signal action for process and signal; currently only for current process 79 */ 80 #define SIGACTION(p, sig) (p->p_sigacts->ps_sigact[_SIG_IDX(sig)]) 81 82 #endif 83 84 /* 85 * sigset_t manipulation macros 86 */ 87 #define SIGADDSET(set, signo) \ 88 (set).__bits[_SIG_WORD(signo)] |= _SIG_BIT(signo) 89 90 #define SIGADDSET_ATOMIC(set, signo) \ 91 atomic_set_int(&(set).__bits[_SIG_WORD(signo)], _SIG_BIT(signo)) 92 93 #define SIGDELSET(set, signo) \ 94 (set).__bits[_SIG_WORD(signo)] &= ~_SIG_BIT(signo) 95 96 #define SIGDELSET_ATOMIC(set, signo) \ 97 atomic_clear_int(&(set).__bits[_SIG_WORD(signo)], _SIG_BIT(signo)) 98 99 #define SIGEMPTYSET(set) \ 100 do { \ 101 int __i; \ 102 for (__i = 0; __i < _SIG_WORDS; __i++) \ 103 (set).__bits[__i] = 0; \ 104 } while (0) 105 106 #define SIGFILLSET(set) \ 107 do { \ 108 int __i; \ 109 for (__i = 0; __i < _SIG_WORDS; __i++) \ 110 (set).__bits[__i] = ~(unsigned int)0; \ 111 } while (0) 112 113 #define SIGISMEMBER(set, signo) \ 114 ((set).__bits[_SIG_WORD(signo)] & _SIG_BIT(signo)) 115 116 #define SIGISEMPTY(set) __sigisempty(&(set)) 117 #define SIGNOTEMPTY(set) (!__sigisempty(&(set))) 118 119 #define SIGSETEQ(set1, set2) __sigseteq(&(set1), &(set2)) 120 #define SIGSETNEQ(set1, set2) (!__sigseteq(&(set1), &(set2))) 121 122 #define SIGSETOR(set1, set2) \ 123 do { \ 124 int __i; \ 125 for (__i = 0; __i < _SIG_WORDS; __i++) \ 126 (set1).__bits[__i] |= (set2).__bits[__i]; \ 127 } while (0) 128 129 #define SIGSETAND(set1, set2) \ 130 do { \ 131 int __i; \ 132 for (__i = 0; __i < _SIG_WORDS; __i++) \ 133 (set1).__bits[__i] &= (set2).__bits[__i]; \ 134 } while (0) 135 136 #define SIGSETNAND(set1, set2) \ 137 do { \ 138 int __i; \ 139 for (__i = 0; __i < _SIG_WORDS; __i++) \ 140 (set1).__bits[__i] &= ~(set2).__bits[__i]; \ 141 } while (0) 142 143 #define SIG_CANTMASK(set) \ 144 SIGDELSET(set, SIGKILL), SIGDELSET(set, SIGSTOP) 145 146 #define SIG_STOPSIGMASK(set) \ 147 SIGDELSET(set, SIGSTOP), SIGDELSET(set, SIGTSTP), \ 148 SIGDELSET(set, SIGTTIN), SIGDELSET(set, SIGTTOU) 149 150 #define SIG_STOPSIGMASK_ATOMIC(set) \ 151 SIGDELSET_ATOMIC(set, SIGSTOP), SIGDELSET_ATOMIC(set, SIGTSTP), \ 152 SIGDELSET_ATOMIC(set, SIGTTIN), SIGDELSET_ATOMIC(set, SIGTTOU) 153 154 #define SIG_CONTSIGMASK(set) \ 155 SIGDELSET(set, SIGCONT) 156 157 #define SIG_CONTSIGMASK_ATOMIC(set) \ 158 SIGDELSET_ATOMIC(set, SIGCONT) 159 160 #define sigcantmask (sigmask(SIGKILL) | sigmask(SIGSTOP)) 161 162 static __inline int 163 __sigisempty(sigset_t *set) 164 { 165 int i; 166 167 for (i = 0; i < _SIG_WORDS; i++) { 168 if (set->__bits[i]) 169 return (0); 170 } 171 return (1); 172 } 173 174 static __inline int 175 __sigseteq(sigset_t *set1, sigset_t *set2) 176 { 177 int i; 178 179 for (i = 0; i < _SIG_WORDS; i++) { 180 if (set1->__bits[i] != set2->__bits[i]) 181 return (0); 182 } 183 return (1); 184 } 185 186 #ifdef _KERNEL 187 188 typedef void (*proc_func_t)(struct proc *); 189 190 struct pgrp; 191 struct proc; 192 struct sigio; 193 194 extern int sugid_coredump; /* Sysctl variable kern.sugid_coredump */ 195 196 /* 197 * Machine-independent functions: 198 */ 199 void execsigs (struct proc *p); 200 void gsignal (int pgid, int sig); 201 int issignal (struct lwp *lp, int maytrace, int *ptokp); 202 int iscaught (struct lwp *p); 203 void killproc (struct proc *p, char *why); 204 void pgsigio (struct sigio *, int signum, int checkctty); 205 void pgsignal (struct pgrp *pgrp, int sig, int checkctty); 206 void postsig (int sig, int ptok); 207 void ksignal (struct proc *p, int sig); 208 void lwpsignal (struct proc *p, struct lwp *lp, int sig); 209 void siginit (struct proc *p); 210 void trapsignal (struct lwp *p, int sig, u_long code); 211 212 /* 213 * Machine-dependent functions: 214 */ 215 void sendsig (sig_t action, int sig, sigset_t *retmask, u_long code); 216 void sigexit (struct lwp *lp, int sig) __dead2; 217 int checkpoint_signal_handler(struct lwp *p); 218 219 #endif /* _KERNEL */ 220 221 #endif /* !_SYS_SIGNALVAR_H_ */ 222