[444] | 1 | /* sys/signal.h */ |
---|
| 2 | |
---|
| 3 | #ifndef _SYS_SIGNAL_H |
---|
| 4 | #define _SYS_SIGNAL_H |
---|
| 5 | #ifdef __cplusplus |
---|
| 6 | extern "C" { |
---|
| 7 | #endif |
---|
| 8 | |
---|
| 9 | #include "_ansi.h" |
---|
| 10 | #include <sys/cdefs.h> |
---|
| 11 | #include <sys/features.h> |
---|
| 12 | #include <sys/types.h> |
---|
| 13 | #include <sys/_sigset.h> |
---|
| 14 | #include <sys/_timespec.h> |
---|
| 15 | |
---|
| 16 | #if !defined(_SIGSET_T_DECLARED) |
---|
| 17 | #define _SIGSET_T_DECLARED |
---|
| 18 | typedef __sigset_t sigset_t; |
---|
| 19 | #endif |
---|
| 20 | |
---|
| 21 | #if defined(__CYGWIN__) |
---|
| 22 | #include <cygwin/signal.h> |
---|
| 23 | #else |
---|
| 24 | |
---|
| 25 | #if defined(_POSIX_REALTIME_SIGNALS) || __POSIX_VISIBLE >= 199309 |
---|
| 26 | |
---|
| 27 | /* sigev_notify values |
---|
| 28 | NOTE: P1003.1c/D10, p. 34 adds SIGEV_THREAD. */ |
---|
| 29 | |
---|
| 30 | #define SIGEV_NONE 1 /* No asynchronous notification shall be delivered */ |
---|
| 31 | /* when the event of interest occurs. */ |
---|
| 32 | #define SIGEV_SIGNAL 2 /* A queued signal, with an application defined */ |
---|
| 33 | /* value, shall be delivered when the event of */ |
---|
| 34 | /* interest occurs. */ |
---|
| 35 | #define SIGEV_THREAD 3 /* A notification function shall be called to */ |
---|
| 36 | /* perform notification. */ |
---|
| 37 | |
---|
| 38 | /* Signal Generation and Delivery, P1003.1b-1993, p. 63 |
---|
| 39 | NOTE: P1003.1c/D10, p. 34 adds sigev_notify_function and |
---|
| 40 | sigev_notify_attributes to the sigevent structure. */ |
---|
| 41 | |
---|
| 42 | union sigval { |
---|
| 43 | int sival_int; /* Integer signal value */ |
---|
| 44 | void *sival_ptr; /* Pointer signal value */ |
---|
| 45 | }; |
---|
| 46 | |
---|
| 47 | struct sigevent { |
---|
| 48 | int sigev_notify; /* Notification type */ |
---|
| 49 | int sigev_signo; /* Signal number */ |
---|
| 50 | union sigval sigev_value; /* Signal value */ |
---|
| 51 | |
---|
| 52 | #if defined(_POSIX_THREADS) |
---|
| 53 | void (*sigev_notify_function)( union sigval ); |
---|
| 54 | /* Notification function */ |
---|
| 55 | pthread_attr_t *sigev_notify_attributes; /* Notification Attributes */ |
---|
| 56 | #endif |
---|
| 57 | }; |
---|
| 58 | |
---|
| 59 | /* Signal Actions, P1003.1b-1993, p. 64 */ |
---|
| 60 | /* si_code values, p. 66 */ |
---|
| 61 | |
---|
| 62 | #define SI_USER 1 /* Sent by a user. kill(), abort(), etc */ |
---|
| 63 | #define SI_QUEUE 2 /* Sent by sigqueue() */ |
---|
| 64 | #define SI_TIMER 3 /* Sent by expiration of a timer_settime() timer */ |
---|
| 65 | #define SI_ASYNCIO 4 /* Indicates completion of asycnhronous IO */ |
---|
| 66 | #define SI_MESGQ 5 /* Indicates arrival of a message at an empty queue */ |
---|
| 67 | |
---|
| 68 | typedef struct { |
---|
| 69 | int si_signo; /* Signal number */ |
---|
| 70 | int si_code; /* Cause of the signal */ |
---|
| 71 | union sigval si_value; /* Signal value */ |
---|
| 72 | } siginfo_t; |
---|
| 73 | #endif /* defined(_POSIX_REALTIME_SIGNALS) || __POSIX_VISIBLE >= 199309 */ |
---|
| 74 | |
---|
| 75 | #if defined(__rtems__) |
---|
| 76 | |
---|
| 77 | /* 3.3.8 Synchronously Accept a Signal, P1003.1b-1993, p. 76 */ |
---|
| 78 | |
---|
| 79 | #define SA_NOCLDSTOP 0x1 /* Do not generate SIGCHLD when children stop */ |
---|
| 80 | #define SA_SIGINFO 0x2 /* Invoke the signal catching function with */ |
---|
| 81 | /* three arguments instead of one. */ |
---|
| 82 | #if __BSD_VISIBLE || __XSI_VISIBLE >= 4 || __POSIX_VISIBLE >= 200809 |
---|
| 83 | #define SA_ONSTACK 0x4 /* Signal delivery will be on a separate stack. */ |
---|
| 84 | #endif |
---|
| 85 | |
---|
| 86 | /* struct sigaction notes from POSIX: |
---|
| 87 | * |
---|
| 88 | * (1) Routines stored in sa_handler should take a single int as |
---|
| 89 | * their argument although the POSIX standard does not require this. |
---|
| 90 | * This is not longer true since at least POSIX.1-2008 |
---|
| 91 | * (2) The fields sa_handler and sa_sigaction may overlap, and a conforming |
---|
| 92 | * application should not use both simultaneously. |
---|
| 93 | */ |
---|
| 94 | |
---|
| 95 | typedef void (*_sig_func_ptr)(int); |
---|
| 96 | |
---|
| 97 | struct sigaction { |
---|
| 98 | int sa_flags; /* Special flags to affect behavior of signal */ |
---|
| 99 | sigset_t sa_mask; /* Additional set of signals to be blocked */ |
---|
| 100 | /* during execution of signal-catching */ |
---|
| 101 | /* function. */ |
---|
| 102 | union { |
---|
| 103 | _sig_func_ptr _handler; /* SIG_DFL, SIG_IGN, or pointer to a function */ |
---|
| 104 | #if defined(_POSIX_REALTIME_SIGNALS) |
---|
| 105 | void (*_sigaction)( int, siginfo_t *, void * ); |
---|
| 106 | #endif |
---|
| 107 | } _signal_handlers; |
---|
| 108 | }; |
---|
| 109 | |
---|
| 110 | #define sa_handler _signal_handlers._handler |
---|
| 111 | #if defined(_POSIX_REALTIME_SIGNALS) |
---|
| 112 | #define sa_sigaction _signal_handlers._sigaction |
---|
| 113 | #endif |
---|
| 114 | |
---|
| 115 | #else /* defined(__rtems__) */ |
---|
| 116 | |
---|
| 117 | #define SA_NOCLDSTOP 1 /* only value supported now for sa_flags */ |
---|
| 118 | |
---|
| 119 | typedef void (*_sig_func_ptr)(int); |
---|
| 120 | |
---|
| 121 | struct sigaction |
---|
| 122 | { |
---|
| 123 | _sig_func_ptr sa_handler; |
---|
| 124 | sigset_t sa_mask; |
---|
| 125 | int sa_flags; |
---|
| 126 | }; |
---|
| 127 | #endif /* defined(__rtems__) */ |
---|
| 128 | #endif /* defined(__CYGWIN__) */ |
---|
| 129 | |
---|
| 130 | #if __BSD_VISIBLE || __XSI_VISIBLE >= 4 || __POSIX_VISIBLE >= 200809 |
---|
| 131 | /* |
---|
| 132 | * Minimum and default signal stack constants. Allow for target overrides |
---|
| 133 | * from <sys/features.h>. |
---|
| 134 | */ |
---|
| 135 | #ifndef MINSIGSTKSZ |
---|
| 136 | #define MINSIGSTKSZ 2048 |
---|
| 137 | #endif |
---|
| 138 | #ifndef SIGSTKSZ |
---|
| 139 | #define SIGSTKSZ 8192 |
---|
| 140 | #endif |
---|
| 141 | |
---|
| 142 | /* |
---|
| 143 | * Possible values for ss_flags in stack_t below. |
---|
| 144 | */ |
---|
| 145 | #define SS_ONSTACK 0x1 |
---|
| 146 | #define SS_DISABLE 0x2 |
---|
| 147 | |
---|
| 148 | #endif |
---|
| 149 | |
---|
| 150 | /* |
---|
| 151 | * Structure used in sigaltstack call. |
---|
| 152 | */ |
---|
| 153 | typedef struct sigaltstack { |
---|
| 154 | void *ss_sp; /* Stack base or pointer. */ |
---|
| 155 | int ss_flags; /* Flags. */ |
---|
| 156 | size_t ss_size; /* Stack size. */ |
---|
| 157 | } stack_t; |
---|
| 158 | |
---|
| 159 | #if __POSIX_VISIBLE |
---|
| 160 | #define SIG_SETMASK 0 /* set mask with sigprocmask() */ |
---|
| 161 | #define SIG_BLOCK 1 /* set of signals to block */ |
---|
| 162 | #define SIG_UNBLOCK 2 /* set of signals to, well, unblock */ |
---|
| 163 | |
---|
| 164 | int sigprocmask (int how, const sigset_t *set, sigset_t *oset); |
---|
| 165 | #endif |
---|
| 166 | |
---|
| 167 | #if __POSIX_VISIBLE >= 199506 |
---|
| 168 | int pthread_sigmask (int how, const sigset_t *set, sigset_t *oset); |
---|
| 169 | #endif |
---|
| 170 | |
---|
| 171 | #ifdef _COMPILING_NEWLIB |
---|
| 172 | int _kill (pid_t, int); |
---|
| 173 | #endif /* _COMPILING_NEWLIB */ |
---|
| 174 | |
---|
| 175 | #if __POSIX_VISIBLE |
---|
| 176 | int kill (pid_t, int); |
---|
| 177 | #endif |
---|
| 178 | |
---|
| 179 | #if __BSD_VISIBLE || __XSI_VISIBLE >= 4 |
---|
| 180 | int killpg (pid_t, int); |
---|
| 181 | #endif |
---|
| 182 | #if __POSIX_VISIBLE |
---|
| 183 | int sigaction (int, const struct sigaction *, struct sigaction *); |
---|
| 184 | int sigaddset (sigset_t *, const int); |
---|
| 185 | int sigdelset (sigset_t *, const int); |
---|
| 186 | int sigismember (const sigset_t *, int); |
---|
| 187 | int sigfillset (sigset_t *); |
---|
| 188 | int sigemptyset (sigset_t *); |
---|
| 189 | int sigpending (sigset_t *); |
---|
| 190 | int sigsuspend (const sigset_t *); |
---|
| 191 | int sigwait (const sigset_t *set, int *sig); |
---|
| 192 | |
---|
| 193 | #if !defined(__CYGWIN__) && !defined(__rtems__) |
---|
| 194 | /* These depend upon the type of sigset_t, which right now |
---|
| 195 | is always a long.. They're in the POSIX namespace, but |
---|
| 196 | are not ANSI. */ |
---|
| 197 | #define sigaddset(what,sig) (*(what) |= (1<<(sig)), 0) |
---|
| 198 | #define sigdelset(what,sig) (*(what) &= ~(1<<(sig)), 0) |
---|
| 199 | #define sigemptyset(what) (*(what) = 0, 0) |
---|
| 200 | #define sigfillset(what) (*(what) = ~(0), 0) |
---|
| 201 | #define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0) |
---|
| 202 | #endif /* !__CYGWIN__ && !__rtems__ */ |
---|
| 203 | #endif /* __POSIX_VISIBLE */ |
---|
| 204 | |
---|
| 205 | /* There are two common sigpause variants, both of which take an int argument. |
---|
| 206 | If you request _XOPEN_SOURCE or _GNU_SOURCE, you get the System V version, |
---|
| 207 | which removes the given signal from the process's signal mask; otherwise |
---|
| 208 | you get the BSD version, which sets the process's signal mask to the given |
---|
| 209 | value. */ |
---|
| 210 | #if __XSI_VISIBLE && !defined(__INSIDE_CYGWIN__) |
---|
| 211 | # ifdef __GNUC__ |
---|
| 212 | int sigpause (int) __asm__ (__ASMNAME ("__xpg_sigpause")); |
---|
| 213 | # else |
---|
| 214 | int __xpg_sigpause (int); |
---|
| 215 | # define sigpause __xpg_sigpause |
---|
| 216 | # endif |
---|
| 217 | #elif __BSD_VISIBLE |
---|
| 218 | int sigpause (int); |
---|
| 219 | #endif |
---|
| 220 | |
---|
| 221 | #if __BSD_VISIBLE || __XSI_VISIBLE >= 4 || __POSIX_VISIBLE >= 200809 |
---|
| 222 | int sigaltstack (const stack_t *__restrict, stack_t *__restrict); |
---|
| 223 | #endif |
---|
| 224 | |
---|
| 225 | #if __POSIX_VISIBLE >= 199506 |
---|
| 226 | int pthread_kill (pthread_t thread, int sig); |
---|
| 227 | #endif |
---|
| 228 | |
---|
| 229 | #if __POSIX_VISIBLE >= 199309 |
---|
| 230 | |
---|
| 231 | /* 3.3.8 Synchronously Accept a Signal, P1003.1b-1993, p. 76 |
---|
| 232 | NOTE: P1003.1c/D10, p. 39 adds sigwait(). */ |
---|
| 233 | |
---|
| 234 | int sigwaitinfo (const sigset_t *set, siginfo_t *info); |
---|
| 235 | int sigtimedwait (const sigset_t *set, siginfo_t *info, |
---|
| 236 | const struct timespec *timeout); |
---|
| 237 | /* 3.3.9 Queue a Signal to a Process, P1003.1b-1993, p. 78 */ |
---|
| 238 | int sigqueue (pid_t pid, int signo, const union sigval value); |
---|
| 239 | |
---|
| 240 | #endif /* __POSIX_VISIBLE >= 199309 */ |
---|
| 241 | |
---|
| 242 | #if defined(___AM29K__) |
---|
| 243 | /* These all need to be defined for ANSI C, but I don't think they are |
---|
| 244 | meaningful. */ |
---|
| 245 | #define SIGABRT 1 |
---|
| 246 | #define SIGFPE 1 |
---|
| 247 | #define SIGILL 1 |
---|
| 248 | #define SIGINT 1 |
---|
| 249 | #define SIGSEGV 1 |
---|
| 250 | #define SIGTERM 1 |
---|
| 251 | /* These need to be defined for POSIX, and some others do too. */ |
---|
| 252 | #define SIGHUP 1 |
---|
| 253 | #define SIGQUIT 1 |
---|
| 254 | #define NSIG 2 |
---|
| 255 | #elif defined(__GO32__) |
---|
| 256 | #define SIGINT 1 |
---|
| 257 | #define SIGKILL 2 |
---|
| 258 | #define SIGPIPE 3 |
---|
| 259 | #define SIGFPE 4 |
---|
| 260 | #define SIGHUP 5 |
---|
| 261 | #define SIGTERM 6 |
---|
| 262 | #define SIGSEGV 7 |
---|
| 263 | #define SIGTSTP 8 |
---|
| 264 | #define SIGQUIT 9 |
---|
| 265 | #define SIGTRAP 10 |
---|
| 266 | #define SIGILL 11 |
---|
| 267 | #define SIGEMT 12 |
---|
| 268 | #define SIGALRM 13 |
---|
| 269 | #define SIGBUS 14 |
---|
| 270 | #define SIGLOST 15 |
---|
| 271 | #define SIGSTOP 16 |
---|
| 272 | #define SIGABRT 17 |
---|
| 273 | #define SIGUSR1 18 |
---|
| 274 | #define SIGUSR2 19 |
---|
| 275 | #define NSIG 20 |
---|
| 276 | #elif !defined(SIGTRAP) |
---|
| 277 | #define SIGHUP 1 /* hangup */ |
---|
| 278 | #define SIGINT 2 /* interrupt */ |
---|
| 279 | #define SIGQUIT 3 /* quit */ |
---|
| 280 | #define SIGILL 4 /* illegal instruction (not reset when caught) */ |
---|
| 281 | #define SIGTRAP 5 /* trace trap (not reset when caught) */ |
---|
| 282 | #define SIGIOT 6 /* IOT instruction */ |
---|
| 283 | #define SIGABRT 6 /* used by abort, replace SIGIOT in the future */ |
---|
| 284 | #define SIGEMT 7 /* EMT instruction */ |
---|
| 285 | #define SIGFPE 8 /* floating point exception */ |
---|
| 286 | #define SIGKILL 9 /* kill (cannot be caught or ignored) */ |
---|
| 287 | #define SIGBUS 10 /* bus error */ |
---|
| 288 | #define SIGSEGV 11 /* segmentation violation */ |
---|
| 289 | #define SIGSYS 12 /* bad argument to system call */ |
---|
| 290 | #define SIGPIPE 13 /* write on a pipe with no one to read it */ |
---|
| 291 | #define SIGALRM 14 /* alarm clock */ |
---|
| 292 | #define SIGTERM 15 /* software termination signal from kill */ |
---|
| 293 | |
---|
| 294 | #if defined(__rtems__) |
---|
| 295 | #define SIGURG 16 /* urgent condition on IO channel */ |
---|
| 296 | #define SIGSTOP 17 /* sendable stop signal not from tty */ |
---|
| 297 | #define SIGTSTP 18 /* stop signal from tty */ |
---|
| 298 | #define SIGCONT 19 /* continue a stopped process */ |
---|
| 299 | #define SIGCHLD 20 /* to parent on child stop or exit */ |
---|
| 300 | #define SIGCLD 20 /* System V name for SIGCHLD */ |
---|
| 301 | #define SIGTTIN 21 /* to readers pgrp upon background tty read */ |
---|
| 302 | #define SIGTTOU 22 /* like TTIN for output if (tp->t_local<OSTOP) */ |
---|
| 303 | #define SIGIO 23 /* input/output possible signal */ |
---|
| 304 | #define SIGPOLL SIGIO /* System V name for SIGIO */ |
---|
| 305 | #define SIGWINCH 24 /* window changed */ |
---|
| 306 | #define SIGUSR1 25 /* user defined signal 1 */ |
---|
| 307 | #define SIGUSR2 26 /* user defined signal 2 */ |
---|
| 308 | |
---|
| 309 | /* Real-Time Signals Range, P1003.1b-1993, p. 61 |
---|
| 310 | NOTE: By P1003.1b-1993, this should be at least RTSIG_MAX |
---|
| 311 | (which is a minimum of 8) signals. |
---|
| 312 | */ |
---|
| 313 | #define SIGRTMIN 27 |
---|
| 314 | #define SIGRTMAX 31 |
---|
| 315 | #define __SIGFIRSTNOTRT SIGHUP |
---|
| 316 | #define __SIGLASTNOTRT SIGUSR2 |
---|
| 317 | |
---|
| 318 | #define NSIG 32 /* signal 0 implied */ |
---|
| 319 | |
---|
| 320 | #elif defined(__svr4__) |
---|
| 321 | /* svr4 specifics. different signals above 15, and sigaction. */ |
---|
| 322 | #define SIGUSR1 16 |
---|
| 323 | #define SIGUSR2 17 |
---|
| 324 | #define SIGCLD 18 |
---|
| 325 | #define SIGPWR 19 |
---|
| 326 | #define SIGWINCH 20 |
---|
| 327 | #define SIGPOLL 22 /* 20 for x.out binaries!!!! */ |
---|
| 328 | #define SIGSTOP 23 /* sendable stop signal not from tty */ |
---|
| 329 | #define SIGTSTP 24 /* stop signal from tty */ |
---|
| 330 | #define SIGCONT 25 /* continue a stopped process */ |
---|
| 331 | #define SIGTTIN 26 /* to readers pgrp upon background tty read */ |
---|
| 332 | #define SIGTTOU 27 /* like TTIN for output if (tp->t_local<OSTOP) */ |
---|
| 333 | #define NSIG 28 |
---|
| 334 | #else |
---|
| 335 | #define SIGURG 16 /* urgent condition on IO channel */ |
---|
| 336 | #define SIGSTOP 17 /* sendable stop signal not from tty */ |
---|
| 337 | #define SIGTSTP 18 /* stop signal from tty */ |
---|
| 338 | #define SIGCONT 19 /* continue a stopped process */ |
---|
| 339 | #define SIGCHLD 20 /* to parent on child stop or exit */ |
---|
| 340 | #define SIGCLD 20 /* System V name for SIGCHLD */ |
---|
| 341 | #define SIGTTIN 21 /* to readers pgrp upon background tty read */ |
---|
| 342 | #define SIGTTOU 22 /* like TTIN for output if (tp->t_local<OSTOP) */ |
---|
| 343 | #define SIGIO 23 /* input/output possible signal */ |
---|
| 344 | #define SIGPOLL SIGIO /* System V name for SIGIO */ |
---|
| 345 | #define SIGXCPU 24 /* exceeded CPU time limit */ |
---|
| 346 | #define SIGXFSZ 25 /* exceeded file size limit */ |
---|
| 347 | #define SIGVTALRM 26 /* virtual time alarm */ |
---|
| 348 | #define SIGPROF 27 /* profiling time alarm */ |
---|
| 349 | #define SIGWINCH 28 /* window changed */ |
---|
| 350 | #define SIGLOST 29 /* resource lost (eg, record-lock lost) */ |
---|
| 351 | #define SIGUSR1 30 /* user defined signal 1 */ |
---|
| 352 | #define SIGUSR2 31 /* user defined signal 2 */ |
---|
| 353 | #define NSIG 32 /* signal 0 implied */ |
---|
| 354 | #endif |
---|
| 355 | #endif |
---|
| 356 | |
---|
| 357 | #ifdef __cplusplus |
---|
| 358 | } |
---|
| 359 | #endif |
---|
| 360 | |
---|
| 361 | #if defined(__CYGWIN__) |
---|
| 362 | #if __XSI_VISIBLE >= 4 || __POSIX_VISIBLE >= 200809 |
---|
| 363 | #include <sys/ucontext.h> |
---|
| 364 | #endif |
---|
| 365 | #endif |
---|
| 366 | |
---|
| 367 | #ifndef _SIGNAL_H_ |
---|
| 368 | /* Some applications take advantage of the fact that <sys/signal.h> |
---|
| 369 | * and <signal.h> are equivalent in glibc. Allow for that here. */ |
---|
| 370 | #include <signal.h> |
---|
| 371 | #endif |
---|
| 372 | #endif /* _SYS_SIGNAL_H */ |
---|