sig_machdep.c revision 1.16 1 /* $NetBSD: sig_machdep.c,v 1.16 2007/07/08 10:19:22 pooka Exp $ */
2
3 /*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Matthew Fredette.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Copyright (c) 1982, 1986, 1990, 1993
41 * The Regents of the University of California. All rights reserved.
42 *
43 * This code is derived from software contributed to Berkeley by
44 * the Systems Programming Group of the University of Utah Computer
45 * Science Department.
46 *
47 * Redistribution and use in source and binary forms, with or without
48 * modification, are permitted provided that the following conditions
49 * are met:
50 * 1. Redistributions of source code must retain the above copyright
51 * notice, this list of conditions and the following disclaimer.
52 * 2. Redistributions in binary form must reproduce the above copyright
53 * notice, this list of conditions and the following disclaimer in the
54 * documentation and/or other materials provided with the distribution.
55 * 3. Neither the name of the University nor the names of its contributors
56 * may be used to endorse or promote products derived from this software
57 * without specific prior written permission.
58 *
59 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * SUCH DAMAGE.
70 *
71 * from: Utah Hdr: machdep.c 1.74 92/12/20
72 * from: @(#)machdep.c 8.10 (Berkeley) 4/20/94
73 */
74 /*
75 * Copyright (c) 1988 University of Utah.
76 *
77 * This code is derived from software contributed to Berkeley by
78 * the Systems Programming Group of the University of Utah Computer
79 * Science Department.
80 *
81 * Redistribution and use in source and binary forms, with or without
82 * modification, are permitted provided that the following conditions
83 * are met:
84 * 1. Redistributions of source code must retain the above copyright
85 * notice, this list of conditions and the following disclaimer.
86 * 2. Redistributions in binary form must reproduce the above copyright
87 * notice, this list of conditions and the following disclaimer in the
88 * documentation and/or other materials provided with the distribution.
89 * 3. All advertising materials mentioning features or use of this software
90 * must display the following acknowledgement:
91 * This product includes software developed by the University of
92 * California, Berkeley and its contributors.
93 * 4. Neither the name of the University nor the names of its contributors
94 * may be used to endorse or promote products derived from this software
95 * without specific prior written permission.
96 *
97 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
98 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
99 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
100 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
101 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
102 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
103 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
104 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
105 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
106 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
107 * SUCH DAMAGE.
108 *
109 * from: Utah Hdr: machdep.c 1.74 92/12/20
110 * from: @(#)machdep.c 8.10 (Berkeley) 4/20/94
111 */
112
113 #include <sys/cdefs.h>
114 __KERNEL_RCSID(0, "$NetBSD: sig_machdep.c,v 1.16 2007/07/08 10:19:22 pooka Exp $");
115
116 #include "opt_compat_netbsd.h"
117
118 #define __HPPA_SIGNAL_PRIVATE
119
120 #include <sys/param.h>
121 #include <sys/systm.h>
122 #include <sys/kernel.h>
123 #include <sys/proc.h>
124 #include <sys/user.h>
125 #include <sys/signal.h>
126 #include <sys/signalvar.h>
127
128 #include <sys/mount.h>
129 #include <sys/syscallargs.h>
130
131 #include <machine/cpu.h>
132 #include <machine/reg.h>
133 #include <machine/frame.h>
134
135 #ifdef DEBUG
136 int sigdebug = 0;
137 int sigpid = 0;
138 #define SDB_FOLLOW 0x01
139 #define SDB_KSTACK 0x02
140 #define SDB_FPSTATE 0x04
141 #endif
142
143 static void *getframe(struct lwp *, int, int *);
144 static void *
145 getframe(struct lwp *l, int sig, int *onstack)
146 {
147 struct proc *p = l->l_proc;
148 struct trapframe *tf = l->l_md.md_regs;
149
150 /* Do we need to jump onto the signal stack? */
151 *onstack = (l->l_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0
152 && (SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0;
153 if (*onstack)
154 return (void *)l->l_sigstk.ss_sp;
155 else
156 return (void *)tf->tf_sp;
157 }
158
159 struct sigframe_siginfo {
160 siginfo_t sf_si;
161 ucontext_t sf_uc;
162 };
163
164 void
165 sendsig(const struct ksiginfo *ksi, const sigset_t *mask)
166 {
167 struct lwp *l = curlwp;
168 struct proc *p = l->l_proc;
169 struct sigacts *ps = p->p_sigacts;
170 struct sigframe_siginfo *fp, frame;
171 struct trapframe *tf;
172 int sig = ksi->ksi_signo;
173 sig_t catcher = SIGACTION(p, sig).sa_handler;
174 int onstack, error;
175
176 fp = getframe(l, sig, &onstack);
177 tf = (struct trapframe *)l->l_md.md_regs;
178
179 /* Build stack frame for signal trampoline. */
180 switch (ps->sa_sigdesc[sig].sd_vers) {
181 default:
182 printf("sendsig_siginfo: bad version %d\n",
183 ps->sa_sigdesc[sig].sd_vers);
184 sigexit(l, SIGILL);
185 case 2:
186 break;
187 }
188
189 frame.sf_si._info = ksi->ksi_info;
190 frame.sf_uc.uc_flags = _UC_SIGMASK |
191 ((l->l_sigstk.ss_flags & SS_ONSTACK) ?
192 _UC_SETSTACK : _UC_CLRSTACK);
193 frame.sf_uc.uc_sigmask = *mask;
194 frame.sf_uc.uc_link = l->l_ctxlink;
195 memset(&frame.sf_uc.uc_stack, 0, sizeof(frame.sf_uc.uc_stack));
196 sendsig_reset(l, sig);
197 mutex_exit(&p->p_smutex);
198 cpu_getmcontext(l, &frame.sf_uc.uc_mcontext, &frame.sf_uc.uc_flags);
199 error = copyout(&frame, fp, sizeof(frame));
200 mutex_enter(&p->p_smutex);
201
202 if (error != 0) {
203
204 /*
205 * Process has trashed its stack; give it an illegal
206 * instruction to halt it in its tracks.
207 */
208 sigexit(l, SIGILL);
209 /* NOTREACHED */
210 }
211
212 /*
213 * Set up the registers to invoke the signal trampoline.
214 */
215 tf->tf_arg0 = sig;
216 tf->tf_arg1 = (__greg_t)&fp->sf_si;
217 tf->tf_arg2 = (__greg_t)&fp->sf_uc;
218 tf->tf_r3 = (__greg_t)&fp->sf_uc;
219
220 tf->tf_iisq_head = tf->tf_iisq_tail = l->l_addr->u_pcb.pcb_space;
221 tf->tf_iioq_head =
222 (__greg_t)ps->sa_sigdesc[sig].sd_tramp | HPPA_PC_PRIV_USER;
223 tf->tf_iioq_tail = tf->tf_iioq_head + 4;
224 tf->tf_arg3 = (__greg_t)catcher;
225 tf->tf_sp = HPPA_FRAME_ROUND((uintptr_t)fp + sizeof(*fp) +
226 HPPA_FRAME_SIZE);
227
228 /* Remember that we're now on the signal stack. */
229 if (onstack)
230 l->l_sigstk.ss_flags |= SS_ONSTACK;
231 }
232