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