]> git.proxmox.com Git - wasi-libc.git/blame - libc-top-half/musl/include/signal.h
Update upstream source from tag 'upstream/0.0_git20200731.215adc8'
[wasi-libc.git] / libc-top-half / musl / include / signal.h
CommitLineData
d1cd4f48
DG
1#ifndef _WASI_EMULATED_SIGNAL
2#error "wasm lacks signal support; to enable minimal signal emulation, \
3compile with -D_WASI_EMULATED_SIGNAL and link with -lwasi-emulated-signal"
4#else
320054e8
DG
5#ifndef _SIGNAL_H
6#define _SIGNAL_H
7
8#ifdef __cplusplus
9extern "C" {
10#endif
11
12#include <features.h>
13
14#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
15 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
16 || defined(_BSD_SOURCE)
17
079d7bda 18#ifdef __wasilibc_unmodified_upstream /* WASI has no ucontext support */
320054e8
DG
19#ifdef _GNU_SOURCE
20#define __ucontext ucontext
21#endif
22
23#define __NEED_size_t
24#define __NEED_pid_t
25#define __NEED_uid_t
26#define __NEED_struct_timespec
27#define __NEED_pthread_t
28#define __NEED_pthread_attr_t
29#define __NEED_time_t
30#define __NEED_clock_t
31#define __NEED_sigset_t
32
33#include <bits/alltypes.h>
34
35#define SIG_BLOCK 0
36#define SIG_UNBLOCK 1
37#define SIG_SETMASK 2
38
39#define SI_ASYNCNL (-60)
40#define SI_TKILL (-6)
41#define SI_SIGIO (-5)
42#define SI_ASYNCIO (-4)
43#define SI_MESGQ (-3)
44#define SI_TIMER (-2)
45#define SI_QUEUE (-1)
46#define SI_USER 0
47#define SI_KERNEL 128
48
49typedef struct sigaltstack stack_t;
d1cd4f48 50#endif
320054e8
DG
51
52#endif
53
54#include <bits/signal.h>
55
56#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
57 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
58 || defined(_BSD_SOURCE)
59
d1cd4f48 60#ifdef __wasilibc_unmodified_upstream /* WASI has no sigaction */
320054e8
DG
61#define SIG_HOLD ((void (*)(int)) 2)
62
63#define FPE_INTDIV 1
64#define FPE_INTOVF 2
65#define FPE_FLTDIV 3
66#define FPE_FLTOVF 4
67#define FPE_FLTUND 5
68#define FPE_FLTRES 6
69#define FPE_FLTINV 7
70#define FPE_FLTSUB 8
71
72#define ILL_ILLOPC 1
73#define ILL_ILLOPN 2
74#define ILL_ILLADR 3
75#define ILL_ILLTRP 4
76#define ILL_PRVOPC 5
77#define ILL_PRVREG 6
78#define ILL_COPROC 7
79#define ILL_BADSTK 8
80
81#define SEGV_MAPERR 1
82#define SEGV_ACCERR 2
83#define SEGV_BNDERR 3
84#define SEGV_PKUERR 4
85
86#define BUS_ADRALN 1
87#define BUS_ADRERR 2
88#define BUS_OBJERR 3
89#define BUS_MCEERR_AR 4
90#define BUS_MCEERR_AO 5
91
92#define CLD_EXITED 1
93#define CLD_KILLED 2
94#define CLD_DUMPED 3
95#define CLD_TRAPPED 4
96#define CLD_STOPPED 5
97#define CLD_CONTINUED 6
98
99union sigval {
100 int sival_int;
101 void *sival_ptr;
102};
103
104typedef struct {
105#ifdef __SI_SWAP_ERRNO_CODE
106 int si_signo, si_code, si_errno;
107#else
108 int si_signo, si_errno, si_code;
109#endif
110 union {
111 char __pad[128 - 2*sizeof(int) - sizeof(long)];
112 struct {
113 union {
114 struct {
115 pid_t si_pid;
116 uid_t si_uid;
117 } __piduid;
118 struct {
119 int si_timerid;
120 int si_overrun;
121 } __timer;
122 } __first;
123 union {
124 union sigval si_value;
125 struct {
126 int si_status;
127 clock_t si_utime, si_stime;
128 } __sigchld;
129 } __second;
130 } __si_common;
131 struct {
132 void *si_addr;
133 short si_addr_lsb;
134 union {
135 struct {
136 void *si_lower;
137 void *si_upper;
138 } __addr_bnd;
139 unsigned si_pkey;
140 } __first;
141 } __sigfault;
142 struct {
143 long si_band;
144 int si_fd;
145 } __sigpoll;
146 struct {
147 void *si_call_addr;
148 int si_syscall;
149 unsigned si_arch;
150 } __sigsys;
151 } __si_fields;
152} siginfo_t;
153#define si_pid __si_fields.__si_common.__first.__piduid.si_pid
154#define si_uid __si_fields.__si_common.__first.__piduid.si_uid
155#define si_status __si_fields.__si_common.__second.__sigchld.si_status
156#define si_utime __si_fields.__si_common.__second.__sigchld.si_utime
157#define si_stime __si_fields.__si_common.__second.__sigchld.si_stime
158#define si_value __si_fields.__si_common.__second.si_value
159#define si_addr __si_fields.__sigfault.si_addr
160#define si_addr_lsb __si_fields.__sigfault.si_addr_lsb
161#define si_lower __si_fields.__sigfault.__first.__addr_bnd.si_lower
162#define si_upper __si_fields.__sigfault.__first.__addr_bnd.si_upper
163#define si_pkey __si_fields.__sigfault.__first.si_pkey
164#define si_band __si_fields.__sigpoll.si_band
165#define si_fd __si_fields.__sigpoll.si_fd
166#define si_timerid __si_fields.__si_common.__first.__timer.si_timerid
167#define si_overrun __si_fields.__si_common.__first.__timer.si_overrun
168#define si_ptr si_value.sival_ptr
169#define si_int si_value.sival_int
170#define si_call_addr __si_fields.__sigsys.si_call_addr
171#define si_syscall __si_fields.__sigsys.si_syscall
172#define si_arch __si_fields.__sigsys.si_arch
173
174struct sigaction {
175 union {
176 void (*sa_handler)(int);
177 void (*sa_sigaction)(int, siginfo_t *, void *);
178 } __sa_handler;
179 sigset_t sa_mask;
180 int sa_flags;
181 void (*sa_restorer)(void);
182};
183#define sa_handler __sa_handler.sa_handler
184#define sa_sigaction __sa_handler.sa_sigaction
185
186struct sigevent {
187 union sigval sigev_value;
188 int sigev_signo;
189 int sigev_notify;
190 void (*sigev_notify_function)(union sigval);
191 pthread_attr_t *sigev_notify_attributes;
192 char __pad[56-3*sizeof(long)];
193};
194
195#define SIGEV_SIGNAL 0
196#define SIGEV_NONE 1
197#define SIGEV_THREAD 2
d1cd4f48 198#endif
320054e8 199
e5f14be3 200#ifdef __wasilibc_unmodified_upstream /* WASI has no realtime signals */
320054e8
DG
201int __libc_current_sigrtmin(void);
202int __libc_current_sigrtmax(void);
203
204#define SIGRTMIN (__libc_current_sigrtmin())
205#define SIGRTMAX (__libc_current_sigrtmax())
206#endif
207
e5f14be3 208#ifdef __wasilibc_unmodified_upstream /* WASI has no signals */
320054e8
DG
209int kill(pid_t, int);
210
211int sigemptyset(sigset_t *);
212int sigfillset(sigset_t *);
213int sigaddset(sigset_t *, int);
214int sigdelset(sigset_t *, int);
215int sigismember(const sigset_t *, int);
216
217int sigprocmask(int, const sigset_t *__restrict, sigset_t *__restrict);
218int sigsuspend(const sigset_t *);
219int sigaction(int, const struct sigaction *__restrict, struct sigaction *__restrict);
220int sigpending(sigset_t *);
221int sigwait(const sigset_t *__restrict, int *__restrict);
222int sigwaitinfo(const sigset_t *__restrict, siginfo_t *__restrict);
223int sigtimedwait(const sigset_t *__restrict, siginfo_t *__restrict, const struct timespec *__restrict);
224int sigqueue(pid_t, int, union sigval);
225#endif
226
d1cd4f48 227#ifdef __wasilibc_unmodified_upstream /* WASI has no threads yet */
320054e8
DG
228int pthread_sigmask(int, const sigset_t *__restrict, sigset_t *__restrict);
229int pthread_kill(pthread_t, int);
d1cd4f48 230#endif
320054e8 231
d1cd4f48 232#ifdef __wasilibc_unmodified_upstream /* WASI has no siginfo */
320054e8 233void psiginfo(const siginfo_t *, const char *);
320054e8 234#endif
d1cd4f48 235void psignal(int, const char *);
320054e8
DG
236
237#endif
238
e5f14be3 239#ifdef __wasilibc_unmodified_upstream /* WASI has no signals */
320054e8
DG
240#if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
241int killpg(pid_t, int);
242int sigaltstack(const stack_t *__restrict, stack_t *__restrict);
243int sighold(int);
244int sigignore(int);
245int siginterrupt(int, int);
246int sigpause(int);
247int sigrelse(int);
248void (*sigset(int, void (*)(int)))(int);
249#define TRAP_BRKPT 1
250#define TRAP_TRACE 2
251#define TRAP_BRANCH 3
252#define TRAP_HWBKPT 4
253#define TRAP_UNK 5
254#define POLL_IN 1
255#define POLL_OUT 2
256#define POLL_MSG 3
257#define POLL_ERR 4
258#define POLL_PRI 5
259#define POLL_HUP 6
260#define SS_ONSTACK 1
261#define SS_DISABLE 2
262#define SS_AUTODISARM (1U << 31)
263#define SS_FLAG_BITS SS_AUTODISARM
264#endif
265#endif
266
320054e8
DG
267#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
268#define NSIG _NSIG
269typedef void (*sig_t)(int);
270#endif
271
272#ifdef _GNU_SOURCE
273typedef void (*sighandler_t)(int);
274void (*bsd_signal(int, void (*)(int)))(int);
d1cd4f48 275#ifdef __wasilibc_unmodified_upstream /* WASI has no signal sets */
320054e8
DG
276int sigisemptyset(const sigset_t *);
277int sigorset (sigset_t *, const sigset_t *, const sigset_t *);
278int sigandset(sigset_t *, const sigset_t *, const sigset_t *);
279
280#define SA_NOMASK SA_NODEFER
281#define SA_ONESHOT SA_RESETHAND
282#endif
d1cd4f48 283#endif
320054e8 284
d1cd4f48 285#ifdef __wasilibc_unmodified_upstream /* 1 is a valid function pointer on wasm */
320054e8
DG
286#define SIG_ERR ((void (*)(int))-1)
287#define SIG_DFL ((void (*)(int)) 0)
288#define SIG_IGN ((void (*)(int)) 1)
d1cd4f48
DG
289#else
290void __SIG_ERR(int);
291void __SIG_IGN(int);
292#define SIG_ERR (__SIG_ERR)
293#define SIG_DFL ((void (*)(int)) 0)
294#define SIG_IGN (__SIG_IGN)
320054e8
DG
295#endif
296
d1cd4f48 297#ifdef __wasilibc_unmodified_upstream /* Make sig_atomic_t 64-bit on wasm64 */
320054e8 298typedef int sig_atomic_t;
d1cd4f48
DG
299#else
300typedef long sig_atomic_t;
301#endif
320054e8 302
320054e8 303void (*signal(int, void (*)(int)))(int);
320054e8
DG
304int raise(int);
305
d1cd4f48 306#ifdef __wasilibc_unmodified_upstream /* WASI has no sigtimedwait */
575e1579
DG
307#if _REDIR_TIME64
308#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
309 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
310 || defined(_BSD_SOURCE)
311__REDIR(sigtimedwait, __sigtimedwait_time64);
312#endif
313#endif
d1cd4f48 314#endif
575e1579 315
320054e8
DG
316#ifdef __cplusplus
317}
318#endif
319
320#endif
d1cd4f48 321#endif