]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/signal.h
xnu-792.6.56.tar.gz
[apple/xnu.git] / bsd / sys / signal.h
1 /*
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
24 /*
25 * Copyright (c) 1982, 1986, 1989, 1991, 1993
26 * The Regents of the University of California. All rights reserved.
27 * (c) UNIX System Laboratories, Inc.
28 * All or some portions of this file are derived from material licensed
29 * to the University of California by American Telephone and Telegraph
30 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
31 * the permission of UNIX System Laboratories, Inc.
32 *
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
35 * are met:
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. All advertising materials mentioning features or use of this software
42 * must display the following acknowledgement:
43 * This product includes software developed by the University of
44 * California, Berkeley and its contributors.
45 * 4. Neither the name of the University nor the names of its contributors
46 * may be used to endorse or promote products derived from this software
47 * without specific prior written permission.
48 *
49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * SUCH DAMAGE.
60 *
61 * @(#)signal.h 8.2 (Berkeley) 1/21/94
62 */
63
64 #ifndef _SYS_SIGNAL_H_
65 #define _SYS_SIGNAL_H_
66
67 #include <sys/cdefs.h>
68 #include <sys/appleapiopts.h>
69
70 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE)
71 #define NSIG 32 /* counting 0; could be 33 (mask is 1-32) */
72 #endif
73
74 #include <machine/signal.h> /* sigcontext; codes for SIGILL, SIGFPE */
75
76 #define SIGHUP 1 /* hangup */
77 #define SIGINT 2 /* interrupt */
78 #define SIGQUIT 3 /* quit */
79 #define SIGILL 4 /* illegal instruction (not reset when caught) */
80 #define SIGTRAP 5 /* trace trap (not reset when caught) */
81 #define SIGABRT 6 /* abort() */
82 #if defined(_POSIX_C_SOURCE)
83 #define SIGPOLL 7 /* pollable event ([XSR] generated, not supported) */
84 #else /* !_POSIX_C_SOURCE */
85 #define SIGIOT SIGABRT /* compatibility */
86 #define SIGEMT 7 /* EMT instruction */
87 #endif /* !_POSIX_C_SOURCE */
88 #define SIGFPE 8 /* floating point exception */
89 #define SIGKILL 9 /* kill (cannot be caught or ignored) */
90 #define SIGBUS 10 /* bus error */
91 #define SIGSEGV 11 /* segmentation violation */
92 #define SIGSYS 12 /* bad argument to system call */
93 #define SIGPIPE 13 /* write on a pipe with no one to read it */
94 #define SIGALRM 14 /* alarm clock */
95 #define SIGTERM 15 /* software termination signal from kill */
96 #define SIGURG 16 /* urgent condition on IO channel */
97 #define SIGSTOP 17 /* sendable stop signal not from tty */
98 #define SIGTSTP 18 /* stop signal from tty */
99 #define SIGCONT 19 /* continue a stopped process */
100 #define SIGCHLD 20 /* to parent on child stop or exit */
101 #define SIGTTIN 21 /* to readers pgrp upon background tty read */
102 #define SIGTTOU 22 /* like TTIN for output if (tp->t_local&LTOSTOP) */
103 #if !defined(_POSIX_C_SOURCE)
104 #define SIGIO 23 /* input/output possible signal */
105 #endif
106 #define SIGXCPU 24 /* exceeded CPU time limit */
107 #define SIGXFSZ 25 /* exceeded file size limit */
108 #define SIGVTALRM 26 /* virtual time alarm */
109 #define SIGPROF 27 /* profiling time alarm */
110 #if !defined(_POSIX_C_SOURCE)
111 #define SIGWINCH 28 /* window size changes */
112 #define SIGINFO 29 /* information request */
113 #endif
114 #define SIGUSR1 30 /* user defined signal 1 */
115 #define SIGUSR2 31 /* user defined signal 2 */
116
117 #if defined(_ANSI_SOURCE) || defined(_POSIX_C_SOURCE) || defined(__cplusplus)
118 /*
119 * Language spec sez we must list exactly one parameter, even though we
120 * actually supply three. Ugh!
121 * SIG_HOLD is chosen to avoid KERN_SIG_* values in <sys/signalvar.h>
122 */
123 #define SIG_DFL (void (*)(int))0
124 #define SIG_IGN (void (*)(int))1
125 #define SIG_HOLD (void (*)(int))5
126 #define SIG_ERR ((void (*)(int))-1)
127 #else
128 /* DO NOT REMOVE THE COMMENTED OUT int: fixincludes needs to see them */
129 #define SIG_DFL (void (*)(/*int*/))0
130 #define SIG_IGN (void (*)(/*int*/))1
131 #define SIG_HOLD (void (*)(/*int*/))5
132 #define SIG_ERR ((void (*)(/*int*/))-1)
133 #endif
134
135 #ifndef _ANSI_SOURCE
136 #include <sys/_types.h>
137
138 #ifndef _MCONTEXT_T
139 #define _MCONTEXT_T
140 typedef __darwin_mcontext_t mcontext_t;
141 #endif
142
143 #ifndef _POSIX_C_SOURCE
144 #ifndef _MCONTEXT64_T
145 #define _MCONTEXT64_T
146 typedef __darwin_mcontext64_t mcontext64_t;
147 #endif
148 #endif /* _POSIX_C_SOURCE */
149
150 #ifndef _PID_T
151 #define _PID_T
152 typedef __darwin_pid_t pid_t;
153 #endif
154
155 #ifndef _PTHREAD_ATTR_T
156 #define _PTHREAD_ATTR_T
157 typedef __darwin_pthread_attr_t pthread_attr_t;
158 #endif
159
160 #ifndef _SIGSET_T
161 #define _SIGSET_T
162 typedef __darwin_sigset_t sigset_t;
163 #endif
164
165 #ifndef _SIZE_T
166 #define _SIZE_T
167 typedef __darwin_size_t size_t;
168 #endif
169
170 #ifndef _UCONTEXT_T
171 #define _UCONTEXT_T
172 typedef __darwin_ucontext_t ucontext_t;
173 #endif
174
175 #ifndef _POSIX_C_SOURCE
176 #ifndef _UCONTEXT64_T
177 #define _UCONTEXT64_T
178 typedef __darwin_ucontext64_t ucontext64_t;
179 #endif
180 #endif /* _POSIX_C_SOURCE */
181
182 #ifndef _UID_T
183 #define _UID_T
184 typedef __darwin_uid_t uid_t;
185 #endif
186
187 union sigval {
188 /* Members as suggested by Annex C of POSIX 1003.1b. */
189 int sival_int;
190 void *sival_ptr;
191 };
192
193 #define SIGEV_NONE 0 /* No async notification */
194 #define SIGEV_SIGNAL 1 /* aio - completion notification */
195 #define SIGEV_THREAD 3 /* A notification function will be called to perform notification */
196
197 struct sigevent {
198 int sigev_notify; /* Notification type */
199 int sigev_signo; /* Signal number */
200 union sigval sigev_value; /* Signal value */
201 void (*sigev_notify_function)(union sigval); /* Notification function */
202 pthread_attr_t *sigev_notify_attributes; /* Notification attributes */
203 };
204
205 // LP64todo - should this move?
206 #ifdef BSD_KERNEL_PRIVATE
207
208 #if __DARWIN_ALIGN_NATURAL
209 #pragma options align=natural
210 #endif
211
212 union user_sigval {
213 struct {
214 int pad; /* assumes Motorolla byte order */
215 int sival_int;
216 } size_equivalent;
217 user_addr_t sival_ptr;
218 };
219
220 struct user_sigevent {
221 int sigev_notify; /* Notification type */
222 int sigev_signo; /* Signal number */
223 union user_sigval sigev_value; /* Signal value */
224 user_addr_t sigev_notify_function; /* Notify function */
225 user_addr_t sigev_notify_attributes; /* Notify attributes */
226 };
227
228 #if __DARWIN_ALIGN_NATURAL
229 #pragma options align=reset
230 #endif
231
232 #endif /* BSD_KERNEL_PRIVATE */
233
234 typedef struct __siginfo {
235 int si_signo; /* signal number */
236 int si_errno; /* errno association */
237 int si_code; /* signal code */
238 pid_t si_pid; /* sending process */
239 uid_t si_uid; /* sender's ruid */
240 int si_status; /* exit value */
241 void *si_addr; /* faulting instruction */
242 union sigval si_value; /* signal value */
243 long si_band; /* band event for SIGPOLL */
244 unsigned long pad[7]; /* Reserved for Future Use */
245 } siginfo_t;
246
247 #ifdef BSD_KERNEL_PRIVATE
248
249 #if __DARWIN_ALIGN_NATURAL
250 #pragma options align=natural
251 #endif
252
253 typedef struct __user_siginfo {
254 int si_signo; /* signal number */
255 int si_errno; /* errno association */
256 int si_code; /* signal code */
257 pid_t si_pid; /* sending process */
258 uid_t si_uid; /* sender's ruid */
259 int si_status; /* exit value */
260 user_addr_t si_addr; /* faulting instruction */
261 union user_sigval si_value; /* signal value */
262 user_long_t si_band; /* band event for SIGPOLL */
263 user_ulong_t pad[7]; /* Reserved for Future Use */
264 } user_siginfo_t;
265
266 #if __DARWIN_ALIGN_NATURAL
267 #pragma options align=reset
268 #endif
269
270 #endif /* BSD_KERNEL_PRIVATE */
271
272 /*
273 * Incase of SIGILL and SIGFPE, si_addr contains the address of
274 * faulting instruction.
275 * Incase of SIGSEGV and SIGBUS, si_addr contains address of
276 * faulting memory reference.
277 * Incase of SIGCHLD, si_pid willhave child process ID,
278 * si_status will contain exit value or signal.
279 * si_uid contains real user ID of the process that sent the signal
280 */
281
282 /* Values for si_code */
283
284 /* Codes for SIGILL */
285 #ifndef _POSIX_C_SOURCE
286 #define ILL_NOOP 0 /* if only I knew... */
287 #endif
288 #define ILL_ILLOPC 1 /* [XSI] illegal opcode */
289 #define ILL_ILLTRP 2 /* [XSI] illegal trap */
290 #define ILL_PRVOPC 3 /* [XSI] privileged opcode */
291 #define ILL_ILLOPN 4 /* [XSI] illegal operand -NOTIMP */
292 #define ILL_ILLADR 5 /* [XSI] illegal addressing mode -NOTIMP */
293 #define ILL_PRVREG 6 /* [XSI] privileged register -NOTIMP */
294 #define ILL_COPROC 7 /* [XSI] coprocessor error -NOTIMP */
295 #define ILL_BADSTK 8 /* [XSI] internal stack error -NOTIMP */
296
297 /* Codes for SIGFPE */
298 #ifndef _POSIX_C_SOURCE
299 #define FPE_NOOP 0 /* if only I knew... */
300 #endif
301 #define FPE_FLTDIV 1 /* [XSI] floating point divide by zero */
302 #define FPE_FLTOVF 2 /* [XSI] floating point overflow */
303 #define FPE_FLTUND 3 /* [XSI] floating point underflow */
304 #define FPE_FLTRES 4 /* [XSI] floating point inexact result */
305 #define FPE_FLTINV 5 /* [XSI] invalid floating point operation */
306 #define FPE_FLTSUB 6 /* [XSI] subscript out of range -NOTIMP */
307 #define FPE_INTDIV 7 /* [XSI] integer divide by zero -NOTIMP */
308 #define FPE_INTOVF 8 /* [XSI] integer overflow -NOTIMP */
309
310 /* Codes for SIGSEGV */
311 #ifndef _POSIX_C_SOURCE
312 #define SEGV_NOOP 0 /* if only I knew... */
313 #endif
314 #define SEGV_MAPERR 1 /* [XSI] address not mapped to object */
315 #define SEGV_ACCERR 2 /* [XSI] invalid permission for mapped object */
316
317 /* Codes for SIGBUS */
318 #ifndef _POSIX_C_SOURCE
319 #define BUS_NOOP 0 /* if only I knew... */
320 #endif
321 #define BUS_ADRALN 1 /* [XSI] Invalid address alignment */
322 #define BUS_ADRERR 2 /* [XSI] Nonexistent physical address -NOTIMP */
323 #define BUS_OBJERR 3 /* [XSI] Object-specific HW error - NOTIMP */
324
325 /* Codes for SIGTRAP */
326 #define TRAP_BRKPT 1 /* [XSI] Process breakpoint -NOTIMP */
327 #define TRAP_TRACE 2 /* [XSI] Process trace trap -NOTIMP */
328
329 /* Codes for SIGCHLD */
330 #ifndef _POSIX_C_SOURCE
331 #define CLD_NOOP 0 /* if only I knew... */
332 #endif
333 #define CLD_EXITED 1 /* [XSI] child has exited */
334 #define CLD_KILLED 2 /* [XSI] terminated abnormally, no core file */
335 #define CLD_DUMPED 3 /* [XSI] terminated abnormally, core file */
336 #define CLD_TRAPPED 4 /* [XSI] traced child has trapped */
337 #define CLD_STOPPED 5 /* [XSI] child has stopped */
338 #define CLD_CONTINUED 6 /* [XSI] stopped child has continued */
339
340 /* Codes for SIGPOLL */
341 #define POLL_IN 1 /* [XSR] Data input available */
342 #define POLL_OUT 2 /* [XSR] Output buffers available */
343 #define POLL_MSG 3 /* [XSR] Input message available */
344 #define POLL_ERR 4 /* [XSR] I/O error */
345 #define POLL_PRI 5 /* [XSR] High priority input available */
346 #define POLL_HUP 6 /* [XSR] Device disconnected */
347
348 /* union for signal handlers */
349 union __sigaction_u {
350 void (*__sa_handler)(int);
351 void (*__sa_sigaction)(int, struct __siginfo *,
352 void *);
353 };
354
355 /* Signal vector template for Kernel user boundary */
356 struct __sigaction {
357 union __sigaction_u __sigaction_u; /* signal handler */
358 void (*sa_tramp)(void *, int, int, siginfo_t *, void *);
359 sigset_t sa_mask; /* signal mask to apply */
360 int sa_flags; /* see signal options below */
361 };
362
363 /*
364 * Signal vector "template" used in sigaction call.
365 */
366 struct sigaction {
367 union __sigaction_u __sigaction_u; /* signal handler */
368 sigset_t sa_mask; /* signal mask to apply */
369 int sa_flags; /* see signal options below */
370 };
371
372 #ifdef BSD_KERNEL_PRIVATE
373 #include <machine/types.h>
374
375 #if __DARWIN_ALIGN_NATURAL
376 #pragma options align=natural
377 #endif
378
379 union __user_sigaction_u {
380 user_addr_t __sa_handler;
381 user_addr_t __sa_sigaction;
382 };
383
384 struct user_sigaction {
385 union __user_sigaction_u __sigaction_u; /* signal handler */
386 sigset_t sa_mask; /* signal mask to apply */
387 int sa_flags; /* see signal options below */
388 };
389
390 struct __user_sigaction {
391 union __user_sigaction_u __sigaction_u; /* signal handler */
392 user_addr_t sa_tramp; /* signal mask to apply */
393 sigset_t sa_mask; /* signal mask to apply */
394 int sa_flags; /* see signal options below */
395 };
396
397 #if __DARWIN_ALIGN_NATURAL
398 #pragma options align=reset
399 #endif
400
401 #undef SIG_DFL
402 #undef SIG_IGN
403 #undef SIG_ERR
404 #define SIG_DFL ((user_addr_t)0LL)
405 #define SIG_IGN ((user_addr_t)1LL)
406 #define SIG_ERR ((user_addr_t)-1LL)
407
408 #endif /* BSD_KERNEL_PRIVATE */
409
410
411 /* if SA_SIGINFO is set, sa_sigaction is to be used instead of sa_handler. */
412 #define sa_handler __sigaction_u.__sa_handler
413 #define sa_sigaction __sigaction_u.__sa_sigaction
414
415 #define SA_ONSTACK 0x0001 /* take signal on signal stack */
416 #define SA_RESTART 0x0002 /* restart system on signal return */
417 #define SA_DISABLE 0x0004 /* disable taking signals on alternate stack */
418 #define SA_RESETHAND 0x0004 /* reset to SIG_DFL when taking signal */
419 #define SA_NOCLDSTOP 0x0008 /* do not generate SIGCHLD on child stop */
420 #define SA_NODEFER 0x0010 /* don't mask the signal we're delivering */
421 #define SA_NOCLDWAIT 0x0020 /* don't keep zombies around */
422 #define SA_SIGINFO 0x0040 /* signal handler with SA_SIGINFO args */
423 #ifndef _POSIX_C_SOURCE
424 #define SA_USERTRAMP 0x0100 /* do not bounce off kernel's sigtramp */
425 /* This will provide 64bit register set in a 32bit user address space */
426 #define SA_64REGSET 0x0200 /* signal handler with SA_SIGINFO args with 64bit regs information */
427 #endif /* !_POSIX_C_SOURCE */
428
429 /*
430 * Flags for sigprocmask:
431 */
432 #define SIG_BLOCK 1 /* block specified signal set */
433 #define SIG_UNBLOCK 2 /* unblock specified signal set */
434 #define SIG_SETMASK 3 /* set specified signal set */
435
436 /* POSIX 1003.1b required values. */
437 #define SI_USER 0x10001 /* [CX] signal from kill() */
438 #define SI_QUEUE 0x10002 /* [CX] signal from sigqueue() */
439 #define SI_TIMER 0x10003 /* [CX] timer expiration */
440 #define SI_ASYNCIO 0x10004 /* [CX] aio request completion */
441 #define SI_MESGQ 0x10005 /* [CX] from message arrival on empty queue */
442
443 #ifndef _POSIX_C_SOURCE
444 typedef void (*sig_t)(int); /* type of signal function */
445 #endif
446
447 /*
448 * Structure used in sigaltstack call.
449 */
450 #ifdef BSD_KERNEL_PRIVATE
451
452 #if __DARWIN_ALIGN_NATURAL
453 #pragma options align=natural
454 #endif
455
456 struct user_sigaltstack {
457 user_addr_t ss_sp; /* signal stack base */
458 user_size_t ss_size; /* signal stack length */
459 int ss_flags; /* SA_DISABLE and/or SA_ONSTACK */
460 };
461
462 #if __DARWIN_ALIGN_NATURAL
463 #pragma options align=reset
464 #endif
465
466 #endif /* BSD_KERNEL_PRIVATE */
467
468 #ifndef _STACK_T
469 #define _STACK_T
470 typedef __darwin_stack_t stack_t;
471 #endif
472
473 #define SS_ONSTACK 0x0001 /* take signal on signal stack */
474 #define SS_DISABLE 0x0004 /* disable taking signals on alternate stack */
475 #define MINSIGSTKSZ 32768 /* (32K)minimum allowable stack */
476 #define SIGSTKSZ 131072 /* (128K)recommended stack size */
477
478 #ifndef _POSIX_C_SOURCE
479 /*
480 * 4.3 compatibility:
481 * Signal vector "template" used in sigvec call.
482 */
483 struct sigvec {
484 void (*sv_handler)(int); /* signal handler */
485 int sv_mask; /* signal mask to apply */
486 int sv_flags; /* see signal options below */
487 };
488
489 #define SV_ONSTACK SA_ONSTACK
490 #define SV_INTERRUPT SA_RESTART /* same bit, opposite sense */
491 #define SV_RESETHAND SA_RESETHAND
492 #define SV_NODEFER SA_NODEFER
493 #define SV_NOCLDSTOP SA_NOCLDSTOP
494 #define SV_SIGINFO SA_SIGINFO
495
496 #define sv_onstack sv_flags /* isn't compatibility wonderful! */
497 #endif /* !_POSIX_C_SOURCE */
498
499 /*
500 * Structure used in sigstack call.
501 */
502 struct sigstack {
503 char *ss_sp; /* signal stack pointer */
504 int ss_onstack; /* current status */
505 };
506
507 #ifndef _POSIX_C_SOURCE
508 /*
509 * Macro for converting signal number to a mask suitable for
510 * sigblock().
511 */
512 #define sigmask(m) (1 << ((m)-1))
513
514 #ifdef BSD_KERNEL_PRIVATE
515 /*
516 * signals delivered on a per-thread basis.
517 */
518 #define threadmask (sigmask(SIGILL)|sigmask(SIGTRAP)|\
519 sigmask(SIGIOT)|sigmask(SIGEMT)|\
520 sigmask(SIGFPE)|sigmask(SIGBUS)|\
521 sigmask(SIGSEGV)|sigmask(SIGSYS)|\
522 sigmask(SIGPIPE))
523 #endif /* BSD_KERNEL_PRIVATE */
524
525 #define BADSIG SIG_ERR
526
527 #endif /* !_POSIX_C_SOURCE */
528 #endif /* !_ANSI_SOURCE */
529
530 /*
531 * For historical reasons; programs expect signal's return value to be
532 * defined by <sys/signal.h>.
533 */
534 __BEGIN_DECLS
535 void (*signal(int, void (*)(int)))(int);
536 __END_DECLS
537 #endif /* !_SYS_SIGNAL_H_ */