1 /* $NetBSD: signal.h,v 1.67 2011/01/10 13:56:44 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. Neither the name of the University nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * 36 * @(#)signal.h 8.4 (Berkeley) 5/4/95 37 */ 38 39 #ifndef _SYS_SIGNAL_H_ 40 #define _SYS_SIGNAL_H_ 41 42 #include <sys/featuretest.h> 43 #include <sys/sigtypes.h> 44 45 #define _NSIG 27 46 #define NSIG _NSIG 47 48 49 /* Regular signals. */ 50 #define SIGHUP 1 /* hangup */ 51 #define SIGINT 2 /* interrupt (DEL) */ 52 #define SIGQUIT 3 /* quit (ASCII FS) */ 53 #define SIGILL 4 /* illegal instruction */ 54 #define SIGTRAP 5 /* trace trap (not reset when caught) */ 55 #define SIGABRT 6 /* IOT instruction */ 56 #define SIGBUS 7 /* bus error */ 57 #define SIGFPE 8 /* floating point exception */ 58 #define SIGKILL 9 /* kill (cannot be caught or ignored) */ 59 #define SIGUSR1 10 /* user defined signal # 1 */ 60 #define SIGSEGV 11 /* segmentation violation */ 61 #define SIGUSR2 12 /* user defined signal # 2 */ 62 #define SIGPIPE 13 /* write on a pipe with no one to read it */ 63 #define SIGALRM 14 /* alarm clock */ 64 #define SIGTERM 15 /* software termination signal from kill */ 65 #define SIGEMT 16 /* EMT instruction */ 66 #define SIGCHLD 17 /* child process terminated or stopped */ 67 #define SIGWINCH 21 /* window size has changed */ 68 #define SIGVTALRM 24 /* virtual alarm */ 69 #define SIGPROF 25 /* profiler alarm */ 70 #define SIGINFO 26 /* information request */ 71 72 /* POSIX requires the following signals to be defined, even if they are 73 * not supported. Here are the definitions, but they are not supported. 74 */ 75 #define SIGCONT 18 /* continue if stopped */ 76 #define SIGSTOP 19 /* stop signal */ 77 #define SIGTSTP 20 /* interactive stop signal */ 78 #define SIGTTIN 22 /* background process wants to read */ 79 #define SIGTTOU 23 /* background process wants to write */ 80 81 #if defined(__minix) && defined(_NETBSD_SOURCE) 82 #define SIGIOT SIGABRT /* for people who speak PDP-11 */ 83 84 /* MINIX specific signals. These signals are not used by user proceses, 85 * but meant to inform system processes, like the PM, about system events. 86 * The order here determines the order signals are processed by system 87 * processes in user-space. Higher-priority signals should be first. 88 */ 89 /* Signals delivered by a signal manager. */ 90 #define SIGSNDELAY 27 /* end of delay for signal delivery */ 91 92 #define SIGS_FIRST SIGHUP /* first system signal */ 93 #define SIGS_LAST SIGSNDELAY /* last system signal */ 94 #define IS_SIGS(signo) (signo>=SIGS_FIRST && signo<=SIGS_LAST) 95 96 /* Signals delivered by the kernel. */ 97 #define SIGKMEM 28 /* kernel memory request pending */ 98 #define SIGKMESS 29 /* new kernel message */ 99 #define SIGKSIGSM 30 /* kernel signal pending for signal manager */ 100 #define SIGKSIG 31 /* kernel signal pending */ 101 102 #define SIGK_FIRST SIGKMEM /* first kernel signal */ 103 #define SIGK_LAST SIGKSIG /* last kernel signal */ 104 #define IS_SIGK(signo) (signo>=SIGK_FIRST && signo<=SIGK_LAST) 105 106 /* Termination signals for Minix system processes. */ 107 #define SIGS_IS_LETHAL(sig) \ 108 (sig == SIGILL || sig == SIGBUS || sig == SIGFPE || sig == SIGSEGV \ 109 || sig == SIGEMT || sig == SIGABRT) 110 #define SIGS_IS_TERMINATION(sig) (SIGS_IS_LETHAL(sig) \ 111 || (sig == SIGKILL || sig == SIGPIPE)) 112 #define SIGS_IS_STACKTRACE(sig) (SIGS_IS_LETHAL(sig) && sig != SIGABRT) 113 114 #endif /* defined(__minix) && deinfed(_NETBSD_SOURCE) */ 115 116 #ifndef _KERNEL 117 #include <sys/cdefs.h> 118 #endif 119 120 typedef void (*__sighandler_t)(int); 121 122 /* Macros used as function pointers. */ 123 #define SIG_ERR ((__sighandler_t) -1) /* error return */ 124 #define SIG_DFL ((__sighandler_t) 0) /* default signal handling */ 125 #define SIG_IGN ((__sighandler_t) 1) /* ignore signal */ 126 #define SIG_HOLD ((__sighandler_t) 2) /* block signal */ 127 #define SIG_CATCH ((__sighandler_t) 3) /* catch signal */ 128 129 #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \ 130 defined(_NETBSD_SOURCE) 131 132 #if (_POSIX_C_SOURCE - 0) >= 199309L || (_XOPEN_SOURCE - 0) >= 500 || \ 133 defined(_NETBSD_SOURCE) 134 #include <sys/siginfo.h> 135 #endif 136 137 #if (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \ 138 (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE) 139 #include <sys/ucontext.h> 140 #endif /* _XOPEN_SOURCE_EXTENDED || _XOPEN_SOURCE >= 500 || _NETBSD_SOURCE */ 141 142 /* 143 * Signal vector "template" used in sigaction call. 144 */ 145 struct sigaction { 146 union { 147 void (*_sa_handler)(int); 148 #if (_POSIX_C_SOURCE - 0) >= 199309L || (_XOPEN_SOURCE - 0) >= 500 || \ 149 defined(_NETBSD_SOURCE) 150 void (*_sa_sigaction)(int, siginfo_t *, void *); 151 #endif 152 } _sa_u; /* signal handler */ 153 sigset_t sa_mask; /* signal mask to apply */ 154 int sa_flags; /* see signal options below */ 155 }; 156 157 #define sa_handler _sa_u._sa_handler 158 #if (_POSIX_C_SOURCE - 0) >= 199309L || (_XOPEN_SOURCE - 0) >= 500 || \ 159 defined(_NETBSD_SOURCE) 160 #define sa_sigaction _sa_u._sa_sigaction 161 #endif 162 163 #include <machine/signal.h> /* sigcontext; codes for SIGILL, SIGFPE */ 164 165 /* Fields for sa_flags. */ 166 #define SA_ONSTACK 0x0001 /* deliver signal on alternate stack */ 167 #define SA_RESETHAND 0x0002 /* reset signal handler when signal caught */ 168 #define SA_NODEFER 0x0004 /* don't block signal while catching it */ 169 #define SA_RESTART 0x0008 /* automatic system call restart */ 170 #define SA_SIGINFO 0x0010 /* extended signal handling */ 171 #define SA_NOCLDWAIT 0x0020 /* don't create zombies */ 172 #define SA_NOCLDSTOP 0x0040 /* don't receive SIGCHLD when child stops */ 173 174 /* POSIX requires these values for use with sigprocmask(2). */ 175 #define SIG_BLOCK 0 /* for blocking signals */ 176 #define SIG_UNBLOCK 1 /* for unblocking signals */ 177 #define SIG_SETMASK 2 /* for setting the signal mask */ 178 #define SIG_INQUIRE 4 /* for internal use only */ 179 180 #if defined(_NETBSD_SOURCE) 181 typedef void (*sig_t)(int); /* type of signal function */ 182 #endif 183 184 #if (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \ 185 (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE) 186 /* 187 * Flags used with stack_t/struct sigaltstack. 188 */ 189 #define SS_ONSTACK 1 /* Process is executing on an alternate stack */ 190 #define SS_DISABLE 2 /* Alternate stack is disabled */ 191 192 #define MINSIGSTKSZ 2048 /* Minimal stack size is 2k */ 193 #define SIGSTKSZ (MINSIGSTKSZ + 32768) /* recommended stack size */ 194 #endif /* _XOPEN_SOURCE_EXTENDED || _XOPEN_SOURCE >= 500 || _NETBSD_SOURCE */ 195 196 #if (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \ 197 (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE) 198 /* 199 * Structure used in sigstack call. 200 */ 201 struct sigstack { 202 void *ss_sp; /* signal stack pointer */ 203 int ss_onstack; /* current status */ 204 }; 205 #endif /* _XOPEN_SOURCE_EXTENDED || _XOPEN_SOURCE >= 500 || _NETBSD_SOURCE */ 206 207 #if defined(_NETBSD_SOURCE) && !defined(_KERNEL) 208 /* 209 * Macro for converting signal number to a mask suitable for 210 * sigblock(). 211 */ 212 #define sigmask(n) __sigmask(n) 213 214 #define BADSIG SIG_ERR 215 #endif /* _NETBSD_SOURCE */ 216 217 #if (_POSIX_C_SOURCE - 0) >= 199309L || (_XOPEN_SOURCE - 0) >= 500 || \ 218 defined(_NETBSD_SOURCE) 219 struct sigevent { 220 int sigev_notify; 221 int sigev_signo; 222 union sigval sigev_value; 223 void (*sigev_notify_function)(union sigval); 224 void /* pthread_attr_t */ *sigev_notify_attributes; 225 }; 226 227 #define SIGEV_NONE 0 228 #define SIGEV_SIGNAL 1 229 #define SIGEV_THREAD 2 230 #if defined(_NETBSD_SOURCE) 231 #define SIGEV_SA 3 232 #endif 233 #endif /* (_POSIX_C_SOURCE - 0) >= 199309L || ... */ 234 235 #endif /* _POSIX_C_SOURCE || _XOPEN_SOURCE || _NETBSD_SOURCE */ 236 237 /* 238 * For historical reasons; programs expect signal's return value to be 239 * defined by <sys/signal.h>. 240 */ 241 __BEGIN_DECLS 242 void (*signal(int, void (*)(int)))(int); 243 __END_DECLS 244 #endif /* !_SYS_SIGNAL_H_ */ 245