Mon Dec 14 07:13:31 2009 UTC ()
pullup from -current:
>replace mips:elf_check_itp() and ELFNAME2(netbsd32,probe_noteless) that
>it's based upon with a common compat_elf_check_interp().
>
>tested on MALTA64 and sparc64.


(mrg)
diff -r1.50.54.1.4.10 -r1.50.54.1.4.11 src/sys/arch/mips/mips/cpu_exec.c
diff -r1.41 -r1.41.18.1 src/sys/compat/common/compat_util.c
diff -r1.20 -r1.20.14.1 src/sys/compat/common/compat_util.h
diff -r1.29.14.1 -r1.29.14.2 src/sys/compat/netbsd32/netbsd32_exec_elf32.c

cvs diff -r1.50.54.1.4.10 -r1.50.54.1.4.11 src/sys/arch/mips/mips/cpu_exec.c (expand / switch to unified diff)

--- src/sys/arch/mips/mips/cpu_exec.c 2009/12/08 02:21:16 1.50.54.1.4.10
+++ src/sys/arch/mips/mips/cpu_exec.c 2009/12/14 07:13:31 1.50.54.1.4.11
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: cpu_exec.c,v 1.50.54.1.4.10 2009/12/08 02:21:16 mrg Exp $ */ 1/* $NetBSD: cpu_exec.c,v 1.50.54.1.4.11 2009/12/14 07:13:31 mrg Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1992, 1993 4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by Ralph 7 * This code is derived from software contributed to Berkeley by Ralph
8 * Campbell. 8 * Campbell.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -25,53 +25,55 @@ @@ -25,53 +25,55 @@
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE. 32 * SUCH DAMAGE.
33 * 33 *
34 * @(#)machdep.c 8.3 (Berkeley) 1/12/94 34 * @(#)machdep.c 8.3 (Berkeley) 1/12/94
35 */ 35 */
36 36
37#include <sys/cdefs.h> 37#include <sys/cdefs.h>
38__KERNEL_RCSID(0, "$NetBSD: cpu_exec.c,v 1.50.54.1.4.10 2009/12/08 02:21:16 mrg Exp $"); 38__KERNEL_RCSID(0, "$NetBSD: cpu_exec.c,v 1.50.54.1.4.11 2009/12/14 07:13:31 mrg Exp $");
39 39
40#include "opt_compat_netbsd.h" 40#include "opt_compat_netbsd.h"
41#include "opt_compat_ultrix.h" 41#include "opt_compat_ultrix.h"
42#include "opt_execfmt.h" 42#include "opt_execfmt.h"
43 43
44#include <sys/param.h> 44#include <sys/param.h>
45#include <sys/systm.h> 45#include <sys/systm.h>
46#include <sys/proc.h> 46#include <sys/proc.h>
47#include <sys/malloc.h> 47#include <sys/malloc.h>
48#include <sys/vnode.h> 48#include <sys/vnode.h>
49#include <sys/exec.h> 49#include <sys/exec.h>
50#include <sys/namei.h> 50#include <sys/namei.h>
51#include <sys/resourcevar.h> 51#include <sys/resourcevar.h>
52 52
53#include <uvm/uvm_extern.h> 53#include <uvm/uvm_extern.h>
54 54
55#ifdef EXEC_ECOFF 55#ifdef EXEC_ECOFF
56#include <sys/exec_ecoff.h> 56#include <sys/exec_ecoff.h>
57#endif 57#endif
58#include <sys/exec_elf.h> /* mandatory */ 58#include <sys/exec_elf.h> /* mandatory */
59#ifdef COMPAT_09 59#ifdef COMPAT_09
60#include <machine/bsd-aout.h> 60#include <machine/bsd-aout.h>
61#endif 61#endif
62#include <machine/reg.h> 62#include <machine/reg.h>
63#include <mips/regnum.h> /* symbolic register indices */ 63#include <mips/regnum.h> /* symbolic register indices */
64 64
 65#include <compat/common/compat_util.h>
 66
