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