1 /* $NetBSD: signal.h,v 1.48 2002/11/26 19:07:14 christos Exp $ */ 2 3 /* 4 * Copyright (c) 1982, 1986, 1989, 1991, 1993 5 * The Regents of the University of California. All rights reserved. 6 * (c) UNIX System Laboratories, Inc. 7 * All or some portions of this file are derived from material licensed 8 * to the University of California by American Telephone and Telegraph 9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 10 * the permission of UNIX System Laboratories, Inc. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 3. All advertising materials mentioning features or use of this software 21 * must display the following acknowledgement: 22 * This product includes software developed by the University of 23 * California, Berkeley and its contributors. 24 * 4. Neither the name of the University nor the names of its contributors 25 * may be used to endorse or promote products derived from this software 26 * without specific prior written permission. 27 * 28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 38 * SUCH DAMAGE. 39 * 40 * @(#)signal.h 8.4 (Berkeley) 5/4/95 41 */ 42 43 #ifndef _SYS_SIGNAL_H_ 44 #define _SYS_SIGNAL_H_ 45 46 #include <sys/featuretest.h> 47 48 #define _NSIG 64 49 50 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) && \ 51 !defined(_XOPEN_SOURCE) 52 #define NSIG _NSIG 53 54 #if defined(__LIBC12_SOURCE__) || defined(_KERNEL) 55 /* Number of signals supported by old style signal mask. */ 56 #define NSIG13 32 57 #endif 58 59 #endif /* !_ANSI_SOURCE && !_POSIX_C_SOURCE && !_XOPEN_SOURCE */ 60 61 #define SIGHUP 1 /* hangup */ 62 #define SIGINT 2 /* interrupt */ 63 #define SIGQUIT 3 /* quit */ 64 #define SIGILL 4 /* illegal instruction (not reset when caught) */ 65 #ifndef _POSIX_SOURCE 66 #define SIGTRAP 5 /* trace trap (not reset when caught) */ 67 #endif 68 #define SIGABRT 6 /* abort() */ 69 #ifndef _POSIX_SOURCE 70 #define SIGIOT SIGABRT /* compatibility */ 71 #define SIGEMT 7 /* EMT instruction */ 72 #endif 73 #define SIGFPE 8 /* floating point exception */ 74 #define SIGKILL 9 /* kill (cannot be caught or ignored) */ 75 #ifndef _POSIX_SOURCE 76 #define SIGBUS 10 /* bus error */ 77 #endif 78 #define SIGSEGV 11 /* segmentation violation */ 79 #ifndef _POSIX_SOURCE 80 #define SIGSYS 12 /* bad argument to system call */ 81 #endif 82 #define SIGPIPE 13 /* write on a pipe with no one to read it */ 83 #define SIGALRM 14 /* alarm clock */ 84 #define SIGTERM 15 /* software termination signal from kill */ 85 #ifndef _POSIX_SOURCE 86 #define SIGURG 16 /* urgent condition on IO channel */ 87 #endif 88 #define SIGSTOP 17 /* sendable stop signal not from tty */ 89 #define SIGTSTP 18 /* stop signal from tty */ 90 #define SIGCONT 19 /* continue a stopped process */ 91 #define SIGCHLD 20 /* to parent on child stop or exit */ 92 #define SIGTTIN 21 /* to readers pgrp upon background tty read */ 93 #define SIGTTOU 22 /* like TTIN for output if (tp->t_local<OSTOP) */ 94 #ifndef _POSIX_SOURCE 95 #define SIGIO 23 /* input/output possible signal */ 96 #define SIGXCPU 24 /* exceeded CPU time limit */ 97 #define SIGXFSZ 25 /* exceeded file size limit */ 98 #define SIGVTALRM 26 /* virtual time alarm */ 99 #define SIGPROF 27 /* profiling time alarm */ 100 #define SIGWINCH 28 /* window size changes */ 101 #define SIGINFO 29 /* information request */ 102 #endif 103 #define SIGUSR1 30 /* user defined signal 1 */ 104 #define SIGUSR2 31 /* user defined signal 2 */ 105 #ifndef _POSIX_SOURCE 106 #define SIGPWR 32 /* power fail/restart (not reset when caught) */ 107 #endif 108 #ifdef _KERNEL 109 #define SIGRTMIN 33 /* Kernel only; not exposed to userland yet */ 110 #define SIGRTMAX 63 /* Kernel only; not exposed to userland yet */ 111 #endif 112 113 #ifndef _KERNEL 114 #include <sys/cdefs.h> 115 #endif 116 117 #define SIG_DFL ((void (*) __P((int))) 0) 118 #define SIG_IGN ((void (*) __P((int))) 1) 119 #define SIG_ERR ((void (*) __P((int))) -1) 120 121 #ifndef _ANSI_SOURCE 122 #if defined(__LIBC12_SOURCE__) || defined(_KERNEL) 123 typedef unsigned int sigset13_t; 124 125 /* 126 * Macro for manipulating signal masks. 127 */ 128 #define __sigmask13(n) (1 << ((n) - 1)) 129 #define __sigaddset13(s, n) (*(s) |= __sigmask13(n)) 130 #define __sigdelset13(s, n) (*(s) &= ~__sigmask13(n)) 131 #define __sigismember13(s, n) (*(s) & __sigmask13(n)) 132 #define __sigemptyset13(s) (*(s) = 0) 133 #define __sigfillset13(s) (*(s) = ~(sigset13_t)0) 134 135 /* 136 * Signal vector "template" used in sigaction call. 137 */ 138 struct sigaction13 { 139 void (*osa_handler) /* signal handler */ 140 __P((int)); 141 sigset13_t osa_mask; /* signal mask to apply */ 142 int osa_flags; /* see signal options below */ 143 }; 144 #endif 145 146 typedef struct { 147 u_int32_t __bits[4]; 148 } sigset_t; 149 150 /* 151 * Macro for manipulating signal masks. 152 */ 153 #define __sigmask(n) (1 << (((unsigned int)(n) - 1) & 31)) 154 #define __sigword(n) (((unsigned int)(n) - 1) >> 5) 155 #define __sigaddset(s, n) ((s)->__bits[__sigword(n)] |= __sigmask(n)) 156 #define __sigdelset(s, n) ((s)->__bits[__sigword(n)] &= ~__sigmask(n)) 157 #define __sigismember(s, n) (((s)->__bits[__sigword(n)] & __sigmask(n)) != 0) 158 #define __sigemptyset(s) ((s)->__bits[0] = 0x00000000, \ 159 (s)->__bits[1] = 0x00000000, \ 160 (s)->__bits[2] = 0x00000000, \ 161 (s)->__bits[3] = 0x00000000) 162 #define __sigfillset(s) ((s)->__bits[0] = 0xffffffff, \ 163 (s)->__bits[1] = 0xffffffff, \ 164 (s)->__bits[2] = 0xffffffff, \ 165 (s)->__bits[3] = 0xffffffff) 166 167 #ifdef _KERNEL 168 #define sigaddset(s, n) __sigaddset(s, n) 169 #define sigdelset(s, n) __sigdelset(s, n) 170 #define sigismember(s, n) __sigismember(s, n) 171 #define sigemptyset(s) __sigemptyset(s) 172 #define sigfillset(s) __sigfillset(s) 173 #define sigplusset(s, t) \ 174 do { \ 175 (t)->__bits[0] |= (s)->__bits[0]; \ 176 (t)->__bits[1] |= (s)->__bits[1]; \ 177 (t)->__bits[2] |= (s)->__bits[2]; \ 178 (t)->__bits[3] |= (s)->__bits[3]; \ 179 } while (/* CONSTCOND */ 0) 180 #define sigminusset(s, t) \ 181 do { \ 182 (t)->__bits[0] &= ~(s)->__bits[0]; \ 183 (t)->__bits[1] &= ~(s)->__bits[1]; \ 184 (t)->__bits[2] &= ~(s)->__bits[2]; \ 185 (t)->__bits[3] &= ~(s)->__bits[3]; \ 186 } while (/* CONSTCOND */ 0) 187 #endif /* _KERNEL */ 188 189 #include <sys/siginfo.h> 190 191 /* 192 * Signal vector "template" used in sigaction call. 193 */ 194 struct sigaction { 195 union { 196 void (*_sa_handler) __P((int)); 197 void (*_sa_sigaction) __P((int, siginfo_t *, void *)); 198 } _sa_u; /* signal handler */ 199 sigset_t sa_mask; /* signal mask to apply */ 200 int sa_flags; /* see signal options below */ 201 }; 202 203 #define sa_handler _sa_u._sa_handler 204 #define sa_sigaction _sa_u._sa_sigaction 205 206 #if (!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)) || \ 207 (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \ 208 (_XOPEN_SOURCE - 0) >= 500 209 #define SA_ONSTACK 0x0001 /* take signal on signal stack */ 210 #define SA_RESTART 0x0002 /* restart system on signal return */ 211 #define SA_RESETHAND 0x0004 /* reset to SIG_DFL when taking signal */ 212 #define SA_NODEFER 0x0010 /* don't mask the signal we're delivering */ 213 #if defined(_KERNEL) 214 #define SA_SIGINFO 0x0040 215 #endif /* _KERNEL */ 216 #endif /* (!_POSIX_C_SOURCE && !_XOPEN_SOURCE) || ... */ 217 /* Only valid for SIGCHLD. */ 218 #define SA_NOCLDSTOP 0x0008 /* do not generate SIGCHLD on child stop */ 219 #define SA_NOCLDWAIT 0x0020 /* do not generate zombies on unwaited child */ 220 #ifdef _KERNEL 221 #define SA_ALLBITS 0x007f 222 #endif 223 224 /* 225 * Flags for sigprocmask(): 226 */ 227 #define SIG_BLOCK 1 /* block specified signal set */ 228 #define SIG_UNBLOCK 2 /* unblock specified signal set */ 229 #define SIG_SETMASK 3 /* set specified signal set */ 230 231 #if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) 232 typedef void (*sig_t) __P((int)); /* type of signal function */ 233 #endif 234 235 /* 236 * Structure used in sigaltstack call. 237 */ 238 #if defined(__LIBC12_SOURCE__) || defined(_KERNEL) 239 struct sigaltstack13 { 240 char *ss_sp; /* signal stack base */ 241 int ss_size; /* signal stack length */ 242 int ss_flags; /* SS_DISABLE and/or SS_ONSTACK */ 243 }; 244 #endif /* defined(__LIBC12_SOURCE__) || defined(_KERNEL) */ 245 246 #if (!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)) || \ 247 (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \ 248 (_XOPEN_SOURCE - 0) >= 500 249 typedef struct 250 #ifndef _XOPEN_SOURCE 251 sigaltstack 252 #endif /* !_XOPEN_SOURCE */ 253 { 254 void *ss_sp; /* signal stack base */ 255 size_t ss_size; /* signal stack length */ 256 int ss_flags; /* SS_DISABLE and/or SS_ONSTACK */ 257 } stack_t; 258 259 #define SS_ONSTACK 0x0001 /* take signals on alternate stack */ 260 #define SS_DISABLE 0x0004 /* disable taking signals on alternate stack */ 261 #ifdef _KERNEL 262 #define SS_ALLBITS 0x0005 263 #endif 264 #define MINSIGSTKSZ 8192 /* minimum allowable stack */ 265 #define SIGSTKSZ (MINSIGSTKSZ + 32768) /* recommended stack size */ 266 #endif /* (!_POSIX_C_SOURCE && !_XOPEN_SOURCE) || ... */ 267 268 #if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) 269 /* 270 * 4.3 compatibility: 271 * Signal vector "template" used in sigvec call. 272 */ 273 struct sigvec { 274 void (*sv_handler) /* signal handler */ 275 __P((int)); 276 int sv_mask; /* signal mask to apply */ 277 int sv_flags; /* see signal options below */ 278 }; 279 #define SV_ONSTACK SA_ONSTACK 280 #define SV_INTERRUPT SA_RESTART /* same bit, opposite sense */ 281 #define SV_RESETHAND SA_RESETHAND 282 #define sv_onstack sv_flags /* isn't compatibility wonderful! */ 283 #endif /* !_POSIX_C_SOURCE && !_XOPEN_SOURCE */ 284 285 #if (!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)) || \ 286 (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \ 287 (_XOPEN_SOURCE - 0) >= 500 288 /* 289 * Structure used in sigstack call. 290 */ 291 struct sigstack { 292 void *ss_sp; /* signal stack pointer */ 293 int ss_onstack; /* current status */ 294 }; 295 #endif /* (!_POSIX_C_SOURCE && !_XOPEN_SOURCE) || ... */ 296 297 #include <machine/signal.h> /* sigcontext; codes for SIGILL, SIGFPE */ 298 299 #if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) && !defined(_KERNEL) 300 /* 301 * Macro for converting signal number to a mask suitable for 302 * sigblock(). 303 */ 304 #define sigmask(n) __sigmask(n) 305 306 #define BADSIG SIG_ERR 307 #endif /* !_POSIX_C_SOURCE && !_XOPEN_SOURCE */ 308 309 #endif /* !_ANSI_SOURCE */ 310 311 /* 312 * For historical reasons; programs expect signal's return value to be 313 * defined by <sys/signal.h>. 314 */ 315 __BEGIN_DECLS 316 void (*signal __P((int, void (*) __P((int))))) __P((int)); 317 __END_DECLS 318 #endif /* !_SYS_SIGNAL_H_ */ 319