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: src/sys/sys/signalvar.h,v 1.34.2.1 2000/05/16 06:58:05 dillon Exp $ 35 * $DragonFly: src/sys/sys/signalvar.h,v 1.23 2008/04/21 15:47:58 dillon Exp $ 36 */ 37 38 #ifndef _SYS_SIGNALVAR_H_ /* tmp for user.h */ 39 #define _SYS_SIGNALVAR_H_ 40 41 /* 42 * Don't bring in the entire bleeding include set if we aren't the kernel. 43 * Userland is not allowed to bring in sys/proc.h except under special 44 * circumstances (e.g. sys/user.h) 45 */ 46 #include <sys/signal.h> 47 #ifdef _KERNEL 48 #include <sys/proc.h> 49 #include <machine/lock.h> 50 #endif 51 52 /* 53 * Kernel signal definitions and data structures, 54 * not exported to user programs. 55 */ 56 57 /* 58 * Process signal actions and state, needed only within the process 59 * (not necessarily resident). 60 */ 61 struct sigacts { 62 sig_t ps_sigact[_SIG_MAXSIG]; /* disposition of signals */ 63 sigset_t ps_catchmask[_SIG_MAXSIG]; /* signals to be blocked */ 64 sigset_t ps_sigignore; /* Signals being ignored. */ 65 sigset_t ps_sigcatch; /* Signals being caught by user. */ 66 sigset_t ps_sigonstack; /* signals to take on sigstack */ 67 sigset_t ps_sigintr; /* signals that interrupt syscalls */ 68 sigset_t ps_sigreset; /* signals that reset when caught */ 69 sigset_t ps_signodefer; /* signals not masked while handled */ 70 sigset_t ps_siginfo; /* signals that want SA_SIGINFO args */ 71 sigset_t ps_usertramp; /* SunOS compat; libc sigtramp XXX */ 72 unsigned int ps_refcnt; 73 int ps_flag; 74 }; 75 76 /* additional signal action values, used only temporarily/internally */ 77 #define SIG_CATCH ((__sighandler_t *)2) 78 #define SIG_HOLD ((__sighandler_t *)3) 79 80 #ifdef _KERNEL 81 82 /* 83 * get signal action for process and signal; currently only for current process 84 */ 85 #define SIGACTION(p, sig) (p->p_sigacts->ps_sigact[_SIG_IDX(sig)]) 86 87 #endif 88 89 /* 90 * sigset_t manipulation macros 91 */ 92 #define SIGADDSET(set, signo) \ 93 (set).__bits[_SIG_WORD(signo)] |= _SIG_BIT(signo) 94 95 #define SIGDELSET(set, signo) \ 96 (set).__bits[_SIG_WORD(signo)] &= ~_SIG_BIT(signo) 97 98 #define SIGEMPTYSET(set) \ 99 do { \ 100 int __i; \ 101 for (__i = 0; __i < _SIG_WORDS; __i++) \ 102 (set).__bits[__i] = 0; \ 103 } while (0) 104 105 #define SIGFILLSET(set) \ 106 do { \ 107 int __i; \ 108 for (__i = 0; __i < _SIG_WORDS; __i++) \ 109 (set).__bits[__i] = ~(unsigned int)0; \ 110 } while (0) 111 112 #define SIGISMEMBER(set, signo) \ 113 ((set).__bits[_SIG_WORD(signo)] & _SIG_BIT(signo)) 114 115 #define SIGISEMPTY(set) __sigisempty(&(set)) 116 #define SIGNOTEMPTY(set) (!__sigisempty(&(set))) 117 118 #define SIGSETEQ(set1, set2) __sigseteq(&(set1), &(set2)) 119 #define SIGSETNEQ(set1, set2) (!__sigseteq(&(set1), &(set2))) 120 121 #define SIGSETOR(set1, set2) \ 122 do { \ 123 int __i; \ 124 for (__i = 0; __i < _SIG_WORDS; __i++) \ 125 (set1).__bits[__i] |= (set2).__bits[__i]; \ 126 } while (0) 127 128 #define SIGSETAND(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 SIGSETNAND(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 SIG_CANTMASK(set) \ 143 SIGDELSET(set, SIGKILL), SIGDELSET(set, SIGSTOP) 144 145 #define SIG_STOPSIGMASK(set) \ 146 SIGDELSET(set, SIGSTOP), SIGDELSET(set, SIGTSTP), \ 147 SIGDELSET(set, SIGTTIN), SIGDELSET(set, SIGTTOU) 148 149 #define SIG_CONTSIGMASK(set) \ 150 SIGDELSET(set, SIGCONT) 151 152 #define sigcantmask (sigmask(SIGKILL) | sigmask(SIGSTOP)) 153 154 static __inline int 155 __sigisempty(sigset_t *set) 156 { 157 int i; 158 159 for (i = 0; i < _SIG_WORDS; i++) { 160 if (set->__bits[i]) 161 return (0); 162 } 163 return (1); 164 } 165 166 static __inline int 167 __sigseteq(sigset_t *set1, sigset_t *set2) 168 { 169 int i; 170 171 for (i = 0; i < _SIG_WORDS; i++) { 172 if (set1->__bits[i] != set2->__bits[i]) 173 return (0); 174 } 175 return (1); 176 } 177 178 #ifdef _KERNEL 179 180 typedef void (*proc_func_t)(struct proc *); 181 182 struct pgrp; 183 struct proc; 184 struct sigio; 185 struct vmupcall; 186 187 extern int sugid_coredump; /* Sysctl variable kern.sugid_coredump */ 188 189 /* 190 * Machine-independent functions: 191 */ 192 void execsigs (struct proc *p); 193 void gsignal (int pgid, int sig); 194 int issignal (struct lwp *lp, int maytrace); 195 int iscaught (struct lwp *p); 196 void killproc (struct proc *p, char *why); 197 void pgsigio (struct sigio *, int signum, int checkctty); 198 void pgsignal (struct pgrp *pgrp, int sig, int checkctty); 199 void postsig (int sig); 200 void ksignal (struct proc *p, int sig); 201 void lwpsignal (struct proc *p, struct lwp *lp, int sig); 202 void siginit (struct proc *p); 203 void trapsignal (struct lwp *p, int sig, u_long code); 204 205 /* 206 * Machine-dependent functions: 207 */ 208 void sendsig (sig_t action, int sig, sigset_t *retmask, u_long code); 209 void sendupcall (struct vmupcall *vu, int morepending); 210 int fetchupcall (struct vmupcall *vu, int morepending, void *rsp); 211 void sigexit (struct lwp *lp, int sig); 212 int checkpoint_signal_handler(struct lwp *p); 213 214 #endif /* _KERNEL */ 215 216 #endif /* !_SYS_SIGNALVAR_H_ */ 217