xref: /xnu-10063.121.3/bsd/sys/signalvar.h (revision 2c2f96dc2b9a4408a43d3150ae9c105355ca3daa)
1 /*
2  * Copyright (c) 2000-2002 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) 1991, 1993
31  *	The Regents of the University of California.  All rights reserved.
32  *
33  * Redistribution and use in source and binary forms, with or without
34  * modification, are permitted provided that the following conditions
35  * are met:
36  * 1. Redistributions of source code must retain the above copyright
37  *    notice, this list of conditions and the following disclaimer.
38  * 2. Redistributions in binary form must reproduce the above copyright
39  *    notice, this list of conditions and the following disclaimer in the
40  *    documentation and/or other materials provided with the distribution.
41  * 3. All advertising materials mentioning features or use of this software
42  *    must display the following acknowledgement:
43  *	This product includes software developed by the University of
44  *	California, Berkeley and its contributors.
45  * 4. Neither the name of the University nor the names of its contributors
46  *    may be used to endorse or promote products derived from this software
47  *    without specific prior written permission.
48  *
49  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59  * SUCH DAMAGE.
60  *
61  *	@(#)signalvar.h	8.3 (Berkeley) 1/4/94
62  */
63 
64 #ifndef _SYS_SIGNALVAR_H_               /* tmp for user.h */
65 #define _SYS_SIGNALVAR_H_
66 
67 #include <sys/appleapiopts.h>
68 
69 #ifdef BSD_KERNEL_PRIVATE
70 
71 #include <stdatomic.h>
72 
73 /* signal flags */
74 #define SAS_OLDMASK     0x01            /* need to restore mask before pause */
75 #define SAS_ALTSTACK    0x02            /* have alternate signal stack */
76 
77 /*
78  * Additional signal action values, used only temporarily/internally; these
79  * values should be non-intersecting with values defined in signal.h, e.g.:
80  * SIG_IGN, SIG_DFL, SIG_ERR, SIG_IGN.
81  */
82 #define KERN_SIG_CATCH  CAST_USER_ADDR_T(2)
83 #define KERN_SIG_HOLD   CAST_USER_ADDR_T(3)
84 #define KERN_SIG_WAIT   CAST_USER_ADDR_T(4)
85 
86 /* Values for ps_sigreturn_validation */
87 #define PS_SIGRETURN_VALIDATION_DEFAULT 0x0u
88 #define PS_SIGRETURN_VALIDATION_ENABLED 0x1u
89 #define PS_SIGRETURN_VALIDATION_DISABLED 0x2u
90 
91 /*
92  * get signal action for process and signal; currently only for current process
93  */
94 #define SIGACTION(p, sig)       ({ p->p_sigacts.ps_sigact[(sig)]; })
95 #define SIGTRAMP(p, sig)        ({ p->p_sigacts.ps_trampact[(sig)]; })
96 
97 /*
98  *	Check for per-process and per thread signals.
99  */
100 #define SHOULDissignal(p, uthreadp) \
101 	 (((uthreadp)->uu_siglist)      \
102 	  & ~((((uthreadp)->uu_sigmask) \
103 	       | (((p)->p_lflag & P_LTRACED) ? 0 : (p)->p_sigignore)) \
104 	      & ~sigcantmask))
105 
106 /*
107  *	Check for signals and per-thread signals.
108  *  Use in trap() and syscall() before
109  *	exiting kernel.
110  */
111 #define CHECK_SIGNALS(p, thread, uthreadp)      \
112 	(!thread_should_halt(thread)    \
113 	 && (SHOULDissignal(p,uthreadp)))
114 
115 /*
116  * Signal properties and actions.
117  * The array below categorizes the signals and their default actions
118  * according to the following properties:
119  */
120 #define SA_KILL         0x01            /* terminates process by default */
121 #define SA_CORE         0x02            /* ditto and coredumps */
122 #define SA_STOP         0x04            /* suspend process */
123 #define SA_TTYSTOP      0x08            /* ditto, from tty */
124 #define SA_IGNORE       0x10            /* ignore by default */
125 #define SA_CONT         0x20            /* continue if suspended */
126 #define SA_CANTMASK     0x40            /* non-maskable, catchable */
127 
128 #ifdef  SIGPROP
129 int sigprop[NSIG] = {
130 	0,                      /* unused */
131 	SA_KILL,                /* SIGHUP */
132 	SA_KILL,                /* SIGINT */
133 	SA_KILL | SA_CORE,        /* SIGQUIT */
134 	SA_KILL | SA_CORE,        /* SIGILL */
135 	SA_KILL | SA_CORE,        /* SIGTRAP */
136 	SA_KILL | SA_CORE,        /* SIGABRT */
137 	SA_KILL | SA_CORE,        /* SIGEMT */
138 	SA_KILL | SA_CORE,        /* SIGFPE */
139 	SA_KILL,                /* SIGKILL */
140 	SA_KILL | SA_CORE,        /* SIGBUS */
141 	SA_KILL | SA_CORE,        /* SIGSEGV */
142 	SA_KILL | SA_CORE,        /* SIGSYS */
143 	SA_KILL,                /* SIGPIPE */
144 	SA_KILL,                /* SIGALRM */
145 	SA_KILL,                /* SIGTERM */
146 	SA_IGNORE,              /* SIGURG */
147 	SA_STOP,                /* SIGSTOP */
148 	SA_STOP | SA_TTYSTOP,     /* SIGTSTP */
149 	SA_IGNORE | SA_CONT,      /* SIGCONT */
150 	SA_IGNORE,              /* SIGCHLD */
151 	SA_STOP | SA_TTYSTOP,     /* SIGTTIN */
152 	SA_STOP | SA_TTYSTOP,     /* SIGTTOU */
153 	SA_IGNORE,              /* SIGIO */
154 	SA_KILL,                /* SIGXCPU */
155 	SA_KILL,                /* SIGXFSZ */
156 	SA_KILL,                /* SIGVTALRM */
157 	SA_KILL,                /* SIGPROF */
158 	SA_IGNORE,              /* SIGWINCH  */
159 	SA_IGNORE,              /* SIGINFO */
160 	SA_KILL,                /* SIGUSR1 */
161 	SA_KILL,                /* SIGUSR2 */
162 };
163 
164 #define contsigmask     (sigmask(SIGCONT))
165 #define stopsigmask     (sigmask(SIGSTOP) | sigmask(SIGTSTP) | \
166 	                    sigmask(SIGTTIN) | sigmask(SIGTTOU))
167 
168 #endif /* SIGPROP */
169 
170 #define sigcantmask     (sigmask(SIGKILL) | sigmask(SIGSTOP))
171 
172 #define SIGRESTRICTMASK (sigmask(SIGILL) | sigmask(SIGTRAP) | sigmask(SIGABRT) | \
173 	                 sigmask(SIGFPE) | sigmask(SIGBUS)  | sigmask(SIGSEGV) | \
174 	                 sigmask(SIGSYS))
175 
176 /*
177  * Machine-independent functions:
178  */
179 
180 #if DEVELOPMENT || DEBUG
181 extern bool no_sigsys;
182 #define send_sigsys (!no_sigsys)
183 #else
184 #define send_sigsys 1
185 #endif
186 
187 
188 void    execsigs(struct proc *p, thread_t thread);
189 void    gsignal(int pgid, int sig);
190 int     issignal_locked(struct proc *p);
191 int     CURSIG(struct proc *p);
192 int clear_procsiglist(struct proc *p, int bit, int in_signalstart);
193 int set_procsigmask(struct proc *p, int bit);
194 void    postsig_locked(int sig);
195 void    siginit(struct proc *p);
196 void    trapsignal(struct proc *p, int sig, unsigned code);
197 void    pt_setrunnable(struct proc *p);
198 int     hassigprop(int sig, int prop);
199 int setsigvec(proc_t, thread_t, int signum, struct __kern_sigaction *, boolean_t in_sigstart);
200 
201 struct os_reason;
202 /*
203  * Machine-dependent functions:
204  */
205 void    sendsig(struct proc *, /*sig_t*/ user_addr_t  action, int sig,
206     int returnmask, uint32_t code, sigset_t siginfo);
207 
208 void    psignal(struct proc *p, int sig);
209 void    psignal_with_reason(struct proc *p, int sig, struct os_reason *signal_reason);
210 void    psignal_locked(struct proc *, int);
211 void    psignal_try_thread(proc_t, thread_t, int signum);
212 void    psignal_try_thread_with_reason(proc_t, thread_t, int, struct os_reason*);
213 void    psignal_thread_with_reason(proc_t, thread_t, int, struct os_reason*);
214 void    psignal_uthread(thread_t, int);
215 void    pgsignal(struct pgrp *pgrp, int sig, int checkctty);
216 void    tty_pgsignal_locked(struct tty * tp, int sig, int checkctty);
217 void    threadsignal(thread_t sig_actthread, int signum,
218     mach_exception_code_t code, boolean_t set_exitreason);
219 int     thread_issignal(proc_t p, thread_t th, sigset_t mask);
220 void    psignal_vfork(struct proc *p, task_t new_task, thread_t thread,
221     int signum);
222 void    psignal_vfork_with_reason(proc_t p, task_t new_task, thread_t thread,
223     int signum, struct os_reason *signal_reason);
224 void    signal_setast(thread_t sig_actthread);
225 void    pgsigio(pid_t pgid, int signalnum);
226 
227 void sig_lock_to_exit(struct proc *p);
228 int sig_try_locked(struct proc *p);
229 
230 #endif  /* BSD_KERNEL_PRIVATE */
231 
232 #if defined(KERNEL_PRIVATE)
233 /* Forward-declare these for consumers of the SDK that don't know about BSD types */
234 struct proc;
235 struct os_reason;
236 void    psignal_sigkill_with_reason(struct proc *p, struct os_reason *signal_reason);
237 #endif /* defined(KERNEL_PRIVATE) */
238 
239 #ifdef XNU_KERNEL_PRIVATE
240 
241 /* Functions exported to Mach as well */
242 
243 #define COREDUMP_IGNORE_ULIMIT  0x0001 /* Ignore the process's core file ulimit. */
244 #define COREDUMP_FULLFSYNC      0x0002 /* Run F_FULLFSYNC on the core file's vnode */
245 
246 cpu_type_t process_cpu_type(struct proc * core_proc);
247 cpu_type_t process_cpu_subtype(struct proc * core_proc);
248 int     coredump(struct proc *p, uint32_t reserve_mb, int coredump_flags);
249 void set_thread_exit_reason(void *th, void *reason, boolean_t proc_locked);
250 
251 #endif  /* XNU_KERNEL_PRIVATE */
252 
253 
254 #endif  /* !_SYS_SIGNALVAR_H_ */
255