1 /* 2 Copyright (c) 1991, 1993 3 The Regents of the University of California. All rights reserved. 4 c) UNIX System Laboratories, Inc. 5 All or some portions of this file are derived from material licensed 6 to the University of California by American Telephone and Telegraph 7 Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 the permission of UNIX System Laboratories, Inc. 9 10 Redistribution and use in source and binary forms, with or without 11 modification, are permitted provided that the following conditions 12 are met: 13 1. Redistributions of source code must retain the above copyright 14 notice, this list of conditions and the following disclaimer. 15 2. Redistributions in binary form must reproduce the above copyright 16 notice, this list of conditions and the following disclaimer in the 17 documentation and/or other materials provided with the distribution. 18 3. Neither the name of the University nor the names of its contributors 19 may be used to endorse or promote products derived from this software 20 without specific prior written permission. 21 22 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 SUCH DAMAGE. 33 */ 34 #ifndef _SIGNAL_H_ 35 #define _SIGNAL_H_ 36 37 #include <sys/cdefs.h> 38 #define __need_size_t 39 #include <stddef.h> 40 #include <sys/_types.h> 41 #include <sys/_sigset.h> 42 #include <sys/_timespec.h> 43 44 _BEGIN_STD_C 45 46 typedef int sig_atomic_t; /* Atomic entity type (ANSI) */ 47 48 typedef void (*_sig_func_ptr)(int); 49 50 #define SIG_DFL ((_sig_func_ptr)0) /* Default action */ 51 #define SIG_IGN ((_sig_func_ptr)1) /* Ignore action */ 52 #define SIG_ERR ((_sig_func_ptr)-1) /* Error return */ 53 54 #if __POSIX_VISIBLE 55 56 #ifndef _UID_T_DECLARED 57 typedef __uid_t uid_t; /* user id */ 58 #define _UID_T_DECLARED 59 #endif 60 61 #if !defined(_SIGSET_T_DECLARED) 62 #define _SIGSET_T_DECLARED 63 typedef __sigset_t sigset_t; 64 #endif 65 66 union sigval { 67 int sival_int; /* Integer signal value */ 68 void *sival_ptr; /* Pointer signal value */ 69 }; 70 71 /* Signal Actions, P1003.1b-1993, p. 64 */ 72 /* si_code values, p. 66 */ 73 74 #define SI_USER 1 /* Sent by a user. kill(), abort(), etc */ 75 #define SI_QUEUE 2 /* Sent by sigqueue() */ 76 #define SI_TIMER 3 /* Sent by expiration of a timer_settime() timer */ 77 #define SI_ASYNCIO 4 /* Indicates completion of asycnhronous IO */ 78 #define SI_MESGQ 5 /* Indicates arrival of a message at an empty queue */ 79 80 typedef struct { 81 int si_signo; /* Signal number */ 82 int si_code; /* Cause of the signal */ 83 int si_errno; /* If non-zero, the errno */ 84 __pid_t si_pid; /* Sending process ID */ 85 uid_t si_uid; /* Real UID of sending process */ 86 void *si_addr; /* Address of faulting instruction */ 87 int si_status; /* Exit value or signal */ 88 union sigval si_value; /* Signal value */ 89 } siginfo_t; 90 91 /* 92 * Possible values for sa_flags in sigaction below. 93 */ 94 95 #define SA_NOCLDSTOP (1 << 0) 96 #define SA_ONSTACK (1 << 1) 97 #define SA_RESETHAND (1 << 2) 98 #define SA_RESTART (1 << 3) 99 #define SA_SIGINFO (1 << 4) 100 #define SA_NOCLDWAIT (1 << 5) 101 #define SA_NODEFER (1 << 6) 102 103 struct sigaction { 104 union { 105 void (*sa_handler)(int); 106 void (*sa_sigaction)(int, siginfo_t *, void *); 107 }; 108 sigset_t sa_mask; 109 int sa_flags; 110 }; 111 112 /* 113 * Possible values for ss_flags in stack_t below. 114 */ 115 #define SS_ONSTACK 0x1 116 #define SS_DISABLE 0x2 117 118 /* 119 * Structure used in sigaltstack call. 120 */ 121 typedef struct sigaltstack { 122 void *ss_sp; /* Stack base or pointer. */ 123 int ss_flags; /* Flags. */ 124 size_t ss_size; /* Stack size. */ 125 } stack_t; 126 127 #define SIG_SETMASK 0 /* set mask with sigprocmask() */ 128 #define SIG_BLOCK 1 /* set of signals to block */ 129 #define SIG_UNBLOCK 2 /* set of signals to unblock */ 130 131 #endif /* __POSIX_VISIBLE */ 132 133 #if defined(_POSIX_REALTIME_SIGNALS) || __POSIX_VISIBLE >= 199309 134 135 /* sigev_notify values 136 NOTE: P1003.1c/D10, p. 34 adds SIGEV_THREAD. */ 137 138 #define SIGEV_NONE 1 /* No asynchronous notification shall be delivered */ 139 /* when the event of interest occurs. */ 140 #define SIGEV_SIGNAL 2 /* A queued signal, with an application defined */ 141 /* value, shall be delivered when the event of */ 142 /* interest occurs. */ 143 #define SIGEV_THREAD 3 /* A notification function shall be called to */ 144 /* perform notification. */ 145 146 /* Signal Generation and Delivery, P1003.1b-1993, p. 63 147 NOTE: P1003.1c/D10, p. 34 adds sigev_notify_function and 148 sigev_notify_attributes to the sigevent structure. */ 149 150 struct sigevent { 151 int sigev_notify; /* Notification type */ 152 int sigev_signo; /* Signal number */ 153 union sigval sigev_value; /* Signal value */ 154 void (*sigev_notify_function)( union sigval ); 155 /* Notification function */ 156 void *sigev_notify_attributes; /* Notification Attributes */ 157 }; 158 #endif /* defined(_POSIX_REALTIME_SIGNALS) || __POSIX_VISIBLE >= 199309 */ 159 160 161 #if __BSD_VISIBLE || __XSI_VISIBLE >= 4 || __POSIX_VISIBLE >= 200809 162 163 /* 164 * Minimum and default signal stack constants. Allow for target overrides 165 * from <sys/features.h>. 166 */ 167 #ifndef MINSIGSTKSZ 168 #define MINSIGSTKSZ 2048 169 #endif 170 #ifndef SIGSTKSZ 171 #define SIGSTKSZ 8192 172 #endif 173 174 #endif 175 176 #define SIGHUP 1 /* hangup */ 177 #define SIGINT 2 /* interrupt */ 178 #define SIGQUIT 3 /* quit */ 179 #define SIGILL 4 /* illegal instruction (not reset when caught) */ 180 #define SIGTRAP 5 /* trace trap (not reset when caught) */ 181 #define SIGIOT 6 /* IOT instruction */ 182 #define SIGABRT 6 /* used by abort, replace SIGIOT in the future */ 183 #define SIGEMT 7 /* EMT instruction */ 184 #define SIGFPE 8 /* floating point exception */ 185 #define SIGKILL 9 /* kill (cannot be caught or ignored) */ 186 #define SIGBUS 10 /* bus error */ 187 #define SIGSEGV 11 /* segmentation violation */ 188 #define SIGSYS 12 /* bad argument to system call */ 189 #define SIGPIPE 13 /* write on a pipe with no one to read it */ 190 #define SIGALRM 14 /* alarm clock */ 191 #define SIGTERM 15 /* software termination signal from kill */ 192 #define SIGURG 16 /* urgent condition on IO channel */ 193 #define SIGSTOP 17 /* sendable stop signal not from tty */ 194 #define SIGTSTP 18 /* stop signal from tty */ 195 #define SIGCONT 19 /* continue a stopped process */ 196 #define SIGCHLD 20 /* to parent on child stop or exit */ 197 #define SIGCLD 20 /* System V name for SIGCHLD */ 198 #define SIGTTIN 21 /* to readers pgrp upon background tty read */ 199 #define SIGTTOU 22 /* like TTIN for output if (tp->t_local<OSTOP) */ 200 #define SIGIO 23 /* input/output possible signal */ 201 #define SIGPOLL SIGIO /* System V name for SIGIO */ 202 #define SIGXCPU 24 /* exceeded CPU time limit */ 203 #define SIGXFSZ 25 /* exceeded file size limit */ 204 #define SIGVTALRM 26 /* virtual time alarm */ 205 #define SIGPROF 27 /* profiling time alarm */ 206 #define SIGWINCH 28 /* window changed */ 207 #define SIGLOST 29 /* resource lost (eg, record-lock lost) */ 208 #define SIGUSR1 30 /* user defined signal 1 */ 209 #define SIGUSR2 31 /* user defined signal 2 */ 210 #define _NSIG 32 211 212 /* Using __MISC_VISIBLE until POSIX Issue 8 is officially released */ 213 #if __MISC_VISIBLE 214 #if __SIZEOF_INT__ >= 4 215 #define SIG2STR_MAX 17 /* (sizeof("RTMAX+") + sizeof("4294967295") - 1) */ 216 #else 217 #define SIG2STR_MAX 12 /* (sizeof("RTMAX+") + sizeof("65535") - 1) */ 218 #endif 219 #endif 220 221 #if __BSD_VISIBLE 222 typedef _sig_func_ptr sig_t; /* BSD naming */ 223 #endif 224 225 #if __GNU_VISIBLE 226 typedef _sig_func_ptr sighandler_t; /* glibc naming */ 227 #endif 228 229 #if __POSIX_VISIBLE 230 int kill(__pid_t pid, int sig); 231 #endif 232 #if __XSI_VISIBLE >= 500 233 int killpg(__pid_t pid, int sig); 234 #endif 235 #if __POSIX_VISIBLE >= 200809L 236 void psiginfo(const siginfo_t *, const char *); 237 #endif 238 #if __BSD_VISIBLE || __SVID_VISIBLE 239 void psignal (int, const char *); 240 #endif 241 int raise (int); 242 #if __MISC_VISIBLE 243 int sig2str(int, char *); 244 #endif 245 #if __POSIX_VISIBLE 246 int sigaction(int, const struct sigaction *__restrict, struct sigaction *__restrict); 247 int sigaddset (sigset_t *, const int); 248 #define sigaddset(what,sig) (*(what) |= (1<<(sig)), 0) 249 #endif 250 #if __BSD_VISIBLE || __XSI_VISIBLE >= 4 || __POSIX_VISIBLE >= 200809 251 int sigaltstack (const stack_t *__restrict, stack_t *__restrict); 252 #endif 253 #if __POSIX_VISIBLE 254 int sigdelset (sigset_t *, const int); 255 #define sigdelset(what,sig) (*(what) &= ~((sigset_t)1<<(sig)), 0) 256 int sigemptyset (sigset_t *); 257 #define sigemptyset(what) (*(what) = (sigset_t) 0, 0) 258 int sigfillset (sigset_t *); 259 #define sigfillset(what) (*(what) = ~((sigset_t)0), 0) 260 int sigismember (const sigset_t *, int); 261 #define sigismember(what,sig) (((*(what)) & ((sigset_t) 1<<(sig))) != 0) 262 #endif 263 _sig_func_ptr signal (int, _sig_func_ptr); 264 #if __POSIX_VISIBLE 265 int sigpending (sigset_t *); 266 int sigprocmask (int, const sigset_t *, sigset_t *); 267 #endif 268 #if __POSIX_VISIBLE >= 199309L 269 int sigqueue (__pid_t, int, const union sigval); 270 #endif 271 #if __POSIX_VISIBLE 272 int sigsuspend (const sigset_t *); 273 #endif 274 #if __POSIX_VISIBLE >= 199309L 275 int sigtimedwait (const sigset_t *, siginfo_t *, const struct timespec *); 276 #endif 277 #if __POSIX_VISIBLE >= 199506L 278 int sigwait (const sigset_t *, int *); 279 #endif 280 #if __POSIX_VISIBLE >= 199309L 281 int sigwaitinfo (const sigset_t *, siginfo_t *); 282 #endif 283 #if __MISC_VISIBLE 284 int str2sig(const char *__restrict, int *__restrict); 285 #endif 286 287 _END_STD_C 288 289 #endif /* _SIGNAL_H_ */ 290