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