Thu Apr 23 16:16:15 2020 UTC ()
use shortcut variables for readability.


(christos)
diff -r1.133 -r1.134 src/sys/arch/amd64/amd64/netbsd32_machdep.c

cvs diff -r1.133 -r1.134 src/sys/arch/amd64/amd64/netbsd32_machdep.c (expand / switch to unified diff)

--- src/sys/arch/amd64/amd64/netbsd32_machdep.c 2019/12/12 02:15:42 1.133
+++ src/sys/arch/amd64/amd64/netbsd32_machdep.c 2020/04/23 16:16:14 1.134
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: netbsd32_machdep.c,v 1.133 2019/12/12 02:15:42 pgoyette Exp $ */ 1/* $NetBSD: netbsd32_machdep.c,v 1.134 2020/04/23 16:16:14 christos Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2001 Wasabi Systems, Inc. 4 * Copyright (c) 2001 Wasabi Systems, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Written by Frank van der Linden for Wasabi Systems, Inc. 7 * Written by Frank van der Linden for Wasabi Systems, Inc.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -26,27 +26,27 @@ @@ -26,27 +26,27 @@
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE. 35 * POSSIBILITY OF SUCH DAMAGE.
36 */ 36 */
37 37
38#include <sys/cdefs.h> 38#include <sys/cdefs.h>
39__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.133 2019/12/12 02:15:42 pgoyette Exp $"); 39__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.134 2020/04/23 16:16:14 christos Exp $");
40 40
41#ifdef _KERNEL_OPT 41#ifdef _KERNEL_OPT
42#include "opt_compat_netbsd.h" 42#include "opt_compat_netbsd.h"
43#include "opt_compat_netbsd32.h" 43#include "opt_compat_netbsd32.h"
44#include "opt_execfmt.h" 44#include "opt_execfmt.h"
45#include "opt_user_ldt.h" 45#include "opt_user_ldt.h"
46#include "opt_mtrr.h" 46#include "opt_mtrr.h"
47#endif 47#endif
48 48
49#include <sys/param.h> 49#include <sys/param.h>
50#include <sys/exec.h> 50#include <sys/exec.h>
51#include <sys/exec_aout.h> 51#include <sys/exec_aout.h>
52#include <sys/kmem.h> 52#include <sys/kmem.h>
@@ -204,65 +204,67 @@ netbsd32_buildcontext(struct lwp *l, str @@ -204,65 +204,67 @@ netbsd32_buildcontext(struct lwp *l, str
204 /* NOTREACHED */ 204 /* NOTREACHED */
205 } 205 }
206} 206}
207 207
208int 208int
209netbsd32_sendsig_siginfo(const ksiginfo_t *ksi, const sigset_t *mask) 209netbsd32_sendsig_siginfo(const ksiginfo_t *ksi, const sigset_t *mask)
210{ 210{
211 struct lwp *l = curlwp; 211 struct lwp *l = curlwp;
212 struct proc *p = l->l_proc; 212 struct proc *p = l->l_proc;
213 struct sigacts *ps = p->p_sigacts; 213 struct sigacts *ps = p->p_sigacts;
214 int onstack, error; 214 int onstack, error;
215 int sig = ksi->ksi_signo; 215 int sig = ksi->ksi_signo;
216 struct netbsd32_sigframe_siginfo *fp, frame; 216 struct netbsd32_sigframe_siginfo *fp, frame;
217 sig_t catcher = SIGACTION(p, sig).sa_handler; 217 const struct sigaction *sa = &SIGACTION(p, sig);
 218 sig_t catcher = sa->sa_handler;
218 struct trapframe *tf = l->l_md.md_regs; 219 struct trapframe *tf = l->l_md.md_regs;
 220 struct sigaltstack * const ss = &l->l_sigstk;
219 221
220 /* Do we need to jump onto the signal stack? */ 222 /* Do we need to jump onto the signal stack? */
221 onstack = 223 onstack =
222 (l->l_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 && 224 (ss->ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 &&
223 (SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0; 225 (sa->sa_flags & SA_ONSTACK) != 0;
224 226
225 /* Allocate space for the signal handler context. */ 227 /* Allocate space for the signal handler context. */
226 if (onstack) 228 if (onstack)
227 fp = (struct netbsd32_sigframe_siginfo *) 229 fp = (struct netbsd32_sigframe_siginfo *)
228 ((char *)l->l_sigstk.ss_sp + l->l_sigstk.ss_size); 230 ((char *)ss->ss_sp + ss->ss_size);
229 else 231 else
230 fp = (struct netbsd32_sigframe_siginfo *)tf->tf_rsp; 232 fp = (struct netbsd32_sigframe_siginfo *)tf->tf_rsp;
231 233
232 fp--; 234 fp--;
233 235
234 /* Build stack frame for signal trampoline. */ 236 /* Build stack frame for signal trampoline. */
235 switch (ps->sa_sigdesc[sig].sd_vers) { 237 switch (ps->sa_sigdesc[sig].sd_vers) {
236 case 0: /* handled by sendsig_sigcontext */ 238 case 0: /* handled by sendsig_sigcontext */
237 case 1: /* handled by sendsig_sigcontext */ 239 case 1: /* handled by sendsig_sigcontext */
238 default: /* unknown version */ 240 default: /* unknown version */
239 printf("nsendsig: bad version %d\n", 241 printf("nsendsig: bad version %d\n",
240 ps->sa_sigdesc[sig].sd_vers); 242 ps->sa_sigdesc[sig].sd_vers);
241 sigexit(l, SIGILL); 243 sigexit(l, SIGILL);
242 case 2: 244 case 2:
243 break; 245 break;
244 } 246 }
245 247
246 memset(&frame, 0, sizeof(frame)); 248 memset(&frame, 0, sizeof(frame));
247 frame.sf_ra = (uint32_t)(uintptr_t)ps->sa_sigdesc[sig].sd_tramp; 249 frame.sf_ra = (uint32_t)(uintptr_t)ps->sa_sigdesc[sig].sd_tramp;
248 frame.sf_signum = sig; 250 frame.sf_signum = sig;
249 frame.sf_sip = (uint32_t)(uintptr_t)&fp->sf_si; 251 frame.sf_sip = (uint32_t)(uintptr_t)&fp->sf_si;
250 frame.sf_ucp = (uint32_t)(uintptr_t)&fp->sf_uc; 252 frame.sf_ucp = (uint32_t)(uintptr_t)&fp->sf_uc;
251 netbsd32_si_to_si32(&frame.sf_si, (const siginfo_t *)&ksi->ksi_info); 253 netbsd32_si_to_si32(&frame.sf_si, (const siginfo_t *)&ksi->ksi_info);
252 frame.sf_uc.uc_flags = _UC_SIGMASK; 254 frame.sf_uc.uc_flags = _UC_SIGMASK;
253 frame.sf_uc.uc_sigmask = *mask; 255 frame.sf_uc.uc_sigmask = *mask;
254 frame.sf_uc.uc_link = (uint32_t)(uintptr_t)l->l_ctxlink; 256 frame.sf_uc.uc_link = (uint32_t)(uintptr_t)l->l_ctxlink;
255 frame.sf_uc.uc_flags |= (l->l_sigstk.ss_flags & SS_ONSTACK) 257 frame.sf_uc.uc_flags |= (ss->ss_flags & SS_ONSTACK)
256 ? _UC_SETSTACK : _UC_CLRSTACK; 258 ? _UC_SETSTACK : _UC_CLRSTACK;
257 sendsig_reset(l, sig); 259 sendsig_reset(l, sig);
258 260
259 mutex_exit(p->p_lock); 261 mutex_exit(p->p_lock);
260 cpu_getmcontext32(l, &frame.sf_uc.uc_mcontext, &frame.sf_uc.uc_flags); 262 cpu_getmcontext32(l, &frame.sf_uc.uc_mcontext, &frame.sf_uc.uc_flags);
261 error = copyout(&frame, fp, sizeof(frame)); 263 error = copyout(&frame, fp, sizeof(frame));
262 mutex_enter(p->p_lock); 264 mutex_enter(p->p_lock);
263 265
264 if (error != 0) { 266 if (error != 0) {
265 /* 267 /*
266 * Process has trashed its stack; give it an illegal 268 * Process has trashed its stack; give it an illegal
267 * instruction to halt it in its tracks. 269 * instruction to halt it in its tracks.
268 */ 270 */