]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/signal.h
xnu-517.7.7.tar.gz
[apple/xnu.git] / bsd / sys / signal.h
1 /*
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
23 /*
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.
31 *
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
34 * are met:
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.
47 *
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
58 * SUCH DAMAGE.
59 *
60 * @(#)signal.h 8.2 (Berkeley) 1/21/94
61 */
62
63 #ifndef _SYS_SIGNAL_H_
64 #define _SYS_SIGNAL_H_
65
66 #include <sys/appleapiopts.h>
67
68 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
69 #define NSIG 32 /* counting 0; could be 33 (mask is 1-32) */
70 #endif
71
72 #include <machine/signal.h> /* sigcontext; codes for SIGILL, SIGFPE */
73
74 #define SIGHUP 1 /* hangup */
75 #define SIGINT 2 /* interrupt */
76 #define SIGQUIT 3 /* quit */
77 #define SIGILL 4 /* illegal instruction (not reset when caught) */
78 #if !defined(_POSIX_SOURCE)
79 #define SIGTRAP 5 /* trace trap (not reset when caught) */
80 #endif
81 #define SIGABRT 6 /* abort() */
82 #if !defined(_POSIX_SOURCE)
83 #define SIGIOT SIGABRT /* compatibility */
84 #define SIGEMT 7 /* EMT instruction */
85 #endif
86 #define SIGFPE 8 /* floating point exception */
87 #define SIGKILL 9 /* kill (cannot be caught or ignored) */
88 #if !defined(_POSIX_SOURCE)
89 #define SIGBUS 10 /* bus error */
90 #endif
91 #define SIGSEGV 11 /* segmentation violation */
92 #if !defined(_POSIX_SOURCE)
93 #define SIGSYS 12 /* bad argument to system call */
94 #endif
95 #define SIGPIPE 13 /* write on a pipe with no one to read it */
96 #define SIGALRM 14 /* alarm clock */
97 #define SIGTERM 15 /* software termination signal from kill */
98 #if !defined(_POSIX_SOURCE)
99 #define SIGURG 16 /* urgent condition on IO channel */
100 #endif
101 #define SIGSTOP 17 /* sendable stop signal not from tty */
102 #define SIGTSTP 18 /* stop signal from tty */
103 #define SIGCONT 19 /* continue a stopped process */
104 #define SIGCHLD 20 /* to parent on child stop or exit */
105 #define SIGTTIN 21 /* to readers pgrp upon background tty read */
106 #define SIGTTOU 22 /* like TTIN for output if (tp->t_local&LTOSTOP) */
107 #if !defined(_POSIX_SOURCE)
108 #define SIGIO 23 /* input/output possible signal */
109 #define SIGXCPU 24 /* exceeded CPU time limit */
110 #define SIGXFSZ 25 /* exceeded file size limit */
111 #define SIGVTALRM 26 /* virtual time alarm */
112 #define SIGPROF 27 /* profiling time alarm */
113 #define SIGWINCH 28 /* window size changes */
114 #define SIGINFO 29 /* information request */
115 #endif
116 #define SIGUSR1 30 /* user defined signal 1 */
117 #define SIGUSR2 31 /* user defined signal 2 */
118
119 #if defined(_ANSI_SOURCE) || defined(__cplusplus)
120 /*
121 * Language spec sez we must list exactly one parameter, even though we
122 * actually supply three. Ugh!
123 */
124 #define SIG_DFL (void (*)(int))0
125 #define SIG_IGN (void (*)(int))1
126 #define SIG_ERR (void (*)(int))-1
127 #else
128 #define SIG_DFL (void (*)())0
129 #define SIG_IGN (void (*)())1
130 #define SIG_ERR (void (*)())-1
131 #endif
132
133 #ifndef _ANSI_SOURCE
134 #include <sys/types.h>
135
136 typedef unsigned int sigset_t;
137
138 union sigval {
139 /* Members as suggested by Annex C of POSIX 1003.1b. */
140 int sigval_int;
141 void *sigval_ptr;
142 };
143
144 #define SIGEV_NONE 0 /* No async notification */
145 #define SIGEV_SIGNAL 1 /* aio - completion notification */
146 #ifdef __APPLE_API_PRIVATE
147 #define SIGEV_THREAD 3 /* A notification function will be called to perform notification */
148 #endif /*__APPLE_API_PRIVATE */
149
150 struct sigevent {
151 int sigev_notify; /* Notification type */
152 int sigev_signo; /* Signal number */
153 union sigval sigev_value; /* Signal value */
154 void (*sigev_notify_function)(union sigval); /* Notification function */
155 pthread_attr_t *sigev_notify_attributes; /* Notification attributes */
156 };
157
158 typedef struct __siginfo {
159 int si_signo; /* signal number */
160 int si_errno; /* errno association */
161 int si_code; /* signal code */
162 int si_pid; /* sending process */
163 unsigned int si_uid; /* sender's ruid */
164 int si_status; /* exit value */
165 void *si_addr; /* faulting instruction */
166 union sigval si_value; /* signal value */
167 long si_band; /* band event for SIGPOLL */
168 unsigned int pad[7]; /* Reserved for Future Use */
169 } siginfo_t;
170
171 /*
172 * Incase of SIGILL and SIGFPE, si_addr contains the address of
173 * faulting instruction.
174 * Incase of SIGSEGV and SIGBUS, si_addr contains address of
175 * faulting memory reference.
176 * Incase of SIGCHLD, si_pid willhave child process ID,
177 * si_status will contain exit value or signal.
178 * si_uid contains real user ID of the process that sent the signal
179 */
180
181 /* Values for si_code */
182
183 /* Codes for SIGILL */
184 #define ILL_NOOP 0 /* if only I knew... */
185 #define ILL_ILLOPC 1 /* illegal opcode */
186 #define ILL_ILLTRP 2 /* illegal trap */
187 #define ILL_PRVOPC 3 /* privileged opcode */
188
189 /* Codes for SIGFPE */
190 #define FPE_NOOP 0 /* if only I knew... */
191 #define FPE_FLTDIV 1 /* floating point divide by zero */
192 #define FPE_FLTOVF 2 /* floating point overflow */
193 #define FPE_FLTUND 3 /* floating point underflow */
194 #define FPE_FLTRES 4 /* floating point inexact result */
195 #define FPE_FLTINV 5 /* invalid floating point operation */
196
197 /* Codes for SIGSEGV */
198 #define SEGV_NOOP 0 /* if only I knew... */
199 #define SEGV_MAPERR 1 /* address not mapped to object */
200 #define SEGV_ACCERR 2 /* invalid permissions for mapped to object */
201
202 /* Codes for SIGBUS */
203 #define BUS_NOOP 0 /* if only I knew... */
204 #define BUS_ADRALN 1 /* invalid address alignment */
205
206 /* Codes for SIGCHLD */
207 #define CLD_NOOP 0 /* if only I knew... */
208 #define CLD_EXITED 1 /* child has exited */
209 #define CLD_KILLED 2
210 /* child has terminated abnormally and did not create a core file */
211 #define CLD_DUMPED 3
212 /* child has terminated abnormally and create a core file */
213 #define CLD_TRAPPED 4 /* traced child has trapped */
214 #define CLD_STOPPED 5 /* child has stopped */
215 #define CLD_CONTINUED 6 /* stopped child has continued */
216
217 /* union for signal handlers */
218 union __sigaction_u {
219 void (*__sa_handler)(int);
220 void (*__sa_sigaction)(int, struct __siginfo *,
221 void *);
222 };
223
224 /* Signal vector template for Kernel user boundary */
225 struct __sigaction {
226 union __sigaction_u __sigaction_u; /* signal handler */
227 void (*sa_tramp)(void *, int, int, siginfo_t *, void *);
228 sigset_t sa_mask; /* signal mask to apply */
229 int sa_flags; /* see signal options below */
230 };
231
232 /*
233 * Signal vector "template" used in sigaction call.
234 */
235 struct sigaction {
236 union __sigaction_u __sigaction_u; /* signal handler */
237 sigset_t sa_mask; /* signal mask to apply */
238 int sa_flags; /* see signal options below */
239 };
240 /* if SA_SIGINFO is set, sa_sigaction is to be used instead of sa_handler. */
241 #define sa_handler __sigaction_u.__sa_handler
242 #define sa_sigaction __sigaction_u.__sa_sigaction
243
244
245 #if !defined(_POSIX_SOURCE)
246 #define SA_ONSTACK 0x0001 /* take signal on signal stack */
247 #define SA_RESTART 0x0002 /* restart system on signal return */
248 #define SA_DISABLE 0x0004 /* disable taking signals on alternate stack */
249 #define SA_RESETHAND 0x0004 /* reset to SIG_DFL when taking signal */
250 #define SA_NODEFER 0x0010 /* don't mask the signal we're delivering */
251 #define SA_NOCLDWAIT 0x0020 /* don't keep zombies around */
252 #define SA_SIGINFO 0x0040 /* signal handler with SA_SIGINFO args */
253 #define SA_USERTRAMP 0x0100 /* do not bounce off kernel's sigtramp */
254 /* This will provide 64bit register set in a 32bit user address space */
255 #define SA_64REGSET 0x0200 /* signal handler with SA_SIGINFO args with 64bit regs information */
256 #endif
257 #define SA_NOCLDSTOP 0x0008 /* do not generate SIGCHLD on child stop */
258
259 /*
260 * Flags for sigprocmask:
261 */
262 #define SIG_BLOCK 1 /* block specified signal set */
263 #define SIG_UNBLOCK 2 /* unblock specified signal set */
264 #define SIG_SETMASK 3 /* set specified signal set */
265
266 /* POSIX 1003.1b required values. */
267 #define SI_USER 0x10001
268 #define SI_QUEUE 0x10002
269 #define SI_TIMER 0x10003
270 #define SI_ASYNCIO 0x10004
271 #define SI_MESGQ 0x10005
272
273 #if !defined(_POSIX_SOURCE)
274 #include <sys/cdefs.h>
275 typedef void (*sig_t) __P((int)); /* type of signal function */
276
277 /*
278 * Structure used in sigaltstack call.
279 */
280 struct sigaltstack {
281 char *ss_sp; /* signal stack base */
282 int ss_size; /* signal stack length */
283 int ss_flags; /* SA_DISABLE and/or SA_ONSTACK */
284 };
285
286 typedef struct sigaltstack stack_t;
287
288 #define SS_ONSTACK 0x0001 /* take signal on signal stack */
289 #define SS_DISABLE 0x0004 /* disable taking signals on alternate stack */
290 #define MINSIGSTKSZ 32768 /* (32K)minimum allowable stack */
291 #define SIGSTKSZ 131072 /* (128K)recommended stack size */
292
293 /*
294 * 4.3 compatibility:
295 * Signal vector "template" used in sigvec call.
296 */
297 struct sigvec {
298 void (*sv_handler)(int); /* signal handler */
299 int sv_mask; /* signal mask to apply */
300 int sv_flags; /* see signal options below */
301 };
302
303 #define SV_ONSTACK SA_ONSTACK
304 #define SV_INTERRUPT SA_RESTART /* same bit, opposite sense */
305 #define SV_RESETHAND SA_RESETHAND
306 #define SV_NODEFER SA_NODEFER
307 #define SV_NOCLDSTOP SA_NOCLDSTOP
308 #define SV_SIGINFO SA_SIGINFO
309
310 #define sv_onstack sv_flags /* isn't compatibility wonderful! */
311
312 /*
313 * Structure used in sigstack call.
314 */
315 struct sigstack {
316 char *ss_sp; /* signal stack pointer */
317 int ss_onstack; /* current status */
318 };
319
320 /*
321 * Macro for converting signal number to a mask suitable for
322 * sigblock().
323 */
324 #define sigmask(m) (1 << ((m)-1))
325
326 #ifdef KERNEL
327 #ifdef __APPLE_API_PRIVATE
328 /*
329 * signals delivered on a per-thread basis.
330 */
331 #define threadmask (sigmask(SIGILL)|sigmask(SIGTRAP)|\
332 sigmask(SIGIOT)|sigmask(SIGEMT)|\
333 sigmask(SIGFPE)|sigmask(SIGBUS)|\
334 sigmask(SIGSEGV)|sigmask(SIGSYS)|\
335 sigmask(SIGPIPE))
336 #endif /* __APPLE_API_PRIVATE */
337 #endif /* KERNEL */
338
339 #define BADSIG SIG_ERR
340
341 #endif /* !_POSIX_SOURCE */
342 #endif /* !_ANSI_SOURCE */
343
344 /*
345 * For historical reasons; programs expect signal's return value to be
346 * defined by <sys/signal.h>.
347 */
348 __BEGIN_DECLS
349 void (*signal __P((int, void (*) __P((int))))) __P((int));
350 __END_DECLS
351 #endif /* !_SYS_SIGNAL_H_ */