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