signalvar.h revision 127976
134925Sdufault/* 234925Sdufault * Copyright (c) 1991, 1993 334030Sdufault * The Regents of the University of California. All rights reserved. 434030Sdufault * 534030Sdufault * Redistribution and use in source and binary forms, with or without 634030Sdufault * modification, are permitted provided that the following conditions 734030Sdufault * are met: 834030Sdufault * 1. Redistributions of source code must retain the above copyright 934030Sdufault * notice, this list of conditions and the following disclaimer. 1034030Sdufault * 2. Redistributions in binary form must reproduce the above copyright 1134030Sdufault * notice, this list of conditions and the following disclaimer in the 1234030Sdufault * documentation and/or other materials provided with the distribution. 1334030Sdufault * 4. Neither the name of the University nor the names of its contributors 1434030Sdufault * may be used to endorse or promote products derived from this software 1534030Sdufault * without specific prior written permission. 1634030Sdufault * 1734030Sdufault * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1834030Sdufault * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1934030Sdufault * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2034030Sdufault * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2134030Sdufault * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2234030Sdufault * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2334030Sdufault * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2434030Sdufault * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2534030Sdufault * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2634030Sdufault * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2734030Sdufault * SUCH DAMAGE. 2834030Sdufault * 2934030Sdufault * @(#)signalvar.h 8.6 (Berkeley) 2/19/95 3034030Sdufault * $FreeBSD: head/sys/sys/signalvar.h 127976 2004-04-07 04:19:52Z imp $ 3134030Sdufault */ 3234030Sdufault 3334030Sdufault#ifndef _SYS_SIGNALVAR_H_ 3455140Sbde#define _SYS_SIGNALVAR_H_ 3534030Sdufault 3634030Sdufault#include <sys/queue.h> 3734030Sdufault#include <sys/_lock.h> 3834030Sdufault#include <sys/_mutex.h> 3934925Sdufault#include <sys/signal.h> 4034925Sdufault 4134030Sdufault/* 4234925Sdufault * Kernel signal definitions and data structures, 4345739Speter * not exported to user programs. 4434925Sdufault */ 4534030Sdufault 4634925Sdufault/* 4734925Sdufault * Logical process signal actions and state, needed only within the process 4883366Sjulian * The mapping between sigacts and proc structures is 1:1 except for rfork() 4934030Sdufault * processes masquerading as threads which use one structure for the whole 5034925Sdufault * group. All members are locked by the included mutex. The reference count 5183366Sjulian * and mutex must be last for the bcopy in sigacts_copy() to work. 5234925Sdufault */ 5383366Sjulianstruct sigacts { 5434925Sdufault sig_t ps_sigact[_SIG_MAXSIG]; /* Disposition of signals. */ 5534030Sdufault sigset_t ps_catchmask[_SIG_MAXSIG]; /* Signals to be blocked. */ 5634030Sdufault sigset_t ps_sigonstack; /* Signals to take on sigstack. */ 5734925Sdufault sigset_t ps_sigintr; /* Signals that interrupt syscalls. */ 5834030Sdufault sigset_t ps_sigreset; /* Signals that reset when caught. */ 5934925Sdufault sigset_t ps_signodefer; /* Signals not masked while handled. */ 6034925Sdufault sigset_t ps_siginfo; /* Signals that want SA_SIGINFO args. */ 6134925Sdufault sigset_t ps_sigignore; /* Signals being ignored. */ 6292727Salfred sigset_t ps_sigcatch; /* Signals being caught by user. */ 6334925Sdufault sigset_t ps_freebsd4; /* signals using freebsd4 ucontext. */ 6492727Salfred sigset_t ps_osigset; /* Signals using <= 3.x osigset_t. */ 65103574Salfred sigset_t ps_usertramp; /* SunOS compat; libc sigtramp. XXX */ 66106998Salfred int ps_flag; 6734925Sdufault int ps_refcnt; 6834925Sdufault struct mtx ps_mtx; 6934925Sdufault}; 7034030Sdufault 7134030Sdufault#define PS_NOCLDWAIT 0x0001 /* No zombies if child dies */ 7234030Sdufault#define PS_NOCLDSTOP 0x0002 /* No SIGCHLD when children stop. */ 7334030Sdufault#define PS_CLDSIGIGN 0x0004 /* The SIGCHLD handler is SIG_IGN. */ 7434030Sdufault 7534030Sdufault#if defined(_KERNEL) && defined(COMPAT_43) 7634030Sdufault/* 7734030Sdufault * Compatibility. 7834030Sdufault */ 7934030Sdufaulttypedef struct { 8034030Sdufault struct osigcontext si_sc; 8134030Sdufault int si_signo; 8234030Sdufault int si_code; 8334030Sdufault union sigval si_value; 8434030Sdufault} osiginfo_t; 8534030Sdufault 8634030Sdufaultstruct osigaction { 8734030Sdufault union { 8834030Sdufault void (*__sa_handler)(int); 8934030Sdufault void (*__sa_sigaction)(int, osiginfo_t *, void *); 9034030Sdufault } __sigaction_u; /* signal handler */ 9134030Sdufault osigset_t sa_mask; /* signal mask to apply */ 9234925Sdufault int sa_flags; /* see signal options below */ 9334030Sdufault}; 9434925Sdufault 9534925Sdufaulttypedef void __osiginfohandler_t(int, osiginfo_t *, void *); 9634030Sdufault#endif /* _KERNEL && COMPAT_43 */ 9755140Sbde 9883366Sjulian/* additional signal action values, used only temporarily/internally */ 9955140Sbde#define SIG_CATCH ((__sighandler_t *)2) 10083366Sjulian#define SIG_HOLD ((__sighandler_t *)3) 10134030Sdufault 10255140Sbde/* 10383366Sjulian * get signal action for process and signal; currently only for current process 10483366Sjulian */ 10534030Sdufault#define SIGACTION(p, sig) (p->p_sigacts->ps_sigact[_SIG_IDX(sig)]) 10655140Sbde 10734030Sdufault/* 10855140Sbde * sigset_t manipulation macros 10955140Sbde */ 11034030Sdufault#define SIGADDSET(set, signo) \ 11155140Sbde ((set).__bits[_SIG_WORD(signo)] |= _SIG_BIT(signo)) 11283366Sjulian 11334030Sdufault#define SIGDELSET(set, signo) \ 11434925Sdufault ((set).__bits[_SIG_WORD(signo)] &= ~_SIG_BIT(signo)) 11534030Sdufault 11634925Sdufault#define SIGEMPTYSET(set) \ 117 do { \ 118 int __i; \ 119 for (__i = 0; __i < _SIG_WORDS; __i++) \ 120 (set).__bits[__i] = 0; \ 121 } while (0) 122 123#define SIGFILLSET(set) \ 124 do { \ 125 int __i; \ 126 for (__i = 0; __i < _SIG_WORDS; __i++) \ 127 (set).__bits[__i] = ~0U; \ 128 } while (0) 129 130#define SIGISMEMBER(set, signo) \ 131 ((set).__bits[_SIG_WORD(signo)] & _SIG_BIT(signo)) 132 133#define SIGISEMPTY(set) (__sigisempty(&(set))) 134#define SIGNOTEMPTY(set) (!__sigisempty(&(set))) 135 136#define SIGSETEQ(set1, set2) (__sigseteq(&(set1), &(set2))) 137#define SIGSETNEQ(set1, set2) (!__sigseteq(&(set1), &(set2))) 138 139#define SIGSETOR(set1, set2) \ 140 do { \ 141 int __i; \ 142 for (__i = 0; __i < _SIG_WORDS; __i++) \ 143 (set1).__bits[__i] |= (set2).__bits[__i]; \ 144 } while (0) 145 146#define SIGSETAND(set1, set2) \ 147 do { \ 148 int __i; \ 149 for (__i = 0; __i < _SIG_WORDS; __i++) \ 150 (set1).__bits[__i] &= (set2).__bits[__i]; \ 151 } while (0) 152 153#define SIGSETNAND(set1, set2) \ 154 do { \ 155 int __i; \ 156 for (__i = 0; __i < _SIG_WORDS; __i++) \ 157 (set1).__bits[__i] &= ~(set2).__bits[__i]; \ 158 } while (0) 159 160#define SIGSETLO(set1, set2) ((set1).__bits[0] = (set2).__bits[0]) 161#define SIGSETOLD(set, oset) ((set).__bits[0] = (oset)) 162 163#define SIG_CANTMASK(set) \ 164 SIGDELSET(set, SIGKILL), SIGDELSET(set, SIGSTOP) 165 166#define SIG_STOPSIGMASK(set) \ 167 SIGDELSET(set, SIGSTOP), SIGDELSET(set, SIGTSTP), \ 168 SIGDELSET(set, SIGTTIN), SIGDELSET(set, SIGTTOU) 169 170#define SIG_CONTSIGMASK(set) \ 171 SIGDELSET(set, SIGCONT) 172 173#define sigcantmask (sigmask(SIGKILL) | sigmask(SIGSTOP)) 174 175#define SIG2OSIG(sig, osig) (osig = (sig).__bits[0]) 176#define OSIG2SIG(osig, sig) SIGEMPTYSET(sig); (sig).__bits[0] = osig 177 178static __inline int 179__sigisempty(sigset_t *set) 180{ 181 int i; 182 183 for (i = 0; i < _SIG_WORDS; i++) { 184 if (set->__bits[i]) 185 return (0); 186 } 187 return (1); 188} 189 190static __inline int 191__sigseteq(sigset_t *set1, sigset_t *set2) 192{ 193 int i; 194 195 for (i = 0; i < _SIG_WORDS; i++) { 196 if (set1->__bits[i] != set2->__bits[i]) 197 return (0); 198 } 199 return (1); 200} 201 202#ifdef _KERNEL 203 204/* 205 * Specifies the target of a signal. 206 * P - Doesn't matter which thread it gets delivered to. 207 * TD - Must be delivered to a specific thread. 208 */ 209typedef enum sigtarget_enum { SIGTARGET_P, SIGTARGET_TD } sigtarget_t; 210 211/* Return nonzero if process p has an unmasked pending signal. */ 212#define SIGPENDING(td) \ 213 (!SIGISEMPTY((td)->td_siglist) && \ 214 !sigsetmasked(&(td)->td_siglist, &(td)->td_sigmask)) 215 216/* 217 * Return the value of the pseudo-expression ((*set & ~*mask) != 0). This 218 * is an optimized version of SIGISEMPTY() on a temporary variable 219 * containing SIGSETNAND(*set, *mask). 220 */ 221static __inline int 222sigsetmasked(sigset_t *set, sigset_t *mask) 223{ 224 int i; 225 226 for (i = 0; i < _SIG_WORDS; i++) { 227 if (set->__bits[i] & ~mask->__bits[i]) 228 return (0); 229 } 230 return (1); 231} 232 233struct pgrp; 234struct thread; 235struct proc; 236struct sigio; 237struct mtx; 238 239extern int sugid_coredump; /* Sysctl variable kern.sugid_coredump */ 240extern struct mtx sigio_lock; 241 242/* 243 * Lock the pointers for a sigio object in the underlying objects of 244 * a file descriptor. 245 */ 246#define SIGIO_LOCK() mtx_lock(&sigio_lock) 247#define SIGIO_TRYLOCK() mtx_trylock(&sigio_lock) 248#define SIGIO_UNLOCK() mtx_unlock(&sigio_lock) 249#define SIGIO_LOCKED() mtx_owned(&sigio_lock) 250#define SIGIO_ASSERT(type) mtx_assert(&sigio_lock, type) 251 252/* 253 * Machine-independent functions: 254 */ 255int cursig(struct thread *td); 256void execsigs(struct proc *p); 257void gsignal(int pgid, int sig); 258void killproc(struct proc *p, char *why); 259void pgsigio(struct sigio **, int signum, int checkctty); 260void pgsignal(struct pgrp *pgrp, int sig, int checkctty); 261void postsig(int sig); 262void psignal(struct proc *p, int sig); 263struct sigacts *sigacts_alloc(void); 264void sigacts_copy(struct sigacts *dest, struct sigacts *src); 265void sigacts_free(struct sigacts *ps); 266struct sigacts *sigacts_hold(struct sigacts *ps); 267int sigacts_shared(struct sigacts *ps); 268void sigexit(struct thread *td, int signum) __dead2; 269int sig_ffs(sigset_t *set); 270void siginit(struct proc *p); 271void signotify(struct thread *td); 272void tdsignal(struct thread *td, int sig, sigtarget_t target); 273void trapsignal(struct thread *td, int sig, u_long code); 274void ptracestop(struct thread *td, int sig); 275 276/* 277 * Machine-dependent functions: 278 */ 279void sendsig(sig_t action, int sig, sigset_t *retmask, u_long code); 280 281#endif /* _KERNEL */ 282 283#endif /* !_SYS_SIGNALVAR_H_ */ 284