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