1 #ifndef _WASI_EMULATED_SIGNAL 2 #error "wasm lacks signal support; to enable minimal signal emulation, \ 3 compile with -D_WASI_EMULATED_SIGNAL and link with -lwasi-emulated-signal" 4 #else 5 #ifndef _SIGNAL_H 6 #define _SIGNAL_H 7 8 #ifdef __cplusplus 9 extern "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 18 #ifdef __wasilibc_unmodified_upstream /* WASI has no ucontext support */ 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 49 typedef struct sigaltstack stack_t; 50 #endif 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 60 #ifdef __wasilibc_unmodified_upstream /* WASI has no sigaction */ 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 99 union sigval { 100 int sival_int; 101 void *sival_ptr; 102 }; 103 104 typedef 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 174 struct 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 186 struct sigevent { 187 union sigval sigev_value; 188 int sigev_signo; 189 int sigev_notify; 190 union { 191 char __pad[64 - 2*sizeof(int) - sizeof(union sigval)]; 192 pid_t sigev_notify_thread_id; 193 struct { 194 void (*sigev_notify_function)(union sigval); 195 pthread_attr_t *sigev_notify_attributes; 196 } __sev_thread; 197 } __sev_fields; 198 }; 199 200 #define sigev_notify_thread_id __sev_fields.sigev_notify_thread_id 201 #define sigev_notify_function __sev_fields.__sev_thread.sigev_notify_function 202 #define sigev_notify_attributes __sev_fields.__sev_thread.sigev_notify_attributes 203 204 #define SIGEV_SIGNAL 0 205 #define SIGEV_NONE 1 206 #define SIGEV_THREAD 2 207 #define SIGEV_THREAD_ID 4 208 #endif 209 210 #ifdef __wasilibc_unmodified_upstream /* WASI has no realtime signals */ 211 int __libc_current_sigrtmin(void); 212 int __libc_current_sigrtmax(void); 213 214 #define SIGRTMIN (__libc_current_sigrtmin()) 215 #define SIGRTMAX (__libc_current_sigrtmax()) 216 #endif 217 218 #ifdef __wasilibc_unmodified_upstream /* WASI has no signals */ 219 int kill(pid_t, int); 220 221 int sigemptyset(sigset_t *); 222 int sigfillset(sigset_t *); 223 int sigaddset(sigset_t *, int); 224 int sigdelset(sigset_t *, int); 225 int sigismember(const sigset_t *, int); 226 227 int sigprocmask(int, const sigset_t *__restrict, sigset_t *__restrict); 228 int sigsuspend(const sigset_t *); 229 int sigaction(int, const struct sigaction *__restrict, struct sigaction *__restrict); 230 int sigpending(sigset_t *); 231 int sigwait(const sigset_t *__restrict, int *__restrict); 232 int sigwaitinfo(const sigset_t *__restrict, siginfo_t *__restrict); 233 int sigtimedwait(const sigset_t *__restrict, siginfo_t *__restrict, const struct timespec *__restrict); 234 int sigqueue(pid_t, int, union sigval); 235 #endif 236 237 #ifdef __wasilibc_unmodified_upstream /* WASI has no threads yet */ 238 int pthread_sigmask(int, const sigset_t *__restrict, sigset_t *__restrict); 239 int pthread_kill(pthread_t, int); 240 #endif 241 242 #ifdef __wasilibc_unmodified_upstream /* WASI has no siginfo */ 243 void psiginfo(const siginfo_t *, const char *); 244 #endif 245 void psignal(int, const char *); 246 247 #endif 248 249 #ifdef __wasilibc_unmodified_upstream /* WASI has no signals */ 250 #if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE) 251 int killpg(pid_t, int); 252 int sigaltstack(const stack_t *__restrict, stack_t *__restrict); 253 int sighold(int); 254 int sigignore(int); 255 int siginterrupt(int, int); 256 int sigpause(int); 257 int sigrelse(int); 258 void (*sigset(int, void (*)(int)))(int); 259 #define TRAP_BRKPT 1 260 #define TRAP_TRACE 2 261 #define TRAP_BRANCH 3 262 #define TRAP_HWBKPT 4 263 #define TRAP_UNK 5 264 #define POLL_IN 1 265 #define POLL_OUT 2 266 #define POLL_MSG 3 267 #define POLL_ERR 4 268 #define POLL_PRI 5 269 #define POLL_HUP 6 270 #define SS_ONSTACK 1 271 #define SS_DISABLE 2 272 #define SS_AUTODISARM (1U << 31) 273 #define SS_FLAG_BITS SS_AUTODISARM 274 #endif 275 #endif 276 277 #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) 278 #define NSIG _NSIG 279 typedef void (*sig_t)(int); 280 #endif 281 282 #ifdef _GNU_SOURCE 283 typedef void (*sighandler_t)(int); 284 void (*bsd_signal(int, void (*)(int)))(int); 285 #ifdef __wasilibc_unmodified_upstream /* WASI has no signal sets */ 286 int sigisemptyset(const sigset_t *); 287 int sigorset (sigset_t *, const sigset_t *, const sigset_t *); 288 int sigandset(sigset_t *, const sigset_t *, const sigset_t *); 289 290 #define SA_NOMASK SA_NODEFER 291 #define SA_ONESHOT SA_RESETHAND 292 #endif 293 #endif 294 295 #ifdef __wasilibc_unmodified_upstream /* 1 is a valid function pointer on wasm */ 296 #define SIG_ERR ((void (*)(int))-1) 297 #define SIG_DFL ((void (*)(int)) 0) 298 #define SIG_IGN ((void (*)(int)) 1) 299 #else 300 void __SIG_ERR(int); 301 void __SIG_IGN(int); 302 #define SIG_ERR (__SIG_ERR) 303 #define SIG_DFL ((void (*)(int)) 0) 304 #define SIG_IGN (__SIG_IGN) 305 #endif 306 307 #ifdef __wasilibc_unmodified_upstream /* Make sig_atomic_t 64-bit on wasm64 */ 308 typedef int sig_atomic_t; 309 #else 310 typedef long sig_atomic_t; 311 #endif 312 313 void (*signal(int, void (*)(int)))(int); 314 int raise(int); 315 316 #ifdef __wasilibc_unmodified_upstream /* WASI has no sigtimedwait */ 317 #if _REDIR_TIME64 318 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ 319 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ 320 || defined(_BSD_SOURCE) 321 __REDIR(sigtimedwait, __sigtimedwait_time64); 322 #endif 323 #endif 324 #endif 325 326 #ifdef __cplusplus 327 } 328 #endif 329 330 #endif 331 #endif 332