signalvar.h revision 58717
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 58717 2000-03-28 07:16:37Z dillon $ 35 */ 36 37#ifndef _SYS_SIGNALVAR_H_ /* tmp for user.h */ 38#define _SYS_SIGNALVAR_H_ 39 40#include <sys/signal.h> 41#include <sys/proc.h> 42#ifdef SMP 43#include <machine/smp.h> 44#endif 45 46/* 47 * Kernel signal definitions and data structures, 48 * not exported to user programs. 49 */ 50 51/* 52 * Process signal actions and state, needed only within the process 53 * (not necessarily resident). 54 */ 55struct sigacts { 56 sig_t ps_sigact[_SIG_MAXSIG]; /* disposition of signals */ 57 sigset_t ps_catchmask[_SIG_MAXSIG]; /* signals to be blocked */ 58 sigset_t ps_sigonstack; /* signals to take on sigstack */ 59 sigset_t ps_sigintr; /* signals that interrupt syscalls */ 60 sigset_t ps_sigreset; /* signals that reset when caught */ 61 sigset_t ps_signodefer; /* signals not masked while handled */ 62 sigset_t ps_siginfo; /* signals that want SA_SIGINFO args */ 63 sigset_t ps_osigset; /* signals that use osigset_t */ 64 sigset_t ps_usertramp; /* SunOS compat; libc sigtramp XXX */ 65}; 66 67/* 68 * Compatibility. 69 */ 70typedef struct { 71 struct osigcontext si_sc; 72 int si_signo; 73 int si_code; 74 union sigval si_value; 75} osiginfo_t; 76 77struct osigaction { 78 union { 79 void (*__sa_handler) __P((int)); 80 void (*__sa_sigaction) __P((int, osiginfo_t *, void *)); 81 } __sigaction_u; /* signal handler */ 82 osigset_t sa_mask; /* signal mask to apply */ 83 int sa_flags; /* see signal options below */ 84}; 85 86typedef void __osiginfohandler_t __P((int, osiginfo_t *, void *)); 87 88/* additional signal action values, used only temporarily/internally */ 89#define SIG_CATCH ((__sighandler_t *)2) 90#define SIG_HOLD ((__sighandler_t *)3) 91 92/* 93 * get signal action for process and signal; currently only for current process 94 */ 95#define SIGACTION(p, sig) (p->p_sigacts->ps_sigact[_SIG_IDX(sig)]) 96 97/* 98 * sigset_t manipulation macros 99 */ 100#define SIGADDSET(set, signo) \ 101 (set).__bits[_SIG_WORD(signo)] |= _SIG_BIT(signo) 102 103#define SIGDELSET(set, signo) \ 104 (set).__bits[_SIG_WORD(signo)] &= ~_SIG_BIT(signo) 105 106#define SIGEMPTYSET(set) \ 107 do { \ 108 int __i; \ 109 for (__i = 0; __i < _SIG_WORDS; __i++) \ 110 (set).__bits[__i] = 0; \ 111 } while (0) 112 113#define SIGFILLSET(set) \ 114 do { \ 115 int __i; \ 116 for (__i = 0; __i < _SIG_WORDS; __i++) \ 117 (set).__bits[__i] = ~(unsigned int)0; \ 118 } while (0) 119 120#define SIGISMEMBER(set, signo) \ 121 ((set).__bits[_SIG_WORD(signo)] & _SIG_BIT(signo)) 122 123#define SIGISEMPTY(set) __sigisempty(&(set)) 124#define SIGNOTEMPTY(set) (!__sigisempty(&(set))) 125 126#define SIGSETEQ(set1, set2) __sigseteq(&(set1), &(set2)) 127#define SIGSETNEQ(set1, set2) (!__sigseteq(&(set1), &(set2))) 128 129#define SIGSETOR(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 SIGSETAND(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 SIGSETNAND(set1, set2) \ 144 do { \ 145 int __i; \ 146 for (__i = 0; __i < _SIG_WORDS; __i++) \ 147 (set1).__bits[__i] &= ~(set2).__bits[__i]; \ 148 } while (0) 149 150#define SIGSETLO(set1, set2) ((set1).__bits[0] = (set2).__bits[0]) 151#define SIGSETOLD(set, oset) ((set).__bits[0] = (oset)) 152 153#define SIG_CANTMASK(set) \ 154 SIGDELSET(set, SIGKILL), SIGDELSET(set, SIGSTOP) 155 156#define SIG_STOPSIGMASK(set) \ 157 SIGDELSET(set, SIGSTOP), SIGDELSET(set, SIGTSTP), \ 158 SIGDELSET(set, SIGTTIN), SIGDELSET(set, SIGTTOU) 159 160#define SIG_CONTSIGMASK(set) \ 161 SIGDELSET(set, SIGCONT) 162 163#define sigcantmask (sigmask(SIGKILL) | sigmask(SIGSTOP)) 164 165#define SIG2OSIG(sig, osig) osig = (sig).__bits[0] 166#define OSIG2SIG(osig, sig) SIGEMPTYSET(sig); (sig).__bits[0] = osig 167 168static __inline int 169__sigisempty(sigset_t *set) 170{ 171 int i; 172 173 for (i = 0; i < _SIG_WORDS; i++) { 174 if (set->__bits[i]) 175 return (0); 176 } 177 return (1); 178} 179 180static __inline int 181__sigseteq(sigset_t *set1, sigset_t *set2) 182{ 183 int i; 184 185 for (i = 0; i < _SIG_WORDS; i++) { 186 if (set1->__bits[i] != set2->__bits[i]) 187 return (0); 188 } 189 return (1); 190} 191 192#ifdef _KERNEL 193 194struct pgrp; 195struct proc; 196struct sigio; 197 198extern int sugid_coredump; /* Sysctl variable kern.sugid_coredump */ 199 200/* 201 * Machine-independent functions: 202 */ 203void check_sigacts __P((void)); 204void execsigs __P((struct proc *p)); 205void gsignal __P((int pgid, int sig)); 206int issignal __P((struct proc *p)); 207void killproc __P((struct proc *p, char *why)); 208void pgsigio __P((struct sigio *, int signum, int checkctty)); 209void pgsignal __P((struct pgrp *pgrp, int sig, int checkctty)); 210void postsig __P((int sig)); 211void psignal __P((struct proc *p, int sig)); 212void sigexit __P((struct proc *p, int signum)); 213void siginit __P((struct proc *p)); 214void trapsignal __P((struct proc *p, int sig, u_long code)); 215int __cursig __P((struct proc *p)); 216 217/* 218 * Machine-dependent functions: 219 */ 220void sendsig __P((sig_t action, int sig, sigset_t *retmask, u_long code)); 221 222/* 223 * Inline functions: 224 */ 225#define CURSIG(p) __cursig(p) 226 227/* 228 * Determine signal that should be delivered to process p, the current 229 * process, 0 if none. If there is a pending stop signal with default 230 * action, the process stops in issignal(). 231 * 232 * MP SAFE 233 */ 234extern __inline int __cursig(struct proc *p) 235{ 236 sigset_t tmpset; 237 int r; 238 239 tmpset = p->p_siglist; 240 SIGSETNAND(tmpset, p->p_sigmask); 241 if (SIGISEMPTY(p->p_siglist) || 242 (!(p->p_flag & P_TRACED) && SIGISEMPTY(tmpset))) { 243 return(0); 244 } 245 get_mplock(); 246 r = issignal(p); 247 rel_mplock(); 248 return(r); 249} 250 251#endif /* _KERNEL */ 252 253#endif /* !_SYS_SIGNALVAR_H_ */ 254