65int mips_elf_makecmds(struct lwp *, struct exec_package *); 67int mips_elf_makecmds(struct lwp *, struct exec_package *);
66 68
67 69
68/* 70/*
69 * cpu_exec_aout_makecmds(): 71 * cpu_exec_aout_makecmds():
70 * cpu-dependent a.out format hook for execve(). 72 * cpu-dependent a.out format hook for execve().
71 * 73 *
72 * Determine of the given exec package refers to something which we 74 * Determine of the given exec package refers to something which we
73 * understand and, if so, set up the vmcmds for it. 75 * understand and, if so, set up the vmcmds for it.
74 * 76 *
75 */ 77 */
76int 78int
77cpu_exec_aout_makecmds(l, epp) 79cpu_exec_aout_makecmds(l, epp)
@@ -300,62 +302,26 @@ mips_elf_makecmds (l, epp) @@ -300,62 +302,26 @@ mips_elf_makecmds (l, epp)
300 * note that in memory, things assumed to be: 0 ....... ep_maxsaddr 302 * note that in memory, things assumed to be: 0 ....... ep_maxsaddr
301 * <stack> ep_minsaddr 303 * <stack> ep_minsaddr
302 */ 304 */
303 NEW_VMCMD2(&epp->ep_vmcmds, vmcmd_map_zero, 305 NEW_VMCMD2(&epp->ep_vmcmds, vmcmd_map_zero,
304 ((epp->ep_minsaddr - epp->ep_ssize) - epp->ep_maxsaddr), 306 ((epp->ep_minsaddr - epp->ep_ssize) - epp->ep_maxsaddr),
305 epp->ep_maxsaddr, NULLVP, 0, VM_PROT_NONE, VMCMD_STACK); 307 epp->ep_maxsaddr, NULLVP, 0, VM_PROT_NONE, VMCMD_STACK);
306 NEW_VMCMD2(&epp->ep_vmcmds, vmcmd_map_zero, epp->ep_ssize, 308 NEW_VMCMD2(&epp->ep_vmcmds, vmcmd_map_zero, epp->ep_ssize,
307 (epp->ep_minsaddr - epp->ep_ssize), NULLVP, 0, 309 (epp->ep_minsaddr - epp->ep_ssize), NULLVP, 0,
308 VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE, VMCMD_STACK); 310 VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE, VMCMD_STACK);
309 311
310 return 0; 312 return 0;
311} 313}
312 314
313static int 
314elf_check_itp(struct exec_package *epp, const char *itp, 
315 const char *itp_suffix) 
316{ 
317 if (itp) { 
318 /* 
319 * If the path is exactly "/usr/libexec/ld.elf_so", first 
320 * try to see if "/usr/libexec/ld.elf_so-<abi>" exists 
321 * and if so, use that instead. 
322 * XXX maybe move this into compat/common 
323 */ 
324 if (strcmp(itp, "/usr/libexec/ld.elf_so") == 0 || 
325 strcmp(itp, "/libexec/ld.elf_so") == 0) { 
326 struct nameidata nd; 
327 char *path; 
328 int error; 
329 
330 path = PNBUF_GET(); 
331 snprintf(path, MAXPATHLEN, "%s-%s", itp, itp_suffix); 
332 NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, path); 
333 error = namei(&nd); 
334 /* 
335 * If that worked, replace interpreter in case we 
336 * actually need to load it 
337 */ 
338 if (error == 0) { 
339 if (epp->ep_interp != NULL) 
340 vrele(epp->ep_interp); 
341 epp->ep_interp = nd.ni_vp; 
342 } 
343 PNBUF_PUT(path); 
344 } 
345 } 
346 return 0; 
347} 
348 
349#if EXEC_ELF32 315#if EXEC_ELF32
350int 316int
351mips_netbsd_elf32_probe(struct lwp *l, struct exec_package *epp, void *eh0, 317mips_netbsd_elf32_probe(struct lwp *l, struct exec_package *epp, void *eh0,
352 char *itp, vaddr_t *start_p) 318 char *itp, vaddr_t *start_p)
353{ 319{
354 struct proc * const p = l->l_proc; 320 struct proc * const p = l->l_proc;
355 const Elf32_Ehdr * const eh = eh0; 321 const Elf32_Ehdr * const eh = eh0;
356 int old_abi = p->p_md.md_abi; 322 int old_abi = p->p_md.md_abi;
357 const char *itp_suffix = NULL; 323 const char *itp_suffix = NULL;
358 324
359 /* 325 /*
360 * Verify we can support the architecture. 326 * Verify we can support the architecture.
361 */ 327 */
@@ -397,27 +363,28 @@ mips_netbsd_elf32_probe(struct lwp *l, s @@ -397,27 +363,28 @@ mips_netbsd_elf32_probe(struct lwp *l, s
397 case EF_MIPS_ABI_O32: 363 case EF_MIPS_ABI_O32:
398 itp_suffix = "o32"; 364 itp_suffix = "o32";
399 p->p_md.md_abi = _MIPS_BSD_API_O32; 365 p->p_md.md_abi = _MIPS_BSD_API_O32;
400#ifdef COMPAT_16 366#ifdef COMPAT_16
401 *start_p = ELF32_LINK_ADDR; 367 *start_p = ELF32_LINK_ADDR;
402#endif 368#endif
403 if (old_abi != p->p_md.md_abi) 369 if (old_abi != p->p_md.md_abi)
404 printf("pid %d(%s): ABI set to O32 (e_flags=%#x)\n", p->p_pid, p->p_comm, eh->e_flags); 370 printf("pid %d(%s): ABI set to O32 (e_flags=%#x)\n", p->p_pid, p->p_comm, eh->e_flags);
405 break; 371 break;
406 default: 372 default:
407 return ENOEXEC; 373 return ENOEXEC;
408 } 374 }
409 375
410 return elf_check_itp(epp, itp, itp_suffix); 376 (void)compat_elf_check_interp(epp, itp, itp_suffix);
 377 return 0;
411} 378}
412 379
413void 380void
414coredump_elf32_setup(struct lwp *l, void *eh0) 381coredump_elf32_setup(struct lwp *l, void *eh0)
415{ 382{
416 struct proc * const p = l->l_proc; 383 struct proc * const p = l->l_proc;
417 Elf32_Ehdr * const eh = eh0; 384 Elf32_Ehdr * const eh = eh0;
418 385
419 /* 386 /*
420 * Mark the type of CPU that the dump happened on. 387 * Mark the type of CPU that the dump happened on.
421 */ 388 */
422 if (cpu_arch & CPU_ARCH_MIPS64) { 389 if (cpu_arch & CPU_ARCH_MIPS64) {
423 eh->e_flags |= EF_MIPS_ARCH_64; 390 eh->e_flags |= EF_MIPS_ARCH_64;
@@ -490,27 +457,28 @@ mips_netbsd_elf64_probe(struct lwp *l, s @@ -490,27 +457,28 @@ mips_netbsd_elf64_probe(struct lwp *l, s
490 if (old_abi != p->p_md.md_abi) 457 if (old_abi != p->p_md.md_abi)
491 printf("pid %d(%s): ABI set to N64 (e_flags=%#x)\n", p->p_pid, p->p_comm, eh->e_flags); 458 printf("pid %d(%s): ABI set to N64 (e_flags=%#x)\n", p->p_pid, p->p_comm, eh->e_flags);
492 break; 459 break;
493 case EF_MIPS_ABI_O64: 460 case EF_MIPS_ABI_O64:
494 itp_suffix = "o64"; 461 itp_suffix = "o64";
495 p->p_md.md_abi = _MIPS_BSD_API_O64; 462 p->p_md.md_abi = _MIPS_BSD_API_O64;
496 if (old_abi != p->p_md.md_abi) 463 if (old_abi != p->p_md.md_abi)
497 printf("pid %d(%s): ABI set to O64 (e_flags=%#x)\n", p->p_pid, p->p_comm, eh->e_flags); 464 printf("pid %d(%s): ABI set to O64 (e_flags=%#x)\n", p->p_pid, p->p_comm, eh->e_flags);
498 break; 465 break;
499 default: 466 default:
500 return ENOEXEC; 467 return ENOEXEC;
501 } 468 }
502 469
503 return elf_check_itp(epp, itp, itp_suffix); 470 (void)compat_elf_check_interp(epp, itp, itp_suffix);
 471 return 0;
504} 472}
505 473
506void 474void
507coredump_elf64_setup(struct lwp *l, void *eh0) 475coredump_elf64_setup(struct lwp *l, void *eh0)
508{ 476{
509 struct proc * const p = l->l_proc; 477 struct proc * const p = l->l_proc;
510 Elf64_Ehdr * const eh = eh0; 478 Elf64_Ehdr * const eh = eh0;
511 479
512 /* 480 /*
513 * Mark the type of CPU that the dump happened on. 481 * Mark the type of CPU that the dump happened on.
514 */ 482 */
515 if (cpu_arch & CPU_ARCH_MIPS64) { 483 if (cpu_arch & CPU_ARCH_MIPS64) {
516 eh->e_flags |= EF_MIPS_ARCH_64; 484 eh->e_flags |= EF_MIPS_ARCH_64;

cvs diff -r1.41 -r1.41.18.1 src/sys/compat/common/compat_util.c (expand / switch to unified diff)

--- src/sys/compat/common/compat_util.c 2008/04/28 20:23:41 1.41
+++ src/sys/compat/common/compat_util.c 2009/12/14 07:13:31 1.41.18.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: compat_util.c,v 1.41 2008/04/28 20:23:41 martin Exp $ */ 1/* $NetBSD: compat_util.c,v 1.41.18.1 2009/12/14 07:13:31 mrg Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1994 The NetBSD Foundation, Inc. 4 * Copyright (c) 1994 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas and Frank van der Linden. 8 * by Christos Zoulas and Frank van der Linden.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -19,28 +19,56 @@ @@ -19,28 +19,56 @@
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 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 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 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 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 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
 32/*
 33 * Copyright (c) 2008, 2009 Matthew R. Green
 34 * All rights reserved.
 35 *
 36 * Redistribution and use in source and binary forms, with or without
 37 * modification, are permitted provided that the following conditions
 38 * are met:
 39 * 1. Redistributions of source code must retain the above copyright
 40 * notice, this list of conditions and the following disclaimer.
 41 * 2. Redistributions in binary form must reproduce the above copyright
 42 * notice, this list of conditions and the following disclaimer in the
 43 * documentation and/or other materials provided with the distribution.
 44 * 3. The name of the author may not be used to endorse or promote products
 45 * derived from this software without specific prior written permission.
 46 *
 47 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 48 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 49 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 50 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 51 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 52 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 53 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 54 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 55 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 57 * SUCH DAMAGE.
 58 */
 59
32#include <sys/cdefs.h> 60#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: compat_util.c,v 1.41 2008/04/28 20:23:41 martin Exp $"); 61__KERNEL_RCSID(0, "$NetBSD: compat_util.c,v 1.41.18.1 2009/12/14 07:13:31 mrg Exp $");
34 62
35#include <sys/param.h> 63#include <sys/param.h>
36#include <sys/systm.h> 64#include <sys/systm.h>
37#include <sys/namei.h> 65#include <sys/namei.h>
38#include <sys/proc.h> 66#include <sys/proc.h>
39#include <sys/file.h> 67#include <sys/file.h>
40#include <sys/stat.h> 68#include <sys/stat.h>
41#include <sys/filedesc.h> 69#include <sys/filedesc.h>
42#include <sys/exec.h> 70#include <sys/exec.h>
43#include <sys/ioctl.h> 71#include <sys/ioctl.h>
44#include <sys/kernel.h> 72#include <sys/kernel.h>
45#include <sys/malloc.h> 73#include <sys/malloc.h>
46#include <sys/vnode.h> 74#include <sys/vnode.h>
@@ -138,13 +166,59 @@ emul_flags_translate(const struct emul_f @@ -138,13 +166,59 @@ emul_flags_translate(const struct emul_f
138} 166}
139 167
140void 168void
141compat_offseterr(struct vnode *vp, const char *msg) 169compat_offseterr(struct vnode *vp, const char *msg)
142{ 170{
143 struct mount *mp; 171 struct mount *mp;
144 172
145 mp = vp->v_mount; 173 mp = vp->v_mount;
146 174
147 log(LOG_ERR, "%s: dir offset too large on fs %s (mounted from %s)\n", 175 log(LOG_ERR, "%s: dir offset too large on fs %s (mounted from %s)\n",
148 msg, mp->mnt_stat.f_mntonname, mp->mnt_stat.f_mntfromname); 176 msg, mp->mnt_stat.f_mntonname, mp->mnt_stat.f_mntfromname);
149 uprintf("%s: dir offset too large for emulated program\n", msg); 177 uprintf("%s: dir offset too large for emulated program\n", msg);
150} 178}
 179
 180/*
 181 * Look for native NetBSD compatibility libraries, usually interp-ABI.
 182 * It returns 0 if it changed the interpreter, otherwise it returns
 183 * the error from namei(). Callers should not try any more processing
 184 * if this returns 0.
 185 */
 186int
 187compat_elf_check_interp(struct exec_package *epp,
 188 char *interp,
 189 const char *interp_suffix)
 190{
 191 int error = 0;
 192
 193 /*
 194 * Don't look for something else, if someone has already found and
 195 * setup the ep_interp already.
 196 */
 197 if (interp && epp->ep_interp == NULL) {
 198 /*
 199 * If the path is exactly "/usr/libexec/ld.elf_so", first
 200 * try to see if "/usr/libexec/ld.elf_so-<abi>" exists
 201 * and if so, use that instead.
 202 */
 203 if (strcmp(interp, "/usr/libexec/ld.elf_so") == 0 ||
 204 strcmp(interp, "/libexec/ld.elf_so") == 0) {
 205 struct nameidata nd;
 206 char *path;
 207
 208 path = PNBUF_GET();
 209 snprintf(path, MAXPATHLEN, "%s-%s", interp, interp_suffix);
 210 NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, path);
 211 error = namei(&nd);
 212 /*
 213 * If that worked, replace interpreter in case we
 214 * actually need to load it
 215 */
 216 if (error == 0) {
 217 epp->ep_interp = nd.ni_vp;
 218 snprintf(interp, MAXPATHLEN, "%s", path);
 219 }
 220 PNBUF_PUT(path);
 221 }
 222 }
 223 return error;
 224}

cvs diff -r1.20 -r1.20.14.1 src/sys/compat/common/compat_util.h (expand / switch to unified diff)

--- src/sys/compat/common/compat_util.h 2008/04/28 20:23:41 1.20
+++ src/sys/compat/common/compat_util.h 2009/12/14 07:13:31 1.20.14.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: compat_util.h,v 1.20 2008/04/28 20:23:41 martin Exp $ */ 1/* $NetBSD: compat_util.h,v 1.20.14.1 2009/12/14 07:13:31 mrg Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1994 The NetBSD Foundation, Inc. 4 * Copyright (c) 1994 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas. 8 * by Christos Zoulas.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -21,26 +21,27 @@ @@ -21,26 +21,27 @@
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 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 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32/* 32/*
33 * Copyright (c) 1995 Frank van der Linden 33 * Copyright (c) 1995 Frank van der Linden
 34 * Copyright (c) 2009 Matthew R. Green
34 * All rights reserved. 35 * All rights reserved.
35 * 36 *
36 * Redistribution and use in source and binary forms, with or without 37 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions 38 * modification, are permitted provided that the following conditions
38 * are met: 39 * are met:
39 * 1. Redistributions of source code must retain the above copyright 40 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer. 41 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright 42 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the 43 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution. 44 * documentation and/or other materials provided with the distribution.
44 * 3. The name of the author may not be used to endorse or promote products 45 * 3. The name of the author may not be used to endorse or promote products
45 * derived from this software without specific prior written permission 46 * derived from this software without specific prior written permission
46 * 47 *
@@ -69,14 +70,16 @@ struct emul_flags_xtab { @@ -69,14 +70,16 @@ struct emul_flags_xtab {
69 unsigned long oval; 70 unsigned long oval;
70 unsigned long nval; 71 unsigned long nval;
71}; 72};
72 73
73void emul_find_root(struct lwp *, struct exec_package *); 74void emul_find_root(struct lwp *, struct exec_package *);
74 75
75int emul_find_interp(struct lwp *, struct exec_package *, const char *); 76int emul_find_interp(struct lwp *, struct exec_package *, const char *);
76 77
77unsigned long emul_flags_translate(const struct emul_flags_xtab *tab, 78unsigned long emul_flags_translate(const struct emul_flags_xtab *tab,
78 unsigned long in, unsigned long *leftover); 79 unsigned long in, unsigned long *leftover);
79 80
80void compat_offseterr(struct vnode *, const char *); 81void compat_offseterr(struct vnode *, const char *);
81 82
 83int compat_elf_check_interp(struct exec_package *, char *, const char *);
 84
82#endif /* !_COMPAT_UTIL_H_ */ 85#endif /* !_COMPAT_UTIL_H_ */

cvs diff -r1.29.14.1 -r1.29.14.2 src/sys/compat/netbsd32/netbsd32_exec_elf32.c (expand / switch to unified diff)

--- src/sys/compat/netbsd32/netbsd32_exec_elf32.c 2009/09/12 17:45:08 1.29.14.1
+++ src/sys/compat/netbsd32/netbsd32_exec_elf32.c 2009/12/14 07:13:31 1.29.14.2
@@ -1,18 +1,18 @@ @@ -1,18 +1,18 @@
1/* $NetBSD: netbsd32_exec_elf32.c,v 1.29.14.1 2009/09/12 17:45:08 matt Exp $ */ 1/* $NetBSD: netbsd32_exec_elf32.c,v 1.29.14.2 2009/12/14 07:13:31 mrg Exp $ */
2/* from: NetBSD: exec_aout.c,v 1.15 1996/09/26 23:34:46 cgd Exp */ 2/* from: NetBSD: exec_aout.c,v 1.15 1996/09/26 23:34:46 cgd Exp */
3 3
4/* 4/*
5 * Copyright (c) 1998, 2001 Matthew R. Green. 5 * Copyright (c) 1998, 2001, 2008 Matthew R. Green.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution. 15 * documentation and/or other materials provided with the distribution.
16 * 16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
@@ -47,43 +47,45 @@ @@ -47,43 +47,45 @@
47 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 47 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
48 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 48 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 49 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
50 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 50 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
51 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 51 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
52 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 52 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
53 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 53 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
54 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 54 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
55 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 55 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
56 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 56 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57 */ 57 */
58 58
59#include <sys/cdefs.h> 59#include <sys/cdefs.h>
60__KERNEL_RCSID(0, "$NetBSD: netbsd32_exec_elf32.c,v 1.29.14.1 2009/09/12 17:45:08 matt Exp $"); 60__KERNEL_RCSID(0, "$NetBSD: netbsd32_exec_elf32.c,v 1.29.14.2 2009/12/14 07:13:31 mrg Exp $");
61 61
62#define ELFSIZE 32 62#define ELFSIZE 32
63 63
64#include <sys/param.h> 64#include <sys/param.h>
65#include <sys/systm.h> 65#include <sys/systm.h>
66#include <sys/proc.h> 66#include <sys/proc.h>
67#include <sys/malloc.h> 67#include <sys/malloc.h>
68#include <sys/vnode.h> 68#include <sys/vnode.h>
69#include <sys/exec.h> 69#include <sys/exec.h>
70#include <sys/exec_elf.h> 70#include <sys/exec_elf.h>
71#include <sys/resourcevar.h> 71#include <sys/resourcevar.h>
72#include <sys/signal.h> 72#include <sys/signal.h>
73#include <sys/signalvar.h> 73#include <sys/signalvar.h>
74#include <sys/kauth.h> 74#include <sys/kauth.h>
75#include <sys/namei.h> 75#include <sys/namei.h>
76 76
 77#include <compat/common/compat_util.h>
 78
77#include <compat/netbsd32/netbsd32.h> 79#include <compat/netbsd32/netbsd32.h>
78#include <compat/netbsd32/netbsd32_exec.h> 80#include <compat/netbsd32/netbsd32_exec.h>
79 81
80#include <machine/netbsd32_machdep.h> 82#include <machine/netbsd32_machdep.h>
81 83
82int netbsd32_copyinargs(struct exec_package *, struct ps_strings *, 84int netbsd32_copyinargs(struct exec_package *, struct ps_strings *,
83 void *, size_t, const void *, const void *); 85 void *, size_t, const void *, const void *);
84int ELFNAME2(netbsd32,probe_noteless)(struct lwp *, struct exec_package *epp, 86int ELFNAME2(netbsd32,probe_noteless)(struct lwp *, struct exec_package *epp,
85 void *eh, char *itp, vaddr_t *pos); 87 void *eh, char *itp, vaddr_t *pos);
86extern int ELFNAME2(netbsd,signature)(struct lwp *, struct exec_package *, 88extern int ELFNAME2(netbsd,signature)(struct lwp *, struct exec_package *,
87 Elf_Ehdr *); 89 Elf_Ehdr *);
88 90
89int 91int
@@ -99,63 +101,31 @@ ELFNAME2(netbsd32,probe)(struct lwp *l,  @@ -99,63 +101,31 @@ ELFNAME2(netbsd32,probe)(struct lwp *l,
99 if ((error = ELF_MD_PROBE_FUNC(l, epp, eh, itp, pos)) != 0) 101 if ((error = ELF_MD_PROBE_FUNC(l, epp, eh, itp, pos)) != 0)
100 return error; 102 return error;
101#elif defined(ELF_INTERP_NON_RELOCATABLE) 103#elif defined(ELF_INTERP_NON_RELOCATABLE)
102 *pos = ELF_LINK_ADDR; 104 *pos = ELF_LINK_ADDR;
103#endif 105#endif
104 106
105 return ELFNAME2(netbsd32,probe_noteless)(l, epp, eh, itp, pos); 107 return ELFNAME2(netbsd32,probe_noteless)(l, epp, eh, itp, pos);
106} 108}
107 109
108int 110int
109ELFNAME2(netbsd32,probe_noteless)(struct lwp *l, struct exec_package *epp, 111ELFNAME2(netbsd32,probe_noteless)(struct lwp *l, struct exec_package *epp,
110 void *eh, char *itp, vaddr_t *pos) 112 void *eh, char *itp, vaddr_t *pos)
111{ 113{
112 int error; 
113 114
114 if (itp) { 115 if (itp && epp->ep_interp == NULL) {
115 /* 116 extern const char machine32[];
116 * If the path is exactly "/usr/libexec/ld.elf_so", first 117 (void)compat_elf_check_interp(epp, itp, machine32);
117 * try to see if "/usr/libexec/ld.elf_so-<arch>" exists 118
118 * and if so, use that instead. 
119 * XXX maybe move this into compat/common 
120 */ 
121 error = 0; 
122 if (strcmp(itp, "/usr/libexec/ld.elf_so") == 0 || 
123 strcmp(itp, "/libexec/ld.elf_so") == 0) { 
124 extern const char machine32[]; 
125 struct nameidata nd; 
126 char *path; 
127 
128 if (epp->ep_interp != NULL) 
129 vrele(epp->ep_interp); 
130  
131 path = PNBUF_GET(); 
132 snprintf(path, MAXPATHLEN, "%s-%s", itp, machine32); 
133 NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, path); 
134 error = namei(&nd); 
135 /* 
136 * If that worked, save interpreter in case we 
137 * actually need to load it 
138 */ 
139 if (error != 0) 
140 epp->ep_interp = NULL; 
141 else 
142 epp->ep_interp = nd.ni_vp; 
143 PNBUF_PUT(path); 
144 } 
145 
146 /* Translate interpreter name if needed */ 
147 if (error && (error = emul_find_interp(l, epp, itp)) != 0) 
148 return error; 
149 } 119 }
150 epp->ep_flags |= EXEC_32; 120 epp->ep_flags |= EXEC_32;
151 epp->ep_vm_minaddr = VM_MIN_ADDRESS; 121 epp->ep_vm_minaddr = VM_MIN_ADDRESS;
152 epp->ep_vm_maxaddr = USRSTACK32; 122 epp->ep_vm_maxaddr = USRSTACK32;
153#ifdef ELF_INTERP_NON_RELOCATABLE 123#ifdef ELF_INTERP_NON_RELOCATABLE
154 *pos = ELF_LINK_ADDR; 124 *pos = ELF_LINK_ADDR;
155#endif 125#endif
156 return 0; 126 return 0;
157} 127}
158 128
159/* round up and down to page boundaries. */ 129/* round up and down to page boundaries. */
160#define ELF_ROUND(a, b) (((a) + (b) - 1) & ~((b) - 1)) 130#define ELF_ROUND(a, b) (((a) + (b) - 1) & ~((b) - 1))
161#define ELF_TRUNC(a, b) ((a) & ~((b) - 1)) 131#define ELF_TRUNC(a, b) ((a) & ~((b) - 1))