blob: 2c3602dfe72a33d565da16e1a39a23bde15c6d28 [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 Felkerc1a96582012-09-07 23:13:55 -04008#include <features.h>
Rich Felker400c5e52012-09-06 22:44:55 -04009
Rich Felker1322cb82011-02-14 20:33:54 -050010#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
Rich Felker419ae6d2012-05-22 21:52:08 -040011 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
12 || defined(_BSD_SOURCE)
Rich Felker1322cb82011-02-14 20:33:54 -050013
Rich Felker03a83622011-09-20 10:58:18 -040014#ifdef _GNU_SOURCE
Rich Felkera8da6c22012-11-25 23:04:23 -050015#define __ucontext ucontext
Rich Felker03a83622011-09-20 10:58:18 -040016#endif
17
Rich Felker0b44a032011-02-12 00:22:29 -050018#define __NEED_size_t
19#define __NEED_pid_t
20#define __NEED_uid_t
21#define __NEED_struct_timespec
22#define __NEED_pthread_t
Rich Felker80c4dcd2011-03-29 13:01:25 -040023#define __NEED_pthread_attr_t
Rich Felker0b44a032011-02-12 00:22:29 -050024#define __NEED_time_t
25#define __NEED_clock_t
26#define __NEED_sigset_t
Rich Felker0b44a032011-02-12 00:22:29 -050027
28#include <bits/alltypes.h>
29
Rich Felker81a55772011-09-21 22:25:31 -040030#define SIG_HOLD ((void (*)(int)) 2)
31
Rich Felkerf780ac52011-09-19 20:02:12 -040032#define SIG_BLOCK 0
33#define SIG_UNBLOCK 1
34#define SIG_SETMASK 2
35
Rich Felkerf780ac52011-09-19 20:02:12 -040036#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
Rich Felker8eb9a3a2012-01-25 15:30:42 -050050#define FPE_FLTUND 5
Rich Felkerf780ac52011-09-19 20:02:12 -040051#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
Szabolcs Nagyb54f1692013-07-24 23:56:13 +000070#define BUS_MCEERR_AR 4
71#define BUS_MCEERR_AO 5
Rich Felkerf780ac52011-09-19 20:02:12 -040072
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
Rich Felker9448b052013-07-22 11:22:36 -040080typedef struct sigaltstack {
Rich Felker0b44a032011-02-12 00:22:29 -050081 void *ss_sp;
82 int ss_flags;
83 size_t ss_size;
84} stack_t;
85
Rich Felker80c4dcd2011-03-29 13:01:25 -040086union sigval {
Rich Felker0b44a032011-02-12 00:22:29 -050087 int sival_int;
88 void *sival_ptr;
89};
90
Rich Felker9448b052013-07-22 11:22:36 -040091typedef struct {
Rich Felkerf780ac52011-09-19 20:02:12 -040092 int si_signo, si_errno, si_code;
93 union {
Rich Felker8c741782013-03-04 17:05:45 -050094 char __pad[128 - 2*sizeof(int) - sizeof(long)];
Rich Felkerf780ac52011-09-19 20:02:12 -040095 struct {
96 pid_t si_pid;
97 uid_t si_uid;
98 union sigval si_sigval;
99 } __rt;
100 struct {
101 unsigned int si_timer1, si_timer2;
102 } __timer;
103 struct {
104 pid_t si_pid;
105 uid_t si_uid;
106 int si_status;
107 clock_t si_utime, si_stime;
108 } __sigchld;
109 struct {
110 void *si_addr;
Szabolcs Nagyb54f1692013-07-24 23:56:13 +0000111 short int si_addr_lsb;
Rich Felkerf780ac52011-09-19 20:02:12 -0400112 } __sigfault;
113 struct {
114 long si_band;
115 int si_fd;
116 } __sigpoll;
Szabolcs Nagyb54f1692013-07-24 23:56:13 +0000117 struct {
118 unsigned int si_call_addr;
119 int si_syscall;
120 unsigned int si_arch;
121 } __sigsys;
Rich Felkerf780ac52011-09-19 20:02:12 -0400122 } __si_fields;
Rich Felker9448b052013-07-22 11:22:36 -0400123} siginfo_t;
Rich Felkerf780ac52011-09-19 20:02:12 -0400124#define si_pid __si_fields.__sigchld.si_pid
125#define si_uid __si_fields.__sigchld.si_uid
126#define si_status __si_fields.__sigchld.si_status
127#define si_utime __si_fields.__sigchld.si_utime
128#define si_stime __si_fields.__sigchld.si_stime
129#define si_value __si_fields.__rt.si_sigval
130#define si_addr __si_fields.__sigfault.si_addr
Szabolcs Nagyb54f1692013-07-24 23:56:13 +0000131#define si_addr_lsb __si_fields.__sigfault.si_addr_lsb
Rich Felkerf780ac52011-09-19 20:02:12 -0400132#define si_band __si_fields.__sigpoll.si_band
133#define si_fd __si_fields.__sigpoll.si_fd
134#define si_timer1 __si_fields.__timer.si_timer1
135#define si_timer2 __si_fields.__timer.si_timer2
Rich Felker8c07f6e2011-09-19 22:27:02 -0400136#define si_ptr __si_fields.__rt.si_sigval.sival_ptr
137#define si_int __si_fields.__rt.si_sigval.sival_int
Szabolcs Nagyb54f1692013-07-24 23:56:13 +0000138#define si_call_addr __si_fields.__sigsys.si_call_addr
139#define si_syscall __si_fields.__sigsys.si_syscall
140#define si_arch __si_fields.__sigsys.si_arch
Rich Felkerf780ac52011-09-19 20:02:12 -0400141
Rich Felker9448b052013-07-22 11:22:36 -0400142struct sigaction {
143 union {
144 void (*sa_handler)(int);
145 void (*sa_sigaction)(int, siginfo_t *, void *);
146 } __sa_handler;
147 sigset_t sa_mask;
148 int sa_flags;
Szabolcs Nagyb54f1692013-07-24 23:56:13 +0000149 void (*sa_restorer)(void);
Rich Felker9448b052013-07-22 11:22:36 -0400150};
151#define sa_handler __sa_handler.sa_handler
152#define sa_sigaction __sa_handler.sa_sigaction
153
Rich Felker80c4dcd2011-03-29 13:01:25 -0400154struct sigevent {
155 union sigval sigev_value;
156 int sigev_signo;
157 int sigev_notify;
158 void (*sigev_notify_function)(union sigval);
159 pthread_attr_t *sigev_notify_attributes;
Rich Felker7f547152011-06-16 17:11:35 -0400160 char __pad[56-3*sizeof(long)];
Rich Felker80c4dcd2011-03-29 13:01:25 -0400161};
162
163#define SIGEV_SIGNAL 0
164#define SIGEV_NONE 1
165#define SIGEV_THREAD 2
166
Rich Felker0b44a032011-02-12 00:22:29 -0500167int __libc_current_sigrtmin(void);
168int __libc_current_sigrtmax(void);
169
170#define SIGRTMIN (__libc_current_sigrtmin())
171#define SIGRTMAX (__libc_current_sigrtmax())
172
Rich Felker0b44a032011-02-12 00:22:29 -0500173int kill(pid_t, int);
Rich Felker0b44a032011-02-12 00:22:29 -0500174
175int sigemptyset(sigset_t *);
176int sigfillset(sigset_t *);
177int sigaddset(sigset_t *, int);
178int sigdelset(sigset_t *, int);
179int sigismember(const sigset_t *, int);
180
Rich Felker400c5e52012-09-06 22:44:55 -0400181int sigprocmask(int, const sigset_t *__restrict, sigset_t *__restrict);
Rich Felker0b44a032011-02-12 00:22:29 -0500182int sigsuspend(const sigset_t *);
Rich Felker400c5e52012-09-06 22:44:55 -0400183int sigaction(int, const struct sigaction *__restrict, struct sigaction *__restrict);
Rich Felker0b44a032011-02-12 00:22:29 -0500184int sigpending(sigset_t *);
Rich Felker400c5e52012-09-06 22:44:55 -0400185int sigwait(const sigset_t *__restrict, int *__restrict);
186int sigwaitinfo(const sigset_t *__restrict, siginfo_t *__restrict);
187int sigtimedwait(const sigset_t *__restrict, siginfo_t *__restrict, const struct timespec *__restrict);
Rich Felker0b44a032011-02-12 00:22:29 -0500188int sigqueue(pid_t, int, const union sigval);
189
Rich Felker400c5e52012-09-06 22:44:55 -0400190int pthread_sigmask(int, const sigset_t *__restrict, sigset_t *__restrict);
Rich Felker0b44a032011-02-12 00:22:29 -0500191int pthread_kill(pthread_t, int);
192
Rich Felkeradb70932011-09-02 14:25:43 -0400193void psiginfo(const siginfo_t *, const char *);
194void psignal(int, const char *);
195
Rich Felker1322cb82011-02-14 20:33:54 -0500196#endif
197
198#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
199int killpg(pid_t, int);
Rich Felker400c5e52012-09-06 22:44:55 -0400200int sigaltstack(const stack_t *__restrict, stack_t *__restrict);
Rich Felker1322cb82011-02-14 20:33:54 -0500201int sighold(int);
202int sigignore(int);
203int siginterrupt(int, int);
204int sigpause(int);
205int sigrelse(int);
206void (*sigset(int, void (*)(int)))(int);
Rich Felkerf780ac52011-09-19 20:02:12 -0400207#define TRAP_BRKPT 1
208#define TRAP_TRACE 2
209#define POLL_IN 1
210#define POLL_OUT 2
211#define POLL_MSG 3
212#define POLL_ERR 4
213#define POLL_PRI 5
214#define POLL_HUP 6
215#define SS_ONSTACK 1
216#define SS_DISABLE 2
217#define MINSIGSTKSZ 2048
218#define SIGSTKSZ 8192
Rich Felker1322cb82011-02-14 20:33:54 -0500219#endif
220
Rich Felker7dcb6402012-11-30 21:00:18 -0500221#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
222#define NSIG _NSIG
223#endif
224
Rich Felker769fd4c2012-12-03 16:57:01 -0500225#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
Rich Felker419ae6d2012-05-22 21:52:08 -0400226typedef void (*sig_t)(int);
227#endif
228
Rich Felker0b44a032011-02-12 00:22:29 -0500229#ifdef _GNU_SOURCE
Rich Felker0f5b4352011-04-13 08:45:28 -0400230typedef void (*sighandler_t)(int);
Rich Felker9f370fa2012-05-22 21:54:19 -0400231void (*bsd_signal(int, void (*)(int)))(int);
Rich Felkerfb80e042011-09-12 00:00:30 -0400232int sigisemptyset(const sigset_t *);
rofl0ra1990e12012-12-06 20:51:32 +0100233int sigorset (sigset_t *, sigset_t *, sigset_t *);
234int sigandset(sigset_t *, sigset_t *, sigset_t *);
235
Rich Felker20291142011-05-05 17:44:06 -0400236#define SA_NOMASK SA_NODEFER
Rich Felkerf780ac52011-09-19 20:02:12 -0400237#define SA_ONESHOT SA_RESETHAND
Rich Felker0b44a032011-02-12 00:22:29 -0500238#endif
239
Rich Felker3eb9fea2011-02-15 15:10:00 -0500240#include <bits/signal.h>
241
Rich Felker81a55772011-09-21 22:25:31 -0400242#define SIG_ERR ((void (*)(int))-1)
243#define SIG_DFL ((void (*)(int)) 0)
244#define SIG_IGN ((void (*)(int)) 1)
245
Rich Felker1322cb82011-02-14 20:33:54 -0500246typedef int sig_atomic_t;
247
248void (*signal(int, void (*)(int)))(int);
249int raise(int);
250
Rich Felker0b44a032011-02-12 00:22:29 -0500251#ifdef __cplusplus
252}
253#endif
254
255#endif