master
  1/*
  2 * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
  3 *
  4 * @APPLE_OSREFERENCE_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. The rights granted to you under the License
 10 * may not be used to create, or enable the creation or redistribution of,
 11 * unlawful or unlicensed copies of an Apple operating system, or to
 12 * circumvent, violate, or enable the circumvention or violation of, any
 13 * terms of an Apple operating system software license agreement.
 14 *
 15 * Please obtain a copy of the License at
 16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
 17 *
 18 * The Original Code and all software distributed under the License are
 19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
 20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
 21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
 22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
 23 * Please see the License for the specific language governing rights and
 24 * limitations under the License.
 25 *
 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
 27 */
 28/* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
 29/*
 30 * Copyright (c) 1982, 1986, 1989, 1991, 1993
 31 *	The Regents of the University of California.  All rights reserved.
 32 * (c) UNIX System Laboratories, Inc.
 33 * All or some portions of this file are derived from material licensed
 34 * to the University of California by American Telephone and Telegraph
 35 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
 36 * the permission of UNIX System Laboratories, Inc.
 37 *
 38 * Redistribution and use in source and binary forms, with or without
 39 * modification, are permitted provided that the following conditions
 40 * are met:
 41 * 1. Redistributions of source code must retain the above copyright
 42 *    notice, this list of conditions and the following disclaimer.
 43 * 2. Redistributions in binary form must reproduce the above copyright
 44 *    notice, this list of conditions and the following disclaimer in the
 45 *    documentation and/or other materials provided with the distribution.
 46 * 3. All advertising materials mentioning features or use of this software
 47 *    must display the following acknowledgement:
 48 *	This product includes software developed by the University of
 49 *	California, Berkeley and its contributors.
 50 * 4. Neither the name of the University nor the names of its contributors
 51 *    may be used to endorse or promote products derived from this software
 52 *    without specific prior written permission.
 53 *
 54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 57 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 64 * SUCH DAMAGE.
 65 *
 66 *	@(#)signal.h	8.2 (Berkeley) 1/21/94
 67 */
 68
 69#ifndef _SYS_SIGNAL_H_
 70#define _SYS_SIGNAL_H_
 71
 72#include <sys/cdefs.h>
 73#include <sys/appleapiopts.h>
 74#include <Availability.h>
 75
 76#define __DARWIN_NSIG   32      /* counting 0; could be 33 (mask is 1-32) */
 77
 78#if !defined(_ANSI_SOURCE) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
 79#define NSIG    __DARWIN_NSIG
 80#endif
 81
 82#include <machine/signal.h>     /* sigcontext; codes for SIGILL, SIGFPE */
 83
 84#define SIGHUP  1       /* hangup */
 85#define SIGINT  2       /* interrupt */
 86#define SIGQUIT 3       /* quit */
 87#define SIGILL  4       /* illegal instruction (not reset when caught) */
 88#define SIGTRAP 5       /* trace trap (not reset when caught) */
 89#define SIGABRT 6       /* abort() */
 90#if  (defined(_POSIX_C_SOURCE) && !defined(_DARWIN_C_SOURCE))
 91#define SIGPOLL 7       /* pollable event ([XSR] generated, not supported) */
 92#else   /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
 93#define SIGIOT  SIGABRT /* compatibility */
 94#define SIGEMT  7       /* EMT instruction */
 95#endif  /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
 96#define SIGFPE  8       /* floating point exception */
 97#define SIGKILL 9       /* kill (cannot be caught or ignored) */
 98#define SIGBUS  10      /* bus error */
 99#define SIGSEGV 11      /* segmentation violation */
