]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/signalvar.h
xnu-517.3.7.tar.gz
[apple/xnu.git] / bsd / sys / signalvar.h
1 /*
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
26 /*
27 * Copyright (c) 1991, 1993
28 * The Regents of the University of California. All rights reserved.
29 *
30 * Redistribution and use in source and binary forms, with or without
31 * modification, are permitted provided that the following conditions
32 * are met:
33 * 1. Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * 2. Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in the
37 * documentation and/or other materials provided with the distribution.
38 * 3. All advertising materials mentioning features or use of this software
39 * must display the following acknowledgement:
40 * This product includes software developed by the University of
41 * California, Berkeley and its contributors.
42 * 4. Neither the name of the University nor the names of its contributors
43 * may be used to endorse or promote products derived from this software
44 * without specific prior written permission.
45 *
46 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 * SUCH DAMAGE.
57 *
58 * @(#)signalvar.h 8.3 (Berkeley) 1/4/94
59 */
60
61 #ifndef _SYS_SIGNALVAR_H_ /* tmp for user.h */
62 #define _SYS_SIGNALVAR_H_
63
64 #include <sys/appleapiopts.h>
65
66 #ifdef __APPLE_API_PRIVATE
67 /*
68 * Kernel signal definitions and data structures,
69 * not exported to user programs.
70 */
71
72 /*
73 * Process signal actions and state, needed only within the process
74 * (not necessarily resident).
75 */
76 struct sigacts {
77 sig_t ps_sigact[NSIG]; /* disposition of signals */
78 sig_t ps_trampact[NSIG]; /* disposition of signals */
79 sigset_t ps_catchmask[NSIG]; /* signals to be blocked */
80 sigset_t ps_sigonstack; /* signals to take on sigstack */
81 sigset_t ps_sigintr; /* signals that interrupt syscalls */
82 sigset_t ps_sigreset; /* signals that reset when caught */
83 sigset_t ps_signodefer; /* signals not masked while handled */
84 sigset_t ps_siginfo; /* signals that want SA_SIGINFO args */
85 sigset_t ps_oldmask; /* saved mask from before sigpause */
86 int ps_flags; /* signal flags, below */
87 struct sigaltstack ps_sigstk; /* sp & on stack state variable */
88 int ps_sig; /* for core dump/debugger XXX */
89 int ps_code; /* for core dump/debugger XXX */
90 int ps_addr; /* for core dump/debugger XXX */
91 sigset_t ps_usertramp; /* SunOS compat; libc sigtramp XXX */
92 sigset_t ps_64regset; /* signals that want SA_EXSIGINFO args */
93 };
94
95 /* signal flags */
96 #define SAS_OLDMASK 0x01 /* need to restore mask before pause */
97 #define SAS_ALTSTACK 0x02 /* have alternate signal stack */
98
99 /* additional signal action values, used only temporarily/internally */
100 #define SIG_CATCH (void (*)())2
101 #define SIG_HOLD (void (*)())3
102 #define SIG_WAIT (void (*)())4
103
104 #define pgsigio(pgid, sig, notused) \
105 { \
106 struct proc *p; \
107 if (pgid < 0) \
108 gsignal(-(pgid), sig);\
109 else if (pgid > 0 && (p = pfind(pgid)) != 0) \
110 psignal(p, sig); \
111 }
112
113 /*
114 * get signal action for process and signal; currently only for current process
115 */
116 #define SIGACTION(p, sig) (p->p_sigacts->ps_sigact[(sig)])
117
118 /*
119 * Check for per-process and per thread signals.
120 */
121 #define SHOULDissignal(p,uthreadp) \
122 (((uthreadp)->uu_siglist) \
123 & ~((((uthreadp)->uu_sigmask) \
124 | (((p)->p_flag & P_TRACED) ? 0 : (p)->p_sigignore)) \
125 & ~sigcantmask))
126
127 /*
128 * Check for signals and per-thread signals.
129 * Use in trap() and syscall() before
130 * exiting kernel.
131 */
132 #define CHECK_SIGNALS(p, thread, uthreadp) \
133 (!thread_should_halt(thread) \
134 && (SHOULDissignal(p,uthreadp)))
135
136 /*
137 * Signal properties and actions.
138 * The array below categorizes the signals and their default actions
139 * according to the following properties:
140 */
141 #define SA_KILL 0x01 /* terminates process by default */
142 #define SA_CORE 0x02 /* ditto and coredumps */
143 #define SA_STOP 0x04 /* suspend process */
144 #define SA_TTYSTOP 0x08 /* ditto, from tty */
145 #define SA_IGNORE 0x10 /* ignore by default */
146 #define SA_CONT 0x20 /* continue if suspended */
147 #define SA_CANTMASK 0x40 /* non-maskable, catchable */
148
149 #ifdef SIGPROP
150 int sigprop[NSIG + 1] = {
151 0, /* unused */
152 SA_KILL, /* SIGHUP */
153 SA_KILL, /* SIGINT */
154 SA_KILL|SA_CORE, /* SIGQUIT */
155 SA_KILL|SA_CORE, /* SIGILL */
156 SA_KILL|SA_CORE, /* SIGTRAP */
157 SA_KILL|SA_CORE, /* SIGABRT */
158 SA_KILL|SA_CORE, /* SIGEMT */
159 SA_KILL|SA_CORE, /* SIGFPE */
160 SA_KILL, /* SIGKILL */
161 SA_KILL|SA_CORE, /* SIGBUS */
162 SA_KILL|SA_CORE, /* SIGSEGV */
163 SA_KILL|SA_CORE, /* SIGSYS */
164 SA_KILL, /* SIGPIPE */
165 SA_KILL, /* SIGALRM */
166 SA_KILL, /* SIGTERM */
167 SA_IGNORE, /* SIGURG */
168 SA_STOP, /* SIGSTOP */
169 SA_STOP|SA_TTYSTOP, /* SIGTSTP */
170 SA_IGNORE|SA_CONT, /* SIGCONT */
171 SA_IGNORE, /* SIGCHLD */
172 SA_STOP|SA_TTYSTOP, /* SIGTTIN */
173 SA_STOP|SA_TTYSTOP, /* SIGTTOU */
174 SA_IGNORE, /* SIGIO */
175 SA_KILL, /* SIGXCPU */
176 SA_KILL, /* SIGXFSZ */
177 SA_KILL, /* SIGVTALRM */
178 SA_KILL, /* SIGPROF */
179 SA_IGNORE, /* SIGWINCH */
180 SA_IGNORE, /* SIGINFO */
181 SA_KILL, /* SIGUSR1 */
182 SA_KILL, /* SIGUSR2 */
183 };
184
185 #define contsigmask (sigmask(SIGCONT))
186 #define stopsigmask (sigmask(SIGSTOP) | sigmask(SIGTSTP) | \
187 sigmask(SIGTTIN) | sigmask(SIGTTOU))
188
189 #endif /* SIGPROP */
190
191 #define sigcantmask (sigmask(SIGKILL) | sigmask(SIGSTOP))
192
193 #ifdef KERNEL
194 /*
195 * Machine-independent functions:
196 */
197 int coredump __P((struct proc *p));
198 void execsigs __P((struct proc *p, thread_act_t thr_act));
199 void gsignal __P((int pgid, int sig));
200 int issignal __P((struct proc *p));
201 int CURSIG __P((struct proc *p));
202 int clear_procsiglist __P((struct proc *p, int bit));
203 int clear_procsigmask __P((struct proc *p, int bit));
204 int set_procsigmask __P((struct proc *p, int bit));
205 void tty_pgsignal __P((struct pgrp *pgrp, int sig));
206 void postsig __P((int sig));
207 void siginit __P((struct proc *p));
208 void trapsignal __P((struct proc *p, int sig, unsigned code));
209 void pt_setrunnable __P((struct proc *p));
210
211 /*
212 * Machine-dependent functions:
213 */
214 void sendsig __P((struct proc *, sig_t action, int sig,
215 int returnmask, u_long code));
216
217 #ifdef __APPLE_API_UNSTABLE
218 void psignal __P((struct proc *p, int sig));
219 void pgsignal __P((struct pgrp *pgrp, int sig, int checkctty));
220 #endif /* __APPLE_API_UNSTABLE */
221
222 #endif /* KERNEL */
223
224 #endif /* __APPLE_API_PRIVATE */
225
226 #endif /* !_SYS_SIGNALVAR_H_ */