blob: e0dae19215951aa19188bffbdea0731c9cfa4884 [file] [log] [blame]
Rich Felker0b44a032011-02-12 00:22:29 -05001#ifndef _SIGNAL_H
2#define _SIGNAL_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
Rich Felker400c5e52012-09-06 22:44:55 -04008#if __STDC_VERSION__ >= 199901L
9#define __restrict restrict
10#elif !defined(__GNUC__)
11#define __restrict
12#endif
13
Rich Felker1322cb82011-02-14 20:33:54 -050014#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
Rich Felker419ae6d2012-05-22 21:52:08 -040015 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
16 || defined(_BSD_SOURCE)
Rich Felker1322cb82011-02-14 20:33:54 -050017
Rich Felker03a83622011-09-20 10:58:18 -040018#ifdef _GNU_SOURCE
19#define __siginfo siginfo
20#endif
21
Rich Felker0b44a032011-02-12 00:22:29 -050022#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 Felker80c4dcd2011-03-29 13:01:25 -040027#define __NEED_pthread_attr_t
Rich Felker0b44a032011-02-12 00:22:29 -050028#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 Felker81a55772011-09-21 22:25:31 -040035#define SIG_HOLD ((void (*)(int)) 2)
36
Rich Felkerf780ac52011-09-19 20:02:12 -040037#define SIG_BLOCK 0
38#define SIG_UNBLOCK 1
39#define SIG_SETMASK 2
40
Rich Felkerf780ac52011-09-19 20:02:12 -040041#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 Felker8eb9a3a2012-01-25 15:30:42 -050055#define FPE_FLTUND 5
Rich Felkerf780ac52011-09-19 20:02:12 -040056#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 Felker80c4dcd2011-03-29 13:01:25 -040083struct sigaction {
Rich Felker0b44a032011-02-12 00:22:29 -050084 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 Felker0115a6e2012-04-13 23:06:54 -040090 void (*sa_restorer)(void);
Rich Felker0b44a032011-02-12 00:22:29 -050091};
92#define sa_handler __sa_handler.sa_handler
93#define sa_sigaction __sa_handler.sa_sigaction
94
Rich Felker80c4dcd2011-03-29 13:01:25 -040095typedef struct {
Rich Felker0b44a032011-02-12 00:22:29 -050096 void *ss_sp;
97 int ss_flags;
98 size_t ss_size;
99} stack_t;
100
Rich Felker80c4dcd2011-03-29 13:01:25 -0400101union sigval {
Rich Felker0b44a032011-02-12 00:22:29 -0500102 int sival_int;
103 void *sival_ptr;
104};
105
Rich Felker03a83622011-09-20 10:58:18 -0400106struct __siginfo {
Rich Felkerf780ac52011-09-19 20:02:12 -0400107 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 Felker8c07f6e2011-09-19 22:27:02 -0400144#define si_ptr __si_fields.__rt.si_sigval.sival_ptr
145#define si_int __si_fields.__rt.si_sigval.sival_int
Rich Felkerf780ac52011-09-19 20:02:12 -0400146
Rich Felker80c4dcd2011-03-29 13:01:25 -0400147struct 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 Felker7f547152011-06-16 17:11:35 -0400153 char __pad[56-3*sizeof(long)];
Rich Felker80c4dcd2011-03-29 13:01:25 -0400154};
155
156#define SIGEV_SIGNAL 0
157#define SIGEV_NONE 1
158#define SIGEV_THREAD 2
159
Rich Felker0b44a032011-02-12 00:22:29 -0500160int __libc_current_sigrtmin(void);
161int __libc_current_sigrtmax(void);
162
163#define SIGRTMIN (__libc_current_sigrtmin())
164#define SIGRTMAX (__libc_current_sigrtmax())
165
Rich Felker0b44a032011-02-12 00:22:29 -0500166int kill(pid_t, int);
Rich Felker0b44a032011-02-12 00:22:29 -0500167
168int sigemptyset(sigset_t *);
169int sigfillset(sigset_t *);
170int sigaddset(sigset_t *, int);
171int sigdelset(sigset_t *, int);
172int sigismember(const sigset_t *, int);
173
Rich Felker400c5e52012-09-06 22:44:55 -0400174int sigprocmask(int, const sigset_t *__restrict, sigset_t *__restrict);
Rich Felker0b44a032011-02-12 00:22:29 -0500175int sigsuspend(const sigset_t *);
Rich Felker400c5e52012-09-06 22:44:55 -0400176int sigaction(int, const struct sigaction *__restrict, struct sigaction *__restrict);
Rich Felker0b44a032011-02-12 00:22:29 -0500177int sigpending(sigset_t *);
Rich Felker400c5e52012-09-06 22:44:55 -0400178int sigwait(const sigset_t *__restrict, int *__restrict);
179int sigwaitinfo(const sigset_t *__restrict, siginfo_t *__restrict);
180int sigtimedwait(const sigset_t *__restrict, siginfo_t *__restrict, const struct timespec *__restrict);
Rich Felker0b44a032011-02-12 00:22:29 -0500181int sigqueue(pid_t, int, const union sigval);
182
Rich Felker400c5e52012-09-06 22:44:55 -0400183int pthread_sigmask(int, const sigset_t *__restrict, sigset_t *__restrict);
Rich Felker0b44a032011-02-12 00:22:29 -0500184int pthread_kill(pthread_t, int);
185
Rich Felkeradb70932011-09-02 14:25:43 -0400186void psiginfo(const siginfo_t *, const char *);
187void psignal(int, const char *);
188
Rich Felker1322cb82011-02-14 20:33:54 -0500189#endif
190
191#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
192int killpg(pid_t, int);
Rich Felker400c5e52012-09-06 22:44:55 -0400193int sigaltstack(const stack_t *__restrict, stack_t *__restrict);
Rich Felker1322cb82011-02-14 20:33:54 -0500194int sighold(int);
195int sigignore(int);
196int siginterrupt(int, int);
197int sigpause(int);
198int sigrelse(int);
199void (*sigset(int, void (*)(int)))(int);
Rich Felkerf780ac52011-09-19 20:02:12 -0400200#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 Felker1322cb82011-02-14 20:33:54 -0500212#endif
213
Rich Felker419ae6d2012-05-22 21:52:08 -0400214#ifdef _BSD_SOURCE
215typedef void (*sig_t)(int);
216#endif
217
Rich Felker0b44a032011-02-12 00:22:29 -0500218#ifdef _GNU_SOURCE
Rich Felker0f5b4352011-04-13 08:45:28 -0400219typedef void (*sighandler_t)(int);
Rich Felker9f370fa2012-05-22 21:54:19 -0400220void (*bsd_signal(int, void (*)(int)))(int);
Rich Felkerfb80e042011-09-12 00:00:30 -0400221int sigisemptyset(const sigset_t *);
Rich Felker20291142011-05-05 17:44:06 -0400222#define SA_NOMASK SA_NODEFER
Rich Felkerf780ac52011-09-19 20:02:12 -0400223#define SA_ONESHOT SA_RESETHAND
Rich Felker0b44a032011-02-12 00:22:29 -0500224#endif
225
Rich Felker3eb9fea2011-02-15 15:10:00 -0500226#include <bits/signal.h>
227
Rich Felker81a55772011-09-21 22:25:31 -0400228#define SIG_ERR ((void (*)(int))-1)
229#define SIG_DFL ((void (*)(int)) 0)
230#define SIG_IGN ((void (*)(int)) 1)
231
Rich Felker1322cb82011-02-14 20:33:54 -0500232typedef int sig_atomic_t;
233
234void (*signal(int, void (*)(int)))(int);
235int raise(int);
236
Rich Felker0b44a032011-02-12 00:22:29 -0500237#ifdef __cplusplus
238}
239#endif
240
241#endif