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
209 int pad
; /* assumes Motorolla byte order */
212 user_addr_t sival_ptr
;
215 struct user_sigevent
{
216 int sigev_notify
; /* Notification type */
217 int sigev_signo
; /* Signal number */
218 union user_sigval sigev_value
; /* Signal value */
219 user_addr_t sigev_notify_function
; /* Notify function */
220 user_addr_t sigev_notify_attributes
; /* Notify attributes */
223 #endif /* BSD_KERNEL_PRIVATE */
225 typedef struct __siginfo
{
226 int si_signo
; /* signal number */
227 int si_errno
; /* errno association */
228 int si_code
; /* signal code */
229 pid_t si_pid
; /* sending process */
230 uid_t si_uid
; /* sender's ruid */
231 int si_status
; /* exit value */
232 void *si_addr
; /* faulting instruction */
233 union sigval si_value
; /* signal value */
234 long si_band
; /* band event for SIGPOLL */
235 unsigned long pad
[7]; /* Reserved for Future Use */
238 #ifdef BSD_KERNEL_PRIVATE
240 typedef struct __user_siginfo
{
241 int si_signo
; /* signal number */
242 int si_errno
; /* errno association */
243 int si_code
; /* signal code */
244 pid_t si_pid
; /* sending process */
245 uid_t si_uid
; /* sender's ruid */
246 int si_status
; /* exit value */
247 user_addr_t si_addr
; /* faulting instruction */
248 union user_sigval si_value
; /* signal value */
249 user_long_t si_band
; /* band event for SIGPOLL */
250 user_ulong_t pad
[7]; /* Reserved for Future Use */
253 #endif /* BSD_KERNEL_PRIVATE */
256 * Incase of SIGILL and SIGFPE, si_addr contains the address of
257 * faulting instruction.
258 * Incase of SIGSEGV and SIGBUS, si_addr contains address of
259 * faulting memory reference.
260 * Incase of SIGCHLD, si_pid willhave child process ID,
261 * si_status will contain exit value or signal.
262 * si_uid contains real user ID of the process that sent the signal
265 /* Values for si_code */
267 /* Codes for SIGILL */
268 #ifndef _POSIX_C_SOURCE
269 #define ILL_NOOP 0 /* if only I knew... */
271 #define ILL_ILLOPC 1 /* [XSI] illegal opcode */
272 #define ILL_ILLTRP 2 /* [XSI] illegal trap */
273 #define ILL_PRVOPC 3 /* [XSI] privileged opcode */
274 #define ILL_ILLOPN 4 /* [XSI] illegal operand -NOTIMP */
275 #define ILL_ILLADR 5 /* [XSI] illegal addressing mode -NOTIMP */
276 #define ILL_PRVREG 6 /* [XSI] privileged register -NOTIMP */
277 #define ILL_COPROC 7 /* [XSI] coprocessor error -NOTIMP */
278 #define ILL_BADSTK 8 /* [XSI] internal stack error -NOTIMP */
280 /* Codes for SIGFPE */
281 #ifndef _POSIX_C_SOURCE
282 #define FPE_NOOP 0 /* if only I knew... */
284 #define FPE_FLTDIV 1 /* [XSI] floating point divide by zero */
285 #define FPE_FLTOVF 2 /* [XSI] floating point overflow */
286 #define FPE_FLTUND 3 /* [XSI] floating point underflow */
287 #define FPE_FLTRES 4 /* [XSI] floating point inexact result */
288 #define FPE_FLTINV 5 /* [XSI] invalid floating point operation */
289 #define FPE_FLTSUB 6 /* [XSI] subscript out of range -NOTIMP */
290 #define FPE_INTDIV 7 /* [XSI] integer divide by zero -NOTIMP */
291 #define FPE_INTOVF 8 /* [XSI] integer overflow -NOTIMP */
293 /* Codes for SIGSEGV */
294 #ifndef _POSIX_C_SOURCE
295 #define SEGV_NOOP 0 /* if only I knew... */
297 #define SEGV_MAPERR 1 /* [XSI] address not mapped to object */
298 #define SEGV_ACCERR 2 /* [XSI] invalid permission for mapped object */
300 /* Codes for SIGBUS */
301 #ifndef _POSIX_C_SOURCE
302 #define BUS_NOOP 0 /* if only I knew... */
304 #define BUS_ADRALN 1 /* [XSI] Invalid address alignment */
305 #define BUS_ADRERR 2 /* [XSI] Nonexistent physical address -NOTIMP */
306 #define BUS_OBJERR 3 /* [XSI] Object-specific HW error - NOTIMP */
308 /* Codes for SIGTRAP */
309 #define TRAP_BRKPT 1 /* [XSI] Process breakpoint -NOTIMP */
310 #define TRAP_TRACE 2 /* [XSI] Process trace trap -NOTIMP */
312 /* Codes for SIGCHLD */
313 #ifndef _POSIX_C_SOURCE
314 #define CLD_NOOP 0 /* if only I knew... */
316 #define CLD_EXITED 1 /* [XSI] child has exited */
317 #define CLD_KILLED 2 /* [XSI] terminated abnormally, no core file */
318 #define CLD_DUMPED 3 /* [XSI] terminated abnormally, core file */
319 #define CLD_TRAPPED 4 /* [XSI] traced child has trapped */
320 #define CLD_STOPPED 5 /* [XSI] child has stopped */
321 #define CLD_CONTINUED 6 /* [XSI] stopped child has continued */
323 /* Codes for SIGPOLL */
324 #define POLL_IN 1 /* [XSR] Data input available */
325 #define POLL_OUT 2 /* [XSR] Output buffers available */
326 #define POLL_MSG 3 /* [XSR] Input message available */
327 #define POLL_ERR 4 /* [XSR] I/O error */
328 #define POLL_PRI 5 /* [XSR] High priority input available */
329 #define POLL_HUP 6 /* [XSR] Device disconnected */
331 /* union for signal handlers */
332 union __sigaction_u
{
333 void (*__sa_handler
)(int);
334 void (*__sa_sigaction
)(int, struct __siginfo
*,
338 /* Signal vector template for Kernel user boundary */
340 union __sigaction_u __sigaction_u
; /* signal handler */
341 void (*sa_tramp
)(void *, int, int, siginfo_t
*, void *);
342 sigset_t sa_mask
; /* signal mask to apply */
343 int sa_flags
; /* see signal options below */
347 * Signal vector "template" used in sigaction call.
350 union __sigaction_u __sigaction_u
; /* signal handler */
351 sigset_t sa_mask
; /* signal mask to apply */
352 int sa_flags
; /* see signal options below */
355 #ifdef BSD_KERNEL_PRIVATE
356 #include <machine/types.h>
358 union __user_sigaction_u
{
359 user_addr_t __sa_handler
;
360 user_addr_t __sa_sigaction
;
363 struct user_sigaction
{
364 union __user_sigaction_u __sigaction_u
; /* signal handler */
365 sigset_t sa_mask
; /* signal mask to apply */
366 int sa_flags
; /* see signal options below */
369 struct __user_sigaction
{
370 union __user_sigaction_u __sigaction_u
; /* signal handler */
371 user_addr_t sa_tramp
; /* signal mask to apply */
372 sigset_t sa_mask
; /* signal mask to apply */
373 int sa_flags
; /* see signal options below */
379 #define SIG_DFL ((user_addr_t)0LL)
380 #define SIG_IGN ((user_addr_t)1LL)
381 #define SIG_ERR ((user_addr_t)-1LL)
383 #endif /* BSD_KERNEL_PRIVATE */
386 /* if SA_SIGINFO is set, sa_sigaction is to be used instead of sa_handler. */
387 #define sa_handler __sigaction_u.__sa_handler
388 #define sa_sigaction __sigaction_u.__sa_sigaction
390 #define SA_ONSTACK 0x0001 /* take signal on signal stack */
391 #define SA_RESTART 0x0002 /* restart system on signal return */
392 #define SA_DISABLE 0x0004 /* disable taking signals on alternate stack */
393 #define SA_RESETHAND 0x0004 /* reset to SIG_DFL when taking signal */
394 #define SA_NOCLDSTOP 0x0008 /* do not generate SIGCHLD on child stop */
395 #define SA_NODEFER 0x0010 /* don't mask the signal we're delivering */
396 #define SA_NOCLDWAIT 0x0020 /* don't keep zombies around */
397 #define SA_SIGINFO 0x0040 /* signal handler with SA_SIGINFO args */
398 #ifndef _POSIX_C_SOURCE
399 #define SA_USERTRAMP 0x0100 /* do not bounce off kernel's sigtramp */
400 /* This will provide 64bit register set in a 32bit user address space */
401 #define SA_64REGSET 0x0200 /* signal handler with SA_SIGINFO args with 64bit regs information */
402 #endif /* !_POSIX_C_SOURCE */
405 * Flags for sigprocmask:
407 #define SIG_BLOCK 1 /* block specified signal set */
408 #define SIG_UNBLOCK 2 /* unblock specified signal set */
409 #define SIG_SETMASK 3 /* set specified signal set */
411 /* POSIX 1003.1b required values. */
412 #define SI_USER 0x10001 /* [CX] signal from kill() */
413 #define SI_QUEUE 0x10002 /* [CX] signal from sigqueue() */
414 #define SI_TIMER 0x10003 /* [CX] timer expiration */
415 #define SI_ASYNCIO 0x10004 /* [CX] aio request completion */
416 #define SI_MESGQ 0x10005 /* [CX] from message arrival on empty queue */
418 #ifndef _POSIX_C_SOURCE
419 typedef void (*sig_t
)(int); /* type of signal function */
423 * Structure used in sigaltstack call.
425 #ifdef BSD_KERNEL_PRIVATE
427 struct user_sigaltstack
{
428 user_addr_t ss_sp
; /* signal stack base */
429 user_size_t ss_size
; /* signal stack length */
430 int ss_flags
__attribute((aligned(8))); /* SA_DISABLE and/or SA_ONSTACK */
433 #endif /* BSD_KERNEL_PRIVATE */
437 typedef __darwin_stack_t stack_t
;
440 #define SS_ONSTACK 0x0001 /* take signal on signal stack */
441 #define SS_DISABLE 0x0004 /* disable taking signals on alternate stack */
442 #define MINSIGSTKSZ 32768 /* (32K)minimum allowable stack */
443 #define SIGSTKSZ 131072 /* (128K)recommended stack size */
445 #ifndef _POSIX_C_SOURCE
448 * Signal vector "template" used in sigvec call.
451 void (*sv_handler
)(int); /* signal handler */
452 int sv_mask
; /* signal mask to apply */
453 int sv_flags
; /* see signal options below */
456 #define SV_ONSTACK SA_ONSTACK
457 #define SV_INTERRUPT SA_RESTART /* same bit, opposite sense */
458 #define SV_RESETHAND SA_RESETHAND
459 #define SV_NODEFER SA_NODEFER
460 #define SV_NOCLDSTOP SA_NOCLDSTOP
461 #define SV_SIGINFO SA_SIGINFO
463 #define sv_onstack sv_flags /* isn't compatibility wonderful! */
464 #endif /* !_POSIX_C_SOURCE */
467 * Structure used in sigstack call.
470 char *ss_sp
; /* signal stack pointer */
471 int ss_onstack
; /* current status */
474 #ifndef _POSIX_C_SOURCE
476 * Macro for converting signal number to a mask suitable for
479 #define sigmask(m) (1 << ((m)-1))
481 #ifdef BSD_KERNEL_PRIVATE
483 * signals delivered on a per-thread basis.
485 #define threadmask (sigmask(SIGILL)|sigmask(SIGTRAP)|\
486 sigmask(SIGIOT)|sigmask(SIGEMT)|\
487 sigmask(SIGFPE)|sigmask(SIGBUS)|\
488 sigmask(SIGSEGV)|sigmask(SIGSYS)|\
490 #endif /* BSD_KERNEL_PRIVATE */
492 #define BADSIG SIG_ERR
494 #endif /* !_POSIX_C_SOURCE */
495 #endif /* !_ANSI_SOURCE */
498 * For historical reasons; programs expect signal's return value to be
499 * defined by <sys/signal.h>.
502 void (*signal(int, void (*)(int)))(int);
504 #endif /* !_SYS_SIGNAL_H_ */