sig_machdep.c revision 1.13 1 /* $NetBSD: sig_machdep.c,v 1.13 2005/05/07 14:27:14 chs 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.13 2005/05/07 14:27:14 chs 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/sa.h>
130 #include <sys/syscallargs.h>
131
132 #include <machine/cpu.h>
133 #include <machine/reg.h>
134 #include <machine/frame.h>
135
136 #ifdef DEBUG
137 int sigdebug = 0;
138 int sigpid = 0;
139 #define SDB_FOLLOW 0x01
140 #define SDB_KSTACK 0x02
141 #define SDB_FPSTATE 0x04
142 #endif
143
144 static void *getframe(struct lwp *, int, int *);
145 static void *
146 getframe(struct lwp *l, int sig, int *onstack)
147 {
148 struct proc *p = l->l_proc;
149 struct sigctx *ctx = &p->p_sigctx;
150 struct trapframe *tf = l->l_md.md_regs;
151
152 /* Do we need to jump onto the signal stack? */
153 *onstack = (ctx->ps_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0
154 && (SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0;
155 if (*onstack)
156 return (void *)ctx->ps_sigstk.ss_sp;
157 else
158 return (void *)tf->tf_sp;
159 }
160
161 struct sigframe_siginfo {
162 siginfo_t sf_si;
163 ucontext_t sf_uc;
164 };
165
166 void
167 sendsig(const struct ksiginfo *ksi, const sigset_t *mask)
168 {
169 struct lwp *l = curlwp;
170 struct proc *p = l->l_proc;
171 struct sigacts *ps = p->p_sigacts;
172 struct sigframe_siginfo *fp, frame;
173 struct trapframe *tf;
174 int sig = ksi->ksi_signo;
175 sig_t catcher = SIGACTION(p, sig).sa_handler;
176 int onstack;
177
178 fp = getframe(l, sig, &onstack);
179 tf = (struct trapframe *)l->l_md.md_regs;
180
181 /* Build stack frame for signal trampoline. */
182 switch (ps->sa_sigdesc[sig].sd_vers) {
183 default:
184 printf("sendsig_siginfo: bad version %d\n",
185 ps->sa_sigdesc[sig].sd_vers);
186 sigexit(l, SIGILL);
187 case 2:
188 break;
189 }
190
191 frame.sf_si._info = ksi->ksi_info;
192 frame.sf_uc.uc_flags = _UC_SIGMASK |
193 ((p->p_sigctx.ps_sigstk.ss_flags & SS_ONSTACK) ?
194 _UC_SETSTACK : _UC_CLRSTACK);
195 frame.sf_uc.uc_sigmask = *mask;
196 frame.sf_uc.uc_link = NULL;
197 memset(&frame.sf_uc.uc_stack, 0, sizeof(frame.sf_uc.uc_stack));
198 cpu_getmcontext(l, &frame.sf_uc.uc_mcontext, &frame.sf_uc.uc_flags);
199
200 if (copyout(&frame, fp, sizeof(frame)) != 0) {
201
202 /*
203 * Process has trashed its stack; give it an illegal
204 * instruction to halt it in its tracks.
205 */
206 sigexit(l, SIGILL);
207 /* NOTREACHED */
208 }
209
210 /*
211 * Set up the registers to invoke the signal trampoline.
212 */
213 tf->tf_arg0 = sig;
214 tf->tf_arg1 = (__greg_t)&fp->sf_si;
215 tf->tf_arg2 = (__greg_t)&fp->sf_uc;
216 tf->tf_r3 = (__greg_t)&fp->sf_uc;
217
218 tf->tf_iisq_head = tf->tf_iisq_tail = l->l_addr->u_pcb.pcb_space;
219 tf->tf_iioq_head =
220 (__greg_t)ps->sa_sigdesc[sig].sd_tramp | HPPA_PC_PRIV_USER;
221 tf->tf_iioq_tail = tf->tf_iioq_head + 4;
222 tf->tf_arg3 = (__greg_t)catcher;
223 tf->tf_sp = HPPA_FRAME_ROUND((uintptr_t)fp + sizeof(*fp) +
224 HPPA_FRAME_SIZE);
225
226 /* Remember that we're now on the signal stack. */
227 if (onstack)
228 p->p_sigctx.ps_sigstk.ss_flags |= SS_ONSTACK;
229 }
230