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