1 /*
2 Copyright (c) 1982, 1986, 1993
3 The Regents of the University of California.  All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8 1. Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 3. Neither the name of the University nor the names of its contributors
14 may be used to endorse or promote products derived from this software
15 without specific prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 SUCH DAMAGE.
28  */
29 /* sys/signal.h */
30 
31 #ifndef _SYS_SIGNAL_H
32 #define _SYS_SIGNAL_H
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #include "_ansi.h"
38 #include <sys/cdefs.h>
39 #include <sys/features.h>
40 #include <sys/types.h>
41 #include <sys/_sigset.h>
42 #include <sys/_timespec.h>
43 #include <stdint.h>
44 
45 #if !defined(_SIGSET_T_DECLARED)
46 #define	_SIGSET_T_DECLARED
47 typedef	__sigset_t	sigset_t;
48 #endif
49 
50 #if defined(__CYGWIN__)
51 #include <cygwin/signal.h>
52 #else
53 
54 #if defined(_POSIX_REALTIME_SIGNALS) || __POSIX_VISIBLE >= 199309
55 
56 /* sigev_notify values
57    NOTE: P1003.1c/D10, p. 34 adds SIGEV_THREAD.  */
58 
59 #define SIGEV_NONE   1  /* No asynchronous notification shall be delivered */
60                         /*   when the event of interest occurs. */
61 #define SIGEV_SIGNAL 2  /* A queued signal, with an application defined */
62                         /*  value, shall be delivered when the event of */
63                         /*  interest occurs. */
64 #define SIGEV_THREAD 3  /* A notification function shall be called to */
65                         /*   perform notification. */
66 
67 /*  Signal Generation and Delivery, P1003.1b-1993, p. 63
68     NOTE: P1003.1c/D10, p. 34 adds sigev_notify_function and
69           sigev_notify_attributes to the sigevent structure.  */
70 
71 union sigval {
72   int    sival_int;    /* Integer signal value */
73   void  *sival_ptr;    /* Pointer signal value */
74 };
75 
76 struct sigevent {
77   int              sigev_notify;               /* Notification type */
78   int              sigev_signo;                /* Signal number */
79   union sigval     sigev_value;                /* Signal value */
80 
81 };
82 
83 /* Signal Actions, P1003.1b-1993, p. 64 */
84 /* si_code values, p. 66 */
85 
86 #define SI_USER    1    /* Sent by a user. kill(), abort(), etc */
87 #define SI_QUEUE   2    /* Sent by sigqueue() */
88 #define SI_TIMER   3    /* Sent by expiration of a timer_settime() timer */
89 #define SI_ASYNCIO 4    /* Indicates completion of asycnhronous IO */
90 #define SI_MESGQ   5    /* Indicates arrival of a message at an empty queue */
91 
92 typedef struct {
93   int          si_signo;    /* Signal number */
94   int          si_code;     /* Cause of the signal */
95   union sigval si_value;    /* Signal value */
96 } siginfo_t;
97 #endif /* defined(_POSIX_REALTIME_SIGNALS) || __POSIX_VISIBLE >= 199309 */
98 
99 #if defined(__rtems__)
100 
101 /*  3.3.8 Synchronously Accept a Signal, P1003.1b-1993, p. 76 */
102 
103 #define SA_NOCLDSTOP 0x1   /* Do not generate SIGCHLD when children stop */
104 #define SA_SIGINFO   0x2   /* Invoke the signal catching function with */
105                            /*   three arguments instead of one. */
106 #if __BSD_VISIBLE || __XSI_VISIBLE >= 4 || __POSIX_VISIBLE >= 200809
107 #define SA_ONSTACK   0x4   /* Signal delivery will be on a separate stack. */
108 #endif
109 
110 /* struct sigaction notes from POSIX:
111  *
112  *  (1) Routines stored in sa_handler should take a single int as
113  *      their argument although the POSIX standard does not require this.
114  *      This is not longer true since at least POSIX.1-2008
115  *  (2) The fields sa_handler and sa_sigaction may overlap, and a conforming
116  *      application should not use both simultaneously.
117  */
118 
119 typedef void (*_sig_func_ptr)(int);
120 
121 struct sigaction {
122   int         sa_flags;       /* Special flags to affect behavior of signal */
123   sigset_t    sa_mask;        /* Additional set of signals to be blocked */
124                               /*   during execution of signal-catching */
125                               /*   function. */
126   union {
127     _sig_func_ptr _handler;  /* SIG_DFL, SIG_IGN, or pointer to a function */
128 #if defined(_POSIX_REALTIME_SIGNALS)
129     void      (*_sigaction)( int, siginfo_t *, void * );
130 #endif
131   } _signal_handlers;
132 };
133 
134 #define sa_handler    _signal_handlers._handler
135 #if defined(_POSIX_REALTIME_SIGNALS)
136 #define sa_sigaction  _signal_handlers._sigaction
137 #endif
138 
139 #else /* defined(__rtems__) */
140 
141 #define SA_NOCLDSTOP 1  /* only value supported now for sa_flags */
142 
143 typedef void (*_sig_func_ptr)(int);
144 
145 struct sigaction
146 {
147 	_sig_func_ptr sa_handler;
148 	sigset_t sa_mask;
149 	int sa_flags;
150 };
151 #endif /* defined(__rtems__) */
152 #endif /* defined(__CYGWIN__) */
153 
154 #if __BSD_VISIBLE || __XSI_VISIBLE >= 4 || __POSIX_VISIBLE >= 200809
155 /*
156  * Minimum and default signal stack constants. Allow for target overrides
157  * from <sys/features.h>.
158  */
159 #ifndef	MINSIGSTKSZ
160 #define	MINSIGSTKSZ	2048
161 #endif
162 #ifndef	SIGSTKSZ
163 #define	SIGSTKSZ	8192
164 #endif
165 
166 /*
167  * Possible values for ss_flags in stack_t below.
168  */
169 #define	SS_ONSTACK	0x1
170 #define	SS_DISABLE	0x2
171 
172 #endif
173 
174 /*
175  * Structure used in sigaltstack call.
176  */
177 typedef struct sigaltstack {
178   void     *ss_sp;    /* Stack base or pointer.  */
179   int       ss_flags; /* Flags.  */
180   size_t    ss_size;  /* Stack size.  */
181 } stack_t;
182 
183 #if __POSIX_VISIBLE
184 #define SIG_SETMASK 0	/* set mask with sigprocmask() */
185 #define SIG_BLOCK 1	/* set of signals to block */
186 #define SIG_UNBLOCK 2	/* set of signals to, well, unblock */
187 
188 int sigprocmask (int, const sigset_t *, sigset_t *);
189 #endif
190 
191 #if __POSIX_VISIBLE >= 199506
192 int pthread_sigmask (int, const sigset_t *, sigset_t *);
193 #endif
194 
195 #if __POSIX_VISIBLE
196 int kill (pid_t, int);
197 #endif
198 
199 #if __BSD_VISIBLE || __XSI_VISIBLE >= 4
200 int killpg (pid_t, int);
201 #endif
202 #if __POSIX_VISIBLE
203 int sigaction (int, const struct sigaction *, struct sigaction *);
204 int sigaddset (sigset_t *, const int);
205 int sigdelset (sigset_t *, const int);
206 int sigismember (const sigset_t *, int);
207 int sigfillset (sigset_t *);
208 int sigemptyset (sigset_t *);
209 int sigpending (sigset_t *);
210 int sigsuspend (const sigset_t *);
211 int sigwait (const sigset_t *, int *);
212 
213 #if !defined(__CYGWIN__) && !defined(__rtems__)
214 /* These depend upon the type of sigset_t, which right now
215    is always a long.. They're in the POSIX namespace, but
216    are not ANSI. */
217 #define sigaddset(what,sig) (*(what) |= (1<<(sig)), 0)
218 #define sigdelset(what,sig) (*(what) &= ~(1<<(sig)), 0)
219 #define sigemptyset(what)   (*(what) = 0, 0)
220 #define sigfillset(what)    (*(what) = ~(0), 0)
221 #define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0)
222 #endif /* !__CYGWIN__ && !__rtems__ */
223 #endif /* __POSIX_VISIBLE */
224 
225 /* There are two common sigpause variants, both of which take an int argument.
226    If you request _XOPEN_SOURCE or _GNU_SOURCE, you get the System V version,
227    which removes the given signal from the process's signal mask; otherwise
228    you get the BSD version, which sets the process's signal mask to the given
229    value. */
230 #if __XSI_VISIBLE && !defined(__INSIDE_CYGWIN__)
231 # ifdef __GNUC__
232 int sigpause (int) __asm__ (__ASMNAME ("__xpg_sigpause"));
233 # else
234 int __xpg_sigpause (int);
235 #  define sigpause __xpg_sigpause
236 # endif
237 #elif __BSD_VISIBLE
238 int sigpause (int);
239 #endif
240 
241 #if __BSD_VISIBLE || __XSI_VISIBLE >= 4 || __POSIX_VISIBLE >= 200809
242 int sigaltstack (const stack_t *__restrict, stack_t *__restrict);
243 #endif
244 
245 #if __POSIX_VISIBLE >= 199309
246 
247 /*  3.3.8 Synchronously Accept a Signal, P1003.1b-1993, p. 76
248     NOTE: P1003.1c/D10, p. 39 adds sigwait().  */
249 
250 int sigwaitinfo (const sigset_t *, siginfo_t *);
251 int sigtimedwait (const sigset_t *, siginfo_t *, const struct timespec *);
252 /*  3.3.9 Queue a Signal to a Process, P1003.1b-1993, p. 78 */
253 int sigqueue (pid_t, int, const union sigval);
254 
255 #endif /* __POSIX_VISIBLE >= 199309 */
256 
257 /* Using __MISC_VISIBLE until POSIX Issue 8 is officially released */
258 #if __MISC_VISIBLE
259 
260 /* POSIX Issue 8 adds sig2str() and str2sig() */
261 
262 #if __SIZEOF_INT__ >= 4
263 #define SIG2STR_MAX 17	/* (sizeof("RTMAX+") + sizeof("4294967295") - 1) */
264 #else
265 #define SIG2STR_MAX 12	/* (sizeof("RTMAX+") + sizeof("65535") - 1) */
266 #endif
267 
268 int sig2str(int, char *);
269 int str2sig(const char *__restrict, int *__restrict);
270 
271 #endif /* __MISC_VISIBLE */
272 
273 #if defined(___AM29K__)
274 /* These all need to be defined for ANSI C, but I don't think they are
275    meaningful.  */
276 #define SIGABRT 1
277 #define SIGFPE 1
278 #define SIGILL 1
279 #define SIGINT 1
280 #define SIGSEGV 1
281 #define SIGTERM 1
282 /* These need to be defined for POSIX, and some others do too.  */
283 #define SIGHUP 1
284 #define SIGQUIT 1
285 #define NSIG 2
286 #elif defined(__GO32__)
287 #define SIGINT  1
288 #define SIGKILL 2
289 #define SIGPIPE 3
290 #define SIGFPE  4
291 #define SIGHUP  5
292 #define SIGTERM 6
293 #define SIGSEGV 7
294 #define SIGTSTP 8
295 #define SIGQUIT 9
296 #define SIGTRAP 10
297 #define SIGILL  11
298 #define SIGEMT  12
299 #define SIGALRM 13
300 #define SIGBUS  14
301 #define SIGLOST 15
302 #define SIGSTOP 16
303 #define SIGABRT 17
304 #define SIGUSR1	18
305 #define SIGUSR2	19
306 #define NSIG    20
307 #elif !defined(SIGTRAP)
308 #define	SIGHUP	1	/* hangup */
309 #define	SIGINT	2	/* interrupt */
310 #define	SIGQUIT	3	/* quit */
311 #define	SIGILL	4	/* illegal instruction (not reset when caught) */
312 #define	SIGTRAP	5	/* trace trap (not reset when caught) */
313 #define	SIGIOT	6	/* IOT instruction */
314 #define	SIGABRT 6	/* used by abort, replace SIGIOT in the future */
315 #define	SIGEMT	7	/* EMT instruction */
316 #define	SIGFPE	8	/* floating point exception */
317 #define	SIGKILL	9	/* kill (cannot be caught or ignored) */
318 #define	SIGBUS	10	/* bus error */
319 #define	SIGSEGV	11	/* segmentation violation */
320 #define	SIGSYS	12	/* bad argument to system call */
321 #define	SIGPIPE	13	/* write on a pipe with no one to read it */
322 #define	SIGALRM	14	/* alarm clock */
323 #define	SIGTERM	15	/* software termination signal from kill */
324 
325 #if defined(__rtems__)
326 #define	SIGURG	16	/* urgent condition on IO channel */
327 #define	SIGSTOP	17	/* sendable stop signal not from tty */
328 #define	SIGTSTP	18	/* stop signal from tty */
329 #define	SIGCONT	19	/* continue a stopped process */
330 #define	SIGCHLD	20	/* to parent on child stop or exit */
331 #define	SIGCLD	20	/* System V name for SIGCHLD */
332 #define	SIGTTIN	21	/* to readers pgrp upon background tty read */
333 #define	SIGTTOU	22	/* like TTIN for output if (tp->t_local&LTOSTOP) */
334 #define	SIGIO	23	/* input/output possible signal */
335 #define	SIGPOLL	SIGIO	/* System V name for SIGIO */
336 #define	SIGWINCH 24	/* window changed */
337 #define	SIGUSR1 25	/* user defined signal 1 */
338 #define	SIGUSR2 26	/* user defined signal 2 */
339 
340 /* Real-Time Signals Range, P1003.1b-1993, p. 61
341    NOTE: By P1003.1b-1993, this should be at least RTSIG_MAX
342          (which is a minimum of 8) signals.
343  */
344 #define SIGRTMIN 27
345 #define SIGRTMAX 31
346 #define __SIGFIRSTNOTRT SIGHUP
347 #define __SIGLASTNOTRT  SIGUSR2
348 
349 #define NSIG	32      /* signal 0 implied */
350 
351 #elif defined(__svr4__)
352 /* svr4 specifics. different signals above 15, and sigaction. */
353 #define	SIGUSR1	16
354 #define SIGUSR2	17
355 #define SIGCLD	18
356 #define	SIGPWR	19
357 #define SIGWINCH 20
358 #define	SIGPOLL	22	/* 20 for x.out binaries!!!! */
359 #define	SIGSTOP	23	/* sendable stop signal not from tty */
360 #define	SIGTSTP	24	/* stop signal from tty */
361 #define	SIGCONT	25	/* continue a stopped process */
362 #define	SIGTTIN	26	/* to readers pgrp upon background tty read */
363 #define	SIGTTOU	27	/* like TTIN for output if (tp->t_local&LTOSTOP) */
364 #define NSIG	28
365 #else
366 #define	SIGURG	16	/* urgent condition on IO channel */
367 #define	SIGSTOP	17	/* sendable stop signal not from tty */
368 #define	SIGTSTP	18	/* stop signal from tty */
369 #define	SIGCONT	19	/* continue a stopped process */
370 #define	SIGCHLD	20	/* to parent on child stop or exit */
371 #define	SIGCLD	20	/* System V name for SIGCHLD */
372 #define	SIGTTIN	21	/* to readers pgrp upon background tty read */
373 #define	SIGTTOU	22	/* like TTIN for output if (tp->t_local&LTOSTOP) */
374 #define	SIGIO	23	/* input/output possible signal */
375 #define	SIGPOLL	SIGIO	/* System V name for SIGIO */
376 #define	SIGXCPU	24	/* exceeded CPU time limit */
377 #define	SIGXFSZ	25	/* exceeded file size limit */
378 #define	SIGVTALRM 26	/* virtual time alarm */
379 #define	SIGPROF	27	/* profiling time alarm */
380 #define	SIGWINCH 28	/* window changed */
381 #define	SIGLOST 29	/* resource lost (eg, record-lock lost) */
382 #define	SIGUSR1 30	/* user defined signal 1 */
383 #define	SIGUSR2 31	/* user defined signal 2 */
384 #define NSIG	32      /* signal 0 implied */
385 #endif
386 #endif
387 
388 #ifdef __cplusplus
389 }
390 #endif
391 
392 #if defined(__CYGWIN__)
393 #if __XSI_VISIBLE >= 4 || __POSIX_VISIBLE >= 200809
394 #include <sys/ucontext.h>
395 #endif
396 #endif
397 
398 #ifndef _SIGNAL_H_
399 /* Some applications take advantage of the fact that <sys/signal.h>
400  * and <signal.h> are equivalent in glibc.  Allow for that here.  */
401 #include <signal.h>
402 #endif
403 #endif /* _SYS_SIGNAL_H */
404