100#define SIGSYS  12      /* bad argument to system call */
101#define SIGPIPE 13      /* write on a pipe with no one to read it */
102#define SIGALRM 14      /* alarm clock */
103#define SIGTERM 15      /* software termination signal from kill */
104#define SIGURG  16      /* urgent condition on IO channel */
105#define SIGSTOP 17      /* sendable stop signal not from tty */
106#define SIGTSTP 18      /* stop signal from tty */
107#define SIGCONT 19      /* continue a stopped process */
108#define SIGCHLD 20      /* to parent on child stop or exit */
109#define SIGTTIN 21      /* to readers pgrp upon background tty read */
110#define SIGTTOU 22      /* like TTIN for output if (tp->t_local&LTOSTOP) */
111#if  (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
112#define SIGIO   23      /* input/output possible signal */
113#endif
114#define SIGXCPU 24      /* exceeded CPU time limit */
115#define SIGXFSZ 25      /* exceeded file size limit */
116#define SIGVTALRM 26    /* virtual time alarm */
117#define SIGPROF 27      /* profiling time alarm */
118#if  (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
119#define SIGWINCH 28     /* window size changes */
120#define SIGINFO 29      /* information request */
121#endif
122#define SIGUSR1 30      /* user defined signal 1 */
123#define SIGUSR2 31      /* user defined signal 2 */
124
125#if defined(_ANSI_SOURCE) || __DARWIN_UNIX03 || defined(__cplusplus)
126/*
127 * Language spec sez we must list exactly one parameter, even though we
128 * actually supply three.  Ugh!
129 * SIG_HOLD is chosen to avoid KERN_SIG_* values in <sys/signalvar.h>
130 */
131#define SIG_DFL         (void (*)(int))0
132#define SIG_IGN         (void (*)(int))1
133#define SIG_HOLD        (void (*)(int))5
134#define SIG_ERR         ((void (*)(int))-1)
135#else
136/* DO NOT REMOVE THE COMMENTED OUT int: fixincludes needs to see them */
137#define SIG_DFL         (void (*)( /*int*/ ))0
138#define SIG_IGN         (void (*)( /*int*/ ))1
139#define SIG_HOLD        (void (*)( /*int*/ ))5
140#define SIG_ERR         ((void (*)( /*int*/ ))-1)
141#endif
142
143#ifndef _ANSI_SOURCE
144#include <sys/_types.h>
145
146#include <machine/_mcontext.h>
147
148#include <sys/_pthread/_pthread_attr_t.h>
149
150#include <sys/_types/_sigaltstack.h>
151#include <sys/_types/_ucontext.h>
152
153#include <sys/_types/_pid_t.h>
154#include <sys/_types/_sigset_t.h>
155#include <sys/_types/_size_t.h>
156#include <sys/_types/_uid_t.h>
157
158union sigval {
159	/* Members as suggested by Annex C of POSIX 1003.1b. */
160	int     sival_int;
161	void    *sival_ptr;
162};
163
164#define SIGEV_NONE      0       /* No async notification */
165#define SIGEV_SIGNAL    1       /* aio - completion notification */
166#define SIGEV_THREAD    3       /* [NOTIMP] [RTS] call notification function */
167#define SIGEV_KEVENT    4       /* Generate a kevent */
168
169struct sigevent {
170	int                             sigev_notify;                           /* Notification type */
171	int                             sigev_signo;                            /* Signal number */
172	union sigval    sigev_value;                            /* Signal value */
173	void                    (*sigev_notify_function)(union sigval);   /* Notification function */
174	pthread_attr_t  *sigev_notify_attributes;       /* Notification attributes */
175};
176
177
178typedef struct __siginfo {
179	int     si_signo;               /* signal number */
180	int     si_errno;               /* errno association */
181	int     si_code;                /* signal code */
182	pid_t   si_pid;                 /* sending process */
183	uid_t   si_uid;                 /* sender's ruid */
184	int     si_status;              /* exit value */
185	void    *si_addr;               /* faulting instruction */
186	union sigval si_value;          /* signal value */
187	long    si_band;                /* band event for SIGPOLL */
188	unsigned long   __pad[7];       /* Reserved for Future Use */
189} siginfo_t;
190
191
192/*
193 * When the signal is SIGILL or SIGFPE, si_addr contains the address of
194 * the faulting instruction.
195 * When the signal is SIGSEGV or SIGBUS, si_addr contains the address of
196 * the faulting memory reference. Although for x86 there are cases of SIGSEGV
197 * for which si_addr cannot be determined and is NULL.
198 * If the signal is SIGCHLD, the si_pid field will contain the child process ID,
199 *  si_status contains the exit value or signal and
200 *  si_uid contains the real user ID of the process that sent the signal.
201 */
202
203/* Values for si_code */
204
205/* Codes for SIGILL */
206#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
207#define ILL_NOOP        0       /* if only I knew... */
208#endif
209#define ILL_ILLOPC      1       /* [XSI] illegal opcode */
210#define ILL_ILLTRP      2       /* [XSI] illegal trap */
211#define ILL_PRVOPC      3       /* [XSI] privileged opcode */
212#define ILL_ILLOPN      4       /* [XSI] illegal operand -NOTIMP */
213#define ILL_ILLADR      5       /* [XSI] illegal addressing mode -NOTIMP */
214#define ILL_PRVREG      6       /* [XSI] privileged register -NOTIMP */
215#define ILL_COPROC      7       /* [XSI] coprocessor error -NOTIMP */
216#define ILL_BADSTK      8       /* [XSI] internal stack error -NOTIMP */
217
218/* Codes for SIGFPE */
219#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
220#define FPE_NOOP        0       /* if only I knew... */
221#endif
222#define FPE_FLTDIV      1       /* [XSI] floating point divide by zero */
223#define FPE_FLTOVF      2       /* [XSI] floating point overflow */
224#define FPE_FLTUND      3       /* [XSI] floating point underflow */
225#define FPE_FLTRES      4       /* [XSI] floating point inexact result */
226#define FPE_FLTINV      5       /* [XSI] invalid floating point operation */
227#define FPE_FLTSUB      6       /* [XSI] subscript out of range -NOTIMP */
228#define FPE_INTDIV      7       /* [XSI] integer divide by zero */
229#define FPE_INTOVF      8       /* [XSI] integer overflow */
230
231/* Codes for SIGSEGV */
232#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
233#define SEGV_NOOP       0       /* if only I knew... */
234#endif
235#define SEGV_MAPERR     1       /* [XSI] address not mapped to object */
236#define SEGV_ACCERR     2       /* [XSI] invalid permission for mapped object */
237
238/* Codes for SIGBUS */
239#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
240#define BUS_NOOP        0       /* if only I knew... */
241#endif
242#define BUS_ADRALN      1       /* [XSI] Invalid address alignment */
243#define BUS_ADRERR      2       /* [XSI] Nonexistent physical address -NOTIMP */
244#define BUS_OBJERR      3       /* [XSI] Object-specific HW error - NOTIMP */
245
246/* Codes for SIGTRAP */
247#define TRAP_BRKPT      1       /* [XSI] Process breakpoint -NOTIMP */
248#define TRAP_TRACE      2       /* [XSI] Process trace trap -NOTIMP */
249
250/* Codes for SIGCHLD */
251#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
252#define CLD_NOOP        0       /* if only I knew... */
253#endif
254#define CLD_EXITED      1       /* [XSI] child has exited */
255#define CLD_KILLED      2       /* [XSI] terminated abnormally, no core file */
256#define CLD_DUMPED      3       /* [XSI] terminated abnormally, core file */
257#define CLD_TRAPPED     4       /* [XSI] traced child has trapped */
258#define CLD_STOPPED     5       /* [XSI] child has stopped */
259#define CLD_CONTINUED   6       /* [XSI] stopped child has continued */
260
261/* Codes for SIGPOLL */
262#define POLL_IN         1       /* [XSR] Data input available */
263#define POLL_OUT        2       /* [XSR] Output buffers available */
264#define POLL_MSG        3       /* [XSR] Input message available */
265#define POLL_ERR        4       /* [XSR] I/O error */
266#define POLL_PRI        5       /* [XSR] High priority input available */
267#define POLL_HUP        6       /* [XSR] Device disconnected */
268
269/* union for signal handlers */
270union __sigaction_u {
271	void    (*__sa_handler)(int);
272	void    (*__sa_sigaction)(int, struct __siginfo *,
273	    void *);
274};
275
276/* Signal vector template for Kernel user boundary */
277struct  __sigaction {
278	union __sigaction_u __sigaction_u;  /* signal handler */
279	void    (*sa_tramp)(void *, int, int, siginfo_t *, void *);
280	sigset_t sa_mask;               /* signal mask to apply */
281	int     sa_flags;               /* see signal options below */
282};
283
284/*
285 * Signal vector "template" used in sigaction call.
286 */
287struct  sigaction {
288	union __sigaction_u __sigaction_u;  /* signal handler */
289	sigset_t sa_mask;               /* signal mask to apply */
290	int     sa_flags;               /* see signal options below */
291};
292
293
294
295/* if SA_SIGINFO is set, sa_sigaction is to be used instead of sa_handler. */
296#define sa_handler      __sigaction_u.__sa_handler
297#define sa_sigaction    __sigaction_u.__sa_sigaction
298
299#define SA_ONSTACK      0x0001  /* take signal on signal stack */
300#define SA_RESTART      0x0002  /* restart system on signal return */
301#define SA_RESETHAND    0x0004  /* reset to SIG_DFL when taking signal */
302#define SA_NOCLDSTOP    0x0008  /* do not generate SIGCHLD on child stop */
303#define SA_NODEFER      0x0010  /* don't mask the signal we're delivering */
304#define SA_NOCLDWAIT    0x0020  /* don't keep zombies around */
305#define SA_SIGINFO      0x0040  /* signal handler with SA_SIGINFO args */
306#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
307#define SA_USERTRAMP    0x0100  /* do not bounce off kernel's sigtramp */
308/* This will provide 64bit register set in a 32bit user address space */
309#define SA_64REGSET     0x0200  /* signal handler with SA_SIGINFO args with 64bit regs information */
310#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
311
312/* the following are the only bits we support from user space, the
313 * rest are for kernel use only.
314 */
315#define SA_USERSPACE_MASK (SA_ONSTACK | SA_RESTART | SA_RESETHAND | SA_NOCLDSTOP | SA_NODEFER | SA_NOCLDWAIT | SA_SIGINFO)
316
317/*
318 * Flags for sigprocmask:
319 */
320#define SIG_BLOCK       1       /* block specified signal set */
321#define SIG_UNBLOCK     2       /* unblock specified signal set */
322#define SIG_SETMASK     3       /* set specified signal set */
323
324/* POSIX 1003.1b required values. */
325#define SI_USER         0x10001 /* [CX] signal from kill() */
326#define SI_QUEUE        0x10002 /* [CX] signal from sigqueue() */
327#define SI_TIMER        0x10003 /* [CX] timer expiration */
328#define SI_ASYNCIO      0x10004 /* [CX] aio request completion */
329#define SI_MESGQ        0x10005 /* [CX]	from message arrival on empty queue */
330
331#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
332typedef void (*sig_t)(int);     /* type of signal function */
333#endif
334
335/*
336 * Structure used in sigaltstack call.
337 */
338
339#define SS_ONSTACK      0x0001  /* take signal on signal stack */
340#define SS_DISABLE      0x0004  /* disable taking signals on alternate stack */
341#define MINSIGSTKSZ     32768   /* (32K)minimum allowable stack */
342#define SIGSTKSZ        131072  /* (128K)recommended stack size */
343
344#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
345/*
346 * 4.3 compatibility:
347 * Signal vector "template" used in sigvec call.
348 */
349struct  sigvec {
350	void    (*sv_handler)(int);     /* signal handler */
351	int     sv_mask;                /* signal mask to apply */
352	int     sv_flags;               /* see signal options below */
353};
354
355#define SV_ONSTACK      SA_ONSTACK
356#define SV_INTERRUPT    SA_RESTART      /* same bit, opposite sense */
357#define SV_RESETHAND    SA_RESETHAND
358#define SV_NODEFER      SA_NODEFER
359#define SV_NOCLDSTOP    SA_NOCLDSTOP
360#define SV_SIGINFO      SA_SIGINFO
361
362#define sv_onstack sv_flags     /* isn't compatibility wonderful! */
363#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
364
365/*
366 * Structure used in sigstack call.
367 */
368struct  sigstack {
369	char    *ss_sp;                 /* signal stack pointer */
370	int     ss_onstack;             /* current status */
371};
372
373#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
374/*
375 * Macro for converting signal number to a mask suitable for
376 * sigblock().
377 */
378#define sigmask(m)      (1 << ((m)-1))
379
380
381#define BADSIG          SIG_ERR
382
383#endif  /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
384#endif  /* !_ANSI_SOURCE */
385
386/*
387 * For historical reasons; programs expect signal's return value to be
388 * defined by <sys/signal.h>.
389 */
390__BEGIN_DECLS
391void(*signal(int, void (*)(int)))(int);
392__END_DECLS
393#endif  /* !_SYS_SIGNAL_H_ */