Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 1 | #ifndef _SIGNAL_H |
| 2 | #define _SIGNAL_H |
| 3 | |
| 4 | #ifdef __cplusplus |
| 5 | extern "C" { |
| 6 | #endif |
| 7 | |
Rich Felker | 400c5e5 | 2012-09-06 22:44:55 -0400 | [diff] [blame^] | 8 | #if __STDC_VERSION__ >= 199901L |
| 9 | #define __restrict restrict |
| 10 | #elif !defined(__GNUC__) |
| 11 | #define __restrict |
| 12 | #endif |
| 13 | |
Rich Felker | 1322cb8 | 2011-02-14 20:33:54 -0500 | [diff] [blame] | 14 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ |
Rich Felker | 419ae6d | 2012-05-22 21:52:08 -0400 | [diff] [blame] | 15 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ |
| 16 | || defined(_BSD_SOURCE) |
Rich Felker | 1322cb8 | 2011-02-14 20:33:54 -0500 | [diff] [blame] | 17 | |
Rich Felker | 03a8362 | 2011-09-20 10:58:18 -0400 | [diff] [blame] | 18 | #ifdef _GNU_SOURCE |
| 19 | #define __siginfo siginfo |
| 20 | #endif |
| 21 | |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 22 | #define __NEED_size_t |
| 23 | #define __NEED_pid_t |
| 24 | #define __NEED_uid_t |
| 25 | #define __NEED_struct_timespec |
| 26 | #define __NEED_pthread_t |
Rich Felker | 80c4dcd | 2011-03-29 13:01:25 -0400 | [diff] [blame] | 27 | #define __NEED_pthread_attr_t |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 28 | #define __NEED_time_t |
| 29 | #define __NEED_clock_t |
| 30 | #define __NEED_sigset_t |
| 31 | #define __NEED_siginfo_t |
| 32 | |
| 33 | #include <bits/alltypes.h> |
| 34 | |
Rich Felker | 81a5577 | 2011-09-21 22:25:31 -0400 | [diff] [blame] | 35 | #define SIG_HOLD ((void (*)(int)) 2) |
| 36 | |
Rich Felker | f780ac5 | 2011-09-19 20:02:12 -0400 | [diff] [blame] | 37 | #define SIG_BLOCK 0 |
| 38 | #define SIG_UNBLOCK 1 |
| 39 | #define SIG_SETMASK 2 |
| 40 | |
Rich Felker | f780ac5 | 2011-09-19 20:02:12 -0400 | [diff] [blame] | 41 | #define SI_ASYNCNL (-60) |
| 42 | #define SI_TKILL (-6) |
| 43 | #define SI_SIGIO (-5) |
| 44 | #define SI_ASYNCIO (-4) |
| 45 | #define SI_MESGQ (-3) |
| 46 | #define SI_TIMER (-2) |
| 47 | #define SI_QUEUE (-1) |
| 48 | #define SI_USER 0 |
| 49 | #define SI_KERNEL 128 |
| 50 | |
| 51 | #define FPE_INTDIV 1 |
| 52 | #define FPE_INTOVF 2 |
| 53 | #define FPE_FLTDIV 3 |
| 54 | #define FPE_FLTOVF 4 |
Rich Felker | 8eb9a3a | 2012-01-25 15:30:42 -0500 | [diff] [blame] | 55 | #define FPE_FLTUND 5 |
Rich Felker | f780ac5 | 2011-09-19 20:02:12 -0400 | [diff] [blame] | 56 | #define FPE_FLTRES 6 |
| 57 | #define FPE_FLTINV 7 |
| 58 | #define FPE_FLTSUB 8 |
| 59 | |
| 60 | #define ILL_ILLOPC 1 |
| 61 | #define ILL_ILLOPN 2 |
| 62 | #define ILL_ILLADR 3 |
| 63 | #define ILL_ILLTRP 4 |
| 64 | #define ILL_PRVOPC 5 |
| 65 | #define ILL_PRVREG 6 |
| 66 | #define ILL_COPROC 7 |
| 67 | #define ILL_BADSTK 8 |
| 68 | |
| 69 | #define SEGV_MAPERR 1 |
| 70 | #define SEGV_ACCERR 2 |
| 71 | |
| 72 | #define BUS_ADRALN 1 |
| 73 | #define BUS_ADRERR 2 |
| 74 | #define BUS_OBJERR 3 |
| 75 | |
| 76 | #define CLD_EXITED 1 |
| 77 | #define CLD_KILLED 2 |
| 78 | #define CLD_DUMPED 3 |
| 79 | #define CLD_TRAPPED 4 |
| 80 | #define CLD_STOPPED 5 |
| 81 | #define CLD_CONTINUED 6 |
| 82 | |
Rich Felker | 80c4dcd | 2011-03-29 13:01:25 -0400 | [diff] [blame] | 83 | struct sigaction { |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 84 | union { |
| 85 | void (*sa_handler)(int); |
| 86 | void (*sa_sigaction)(int, siginfo_t *, void *); |
| 87 | } __sa_handler; |
| 88 | sigset_t sa_mask; |
| 89 | int sa_flags; |
Rich Felker | 0115a6e | 2012-04-13 23:06:54 -0400 | [diff] [blame] | 90 | void (*sa_restorer)(void); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 91 | }; |
| 92 | #define sa_handler __sa_handler.sa_handler |
| 93 | #define sa_sigaction __sa_handler.sa_sigaction |
| 94 | |
Rich Felker | 80c4dcd | 2011-03-29 13:01:25 -0400 | [diff] [blame] | 95 | typedef struct { |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 96 | void *ss_sp; |
| 97 | int ss_flags; |
| 98 | size_t ss_size; |
| 99 | } stack_t; |
| 100 | |
Rich Felker | 80c4dcd | 2011-03-29 13:01:25 -0400 | [diff] [blame] | 101 | union sigval { |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 102 | int sival_int; |
| 103 | void *sival_ptr; |
| 104 | }; |
| 105 | |
Rich Felker | 03a8362 | 2011-09-20 10:58:18 -0400 | [diff] [blame] | 106 | struct __siginfo { |
Rich Felker | f780ac5 | 2011-09-19 20:02:12 -0400 | [diff] [blame] | 107 | int si_signo, si_errno, si_code; |
| 108 | union { |
| 109 | char __pad[128 - 3*sizeof(int)]; |
| 110 | struct { |
| 111 | pid_t si_pid; |
| 112 | uid_t si_uid; |
| 113 | union sigval si_sigval; |
| 114 | } __rt; |
| 115 | struct { |
| 116 | unsigned int si_timer1, si_timer2; |
| 117 | } __timer; |
| 118 | struct { |
| 119 | pid_t si_pid; |
| 120 | uid_t si_uid; |
| 121 | int si_status; |
| 122 | clock_t si_utime, si_stime; |
| 123 | } __sigchld; |
| 124 | struct { |
| 125 | void *si_addr; |
| 126 | } __sigfault; |
| 127 | struct { |
| 128 | long si_band; |
| 129 | int si_fd; |
| 130 | } __sigpoll; |
| 131 | } __si_fields; |
| 132 | }; |
| 133 | #define si_pid __si_fields.__sigchld.si_pid |
| 134 | #define si_uid __si_fields.__sigchld.si_uid |
| 135 | #define si_status __si_fields.__sigchld.si_status |
| 136 | #define si_utime __si_fields.__sigchld.si_utime |
| 137 | #define si_stime __si_fields.__sigchld.si_stime |
| 138 | #define si_value __si_fields.__rt.si_sigval |
| 139 | #define si_addr __si_fields.__sigfault.si_addr |
| 140 | #define si_band __si_fields.__sigpoll.si_band |
| 141 | #define si_fd __si_fields.__sigpoll.si_fd |
| 142 | #define si_timer1 __si_fields.__timer.si_timer1 |
| 143 | #define si_timer2 __si_fields.__timer.si_timer2 |
Rich Felker | 8c07f6e | 2011-09-19 22:27:02 -0400 | [diff] [blame] | 144 | #define si_ptr __si_fields.__rt.si_sigval.sival_ptr |
| 145 | #define si_int __si_fields.__rt.si_sigval.sival_int |
Rich Felker | f780ac5 | 2011-09-19 20:02:12 -0400 | [diff] [blame] | 146 | |
Rich Felker | 80c4dcd | 2011-03-29 13:01:25 -0400 | [diff] [blame] | 147 | struct sigevent { |
| 148 | union sigval sigev_value; |
| 149 | int sigev_signo; |
| 150 | int sigev_notify; |
| 151 | void (*sigev_notify_function)(union sigval); |
| 152 | pthread_attr_t *sigev_notify_attributes; |
Rich Felker | 7f54715 | 2011-06-16 17:11:35 -0400 | [diff] [blame] | 153 | char __pad[56-3*sizeof(long)]; |
Rich Felker | 80c4dcd | 2011-03-29 13:01:25 -0400 | [diff] [blame] | 154 | }; |
| 155 | |
| 156 | #define SIGEV_SIGNAL 0 |
| 157 | #define SIGEV_NONE 1 |
| 158 | #define SIGEV_THREAD 2 |
| 159 | |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 160 | int __libc_current_sigrtmin(void); |
| 161 | int __libc_current_sigrtmax(void); |
| 162 | |
| 163 | #define SIGRTMIN (__libc_current_sigrtmin()) |
| 164 | #define SIGRTMAX (__libc_current_sigrtmax()) |
| 165 | |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 166 | int kill(pid_t, int); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 167 | |
| 168 | int sigemptyset(sigset_t *); |
| 169 | int sigfillset(sigset_t *); |
| 170 | int sigaddset(sigset_t *, int); |
| 171 | int sigdelset(sigset_t *, int); |
| 172 | int sigismember(const sigset_t *, int); |
| 173 | |
Rich Felker | 400c5e5 | 2012-09-06 22:44:55 -0400 | [diff] [blame^] | 174 | int sigprocmask(int, const sigset_t *__restrict, sigset_t *__restrict); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 175 | int sigsuspend(const sigset_t *); |
Rich Felker | 400c5e5 | 2012-09-06 22:44:55 -0400 | [diff] [blame^] | 176 | int sigaction(int, const struct sigaction *__restrict, struct sigaction *__restrict); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 177 | int sigpending(sigset_t *); |
Rich Felker | 400c5e5 | 2012-09-06 22:44:55 -0400 | [diff] [blame^] | 178 | int sigwait(const sigset_t *__restrict, int *__restrict); |
| 179 | int sigwaitinfo(const sigset_t *__restrict, siginfo_t *__restrict); |
| 180 | int sigtimedwait(const sigset_t *__restrict, siginfo_t *__restrict, const struct timespec *__restrict); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 181 | int sigqueue(pid_t, int, const union sigval); |
| 182 | |
Rich Felker | 400c5e5 | 2012-09-06 22:44:55 -0400 | [diff] [blame^] | 183 | int pthread_sigmask(int, const sigset_t *__restrict, sigset_t *__restrict); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 184 | int pthread_kill(pthread_t, int); |
| 185 | |
Rich Felker | adb7093 | 2011-09-02 14:25:43 -0400 | [diff] [blame] | 186 | void psiginfo(const siginfo_t *, const char *); |
| 187 | void psignal(int, const char *); |
| 188 | |
Rich Felker | 1322cb8 | 2011-02-14 20:33:54 -0500 | [diff] [blame] | 189 | #endif |
| 190 | |
| 191 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) |
| 192 | int killpg(pid_t, int); |
Rich Felker | 400c5e5 | 2012-09-06 22:44:55 -0400 | [diff] [blame^] | 193 | int sigaltstack(const stack_t *__restrict, stack_t *__restrict); |
Rich Felker | 1322cb8 | 2011-02-14 20:33:54 -0500 | [diff] [blame] | 194 | int sighold(int); |
| 195 | int sigignore(int); |
| 196 | int siginterrupt(int, int); |
| 197 | int sigpause(int); |
| 198 | int sigrelse(int); |
| 199 | void (*sigset(int, void (*)(int)))(int); |
Rich Felker | f780ac5 | 2011-09-19 20:02:12 -0400 | [diff] [blame] | 200 | #define TRAP_BRKPT 1 |
| 201 | #define TRAP_TRACE 2 |
| 202 | #define POLL_IN 1 |
| 203 | #define POLL_OUT 2 |
| 204 | #define POLL_MSG 3 |
| 205 | #define POLL_ERR 4 |
| 206 | #define POLL_PRI 5 |
| 207 | #define POLL_HUP 6 |
| 208 | #define SS_ONSTACK 1 |
| 209 | #define SS_DISABLE 2 |
| 210 | #define MINSIGSTKSZ 2048 |
| 211 | #define SIGSTKSZ 8192 |
Rich Felker | 1322cb8 | 2011-02-14 20:33:54 -0500 | [diff] [blame] | 212 | #endif |
| 213 | |
Rich Felker | 419ae6d | 2012-05-22 21:52:08 -0400 | [diff] [blame] | 214 | #ifdef _BSD_SOURCE |
| 215 | typedef void (*sig_t)(int); |
| 216 | #endif |
| 217 | |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 218 | #ifdef _GNU_SOURCE |
Rich Felker | 0f5b435 | 2011-04-13 08:45:28 -0400 | [diff] [blame] | 219 | typedef void (*sighandler_t)(int); |
Rich Felker | 9f370fa | 2012-05-22 21:54:19 -0400 | [diff] [blame] | 220 | void (*bsd_signal(int, void (*)(int)))(int); |
Rich Felker | fb80e04 | 2011-09-12 00:00:30 -0400 | [diff] [blame] | 221 | int sigisemptyset(const sigset_t *); |
Rich Felker | 2029114 | 2011-05-05 17:44:06 -0400 | [diff] [blame] | 222 | #define SA_NOMASK SA_NODEFER |
Rich Felker | f780ac5 | 2011-09-19 20:02:12 -0400 | [diff] [blame] | 223 | #define SA_ONESHOT SA_RESETHAND |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 224 | #endif |
| 225 | |
Rich Felker | 3eb9fea | 2011-02-15 15:10:00 -0500 | [diff] [blame] | 226 | #include <bits/signal.h> |
| 227 | |
Rich Felker | 81a5577 | 2011-09-21 22:25:31 -0400 | [diff] [blame] | 228 | #define SIG_ERR ((void (*)(int))-1) |
| 229 | #define SIG_DFL ((void (*)(int)) 0) |
| 230 | #define SIG_IGN ((void (*)(int)) 1) |
| 231 | |
Rich Felker | 1322cb8 | 2011-02-14 20:33:54 -0500 | [diff] [blame] | 232 | typedef int sig_atomic_t; |
| 233 | |
| 234 | void (*signal(int, void (*)(int)))(int); |
| 235 | int raise(int); |
| 236 | |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 237 | #ifdef __cplusplus |
| 238 | } |
| 239 | #endif |
| 240 | |
| 241 | #endif |