diff options
| author | mrg <mrg@NetBSD.org> | 2009-12-14 04:09:38 +0000 |
|---|---|---|
| committer | mrg <mrg@NetBSD.org> | 2009-12-14 04:09:38 +0000 |
| commit | 97c80e8ff0971afb3c3efdd1d116a6e44c3f3df0 (patch) | |
| tree | 74c7db3adedef29ab9f9c43c80b0f5b7bf68ebdc | |
| parent | 10a5ee84956f4a4a635b7147fd5aceaeb3a6c47c (diff) | |
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.
| -rw-r--r-- | sys/arch/mips/mips/cpu_exec.c | 48 | ||||
| -rw-r--r-- | sys/compat/common/compat_util.c | 78 | ||||
| -rw-r--r-- | sys/compat/common/compat_util.h | 5 | ||||
| -rw-r--r-- | sys/compat/netbsd32/netbsd32_exec_elf32.c | 46 |
4 files changed, 95 insertions, 82 deletions
diff --git a/sys/arch/mips/mips/cpu_exec.c b/sys/arch/mips/mips/cpu_exec.c index d7ae120db93..e898b8d982b 100644 --- a/sys/arch/mips/mips/cpu_exec.c +++ b/sys/arch/mips/mips/cpu_exec.c @@ -1,4 +1,4 @@ -/* $NetBSD: cpu_exec.c,v 1.58 2009/12/14 00:46:05 matt Exp $ */ +/* $NetBSD: cpu_exec.c,v 1.59 2009/12/14 04:09:38 mrg Exp $ */ /* * Copyright (c) 1992, 1993 @@ -35,7 +35,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: cpu_exec.c,v 1.58 2009/12/14 00:46:05 matt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cpu_exec.c,v 1.59 2009/12/14 04:09:38 mrg Exp $"); #include "opt_compat_netbsd.h" #include "opt_compat_ultrix.h" @@ -52,6 +52,8 @@ __KERNEL_RCSID(0, "$NetBSD: cpu_exec.c,v 1.58 2009/12/14 00:46:05 matt Exp $"); #include <uvm/uvm_extern.h> +#include <compat/common/compat_util.h> + #ifdef EXEC_ECOFF #include <sys/exec_ecoff.h> #endif @@ -241,42 +243,6 @@ mips_elf_makecmds (struct lwp *l, struct exec_package *epp) return 0; } -static int -elf_check_itp(struct exec_package *epp, const char *itp, - const char *itp_suffix) -{ - if (itp) { - /* - * If the path is exactly "/usr/libexec/ld.elf_so", first - * try to see if "/usr/libexec/ld.elf_so-<abi>" exists - * and if so, use that instead. - * XXX maybe move this into compat/common - */ - if (strcmp(itp, "/usr/libexec/ld.elf_so") == 0 || - strcmp(itp, "/libexec/ld.elf_so") == 0) { - struct nameidata nd; - char *path; - int error; - - path = PNBUF_GET(); - snprintf(path, MAXPATHLEN, "%s-%s", itp, itp_suffix); - NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, path); - error = namei(&nd); - /* - * If that worked, replace interpreter in case we - * actually need to load it - */ - if (error == 0) { - if (epp->ep_interp != NULL) - vrele(epp->ep_interp); - epp->ep_interp = nd.ni_vp; - } - PNBUF_PUT(path); - } - } - return 0; -} - #if EXEC_ELF32 int mips_netbsd_elf32_probe(struct lwp *l, struct exec_package *epp, void *eh0, @@ -338,7 +304,8 @@ mips_netbsd_elf32_probe(struct lwp *l, struct exec_package *epp, void *eh0, return ENOEXEC; } - return elf_check_itp(epp, itp, itp_suffix); + (void)compat_elf_check_interp(epp, itp, itp_suffix); + return 0; } void @@ -431,7 +398,8 @@ mips_netbsd_elf64_probe(struct lwp *l, struct exec_package *epp, void *eh0, return ENOEXEC; } - return elf_check_itp(epp, itp, itp_suffix); + (void)compat_elf_check_interp(epp, itp, itp_suffix); + return 0; } void diff --git a/sys/compat/common/compat_util.c b/sys/compat/common/compat_util.c index 1ce134ff607..b1f0e43a85d 100644 --- a/sys/compat/common/compat_util.c +++ b/sys/compat/common/compat_util.c @@ -1,4 +1,4 @@ -/* $NetBSD: compat_util.c,v 1.42 2009/06/29 05:08:15 dholland Exp $ */ +/* $NetBSD: compat_util.c,v 1.43 2009/12/14 04:09:38 mrg Exp $ */ /*- * Copyright (c) 1994 The NetBSD Foundation, Inc. @@ -29,8 +29,36 @@ * POSSIBILITY OF SUCH DAMAGE. */ +/* + * Copyright (c) 2008, 2009 Matthew R. Green + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: compat_util.c,v 1.42 2009/06/29 05:08:15 dholland Exp $"); +__KERNEL_RCSID(0, "$NetBSD: compat_util.c,v 1.43 2009/12/14 04:09:38 mrg Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -147,3 +175,49 @@ compat_offseterr(struct vnode *vp, const char *msg) msg, mp->mnt_stat.f_mntonname, mp->mnt_stat.f_mntfromname); uprintf("%s: dir offset too large for emulated program\n", msg); } + +/* + * Look for native NetBSD compatibility libraries, usually interp-ABI. + * It returns 0 if it changed the interpreter, otherwise it returns + * the error from namei(). Callers should not try any more processing + * if this returns 0, and probably should just ignore the return value. + */ +int +compat_elf_check_interp(struct exec_package *epp, + char *interp, + const char *interp_suffix) +{ + int error = 0; + + /* + * Don't look for something else, if someone has already found and + * setup the ep_interp already. + */ + if (interp && epp->ep_interp == NULL) { + /* + * If the path is exactly "/usr/libexec/ld.elf_so", first + * try to see if "/usr/libexec/ld.elf_so-<abi>" exists + * and if so, use that instead. + */ + if (strcmp(interp, "/usr/libexec/ld.elf_so") == 0 || + strcmp(interp, "/libexec/ld.elf_so") == 0) { + struct vnode *vp; + char *path; + + path = PNBUF_GET(); + snprintf(path, MAXPATHLEN, "%s-%s", interp, interp_suffix); + error = namei_simple_kernel(path, + NSM_FOLLOW_NOEMULROOT, &vp); + /* + * If that worked, replace interpreter in case we + * actually need to load it. + */ + if (error == 0) { + epp->ep_interp = vp; + snprintf(interp, MAXPATHLEN, "%s", path); + } + PNBUF_PUT(path); + } + } + return error; +} diff --git a/sys/compat/common/compat_util.h b/sys/compat/common/compat_util.h index ba3c836c4ca..9d762809c5f 100644 --- a/sys/compat/common/compat_util.h +++ b/sys/compat/common/compat_util.h @@ -1,4 +1,4 @@ -/* $NetBSD: compat_util.h,v 1.21 2008/11/19 18:36:02 ad Exp $ */ +/* $NetBSD: compat_util.h,v 1.22 2009/12/14 04:09:38 mrg Exp $ */ /*- * Copyright (c) 1994 The NetBSD Foundation, Inc. @@ -31,6 +31,7 @@ /* * Copyright (c) 1995 Frank van der Linden + * Copyright (c) 2009 Matthew R. Green * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -79,6 +80,8 @@ unsigned long emul_flags_translate(const struct emul_flags_xtab *tab, void compat_offseterr(struct vnode *, const char *); +int compat_elf_check_interp(struct exec_package *, char *, const char *); + void compat_sysctl_init(void); void compat_sysctl_fini(void); diff --git a/sys/compat/netbsd32/netbsd32_exec_elf32.c b/sys/compat/netbsd32/netbsd32_exec_elf32.c index 91371207c3f..cadf22f0c00 100644 --- a/sys/compat/netbsd32/netbsd32_exec_elf32.c +++ b/sys/compat/netbsd32/netbsd32_exec_elf32.c @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_exec_elf32.c,v 1.31 2009/12/14 00:47:11 matt Exp $ */ +/* $NetBSD: netbsd32_exec_elf32.c,v 1.32 2009/12/14 04:09:38 mrg Exp $ */ /* from: NetBSD: exec_aout.c,v 1.15 1996/09/26 23:34:46 cgd Exp */ /* @@ -57,7 +57,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: netbsd32_exec_elf32.c,v 1.31 2009/12/14 00:47:11 matt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_exec_elf32.c,v 1.32 2009/12/14 04:09:38 mrg Exp $"); #define ELFSIZE 32 @@ -74,6 +74,8 @@ __KERNEL_RCSID(0, "$NetBSD: netbsd32_exec_elf32.c,v 1.31 2009/12/14 00:47:11 mat #include <sys/kauth.h> #include <sys/namei.h> +#include <compat/common/compat_util.h> + #include <compat/netbsd32/netbsd32.h> #include <compat/netbsd32/netbsd32_exec.h> @@ -109,43 +111,9 @@ int ELFNAME2(netbsd32,probe_noteless)(struct lwp *l, struct exec_package *epp, void *eh, char *itp, vaddr_t *pos) { - int error; - - if (itp) { - /* - * If the path is exactly "/usr/libexec/ld.elf_so", first - * try to see if "/usr/libexec/ld.elf_so-<arch>" exists - * and if so, use that instead. - * XXX maybe move this into compat/common - */ - error = 0; - if (strcmp(itp, "/usr/libexec/ld.elf_so") == 0 || - strcmp(itp, "/libexec/ld.elf_so") == 0) { - extern const char machine32[]; - struct vnode *vp; - char *path; - - if (epp->ep_interp != NULL) - vrele(epp->ep_interp); - - path = PNBUF_GET(); - snprintf(path, MAXPATHLEN, "%s-%s", itp, machine32); - error = namei_simple_kernel(path, - NSM_FOLLOW_NOEMULROOT, &vp); - /* - * If that worked, save interpreter in case we - * actually need to load it - */ - if (error != 0) - epp->ep_interp = NULL; - else - epp->ep_interp = vp; - PNBUF_PUT(path); - } - - /* Translate interpreter name if needed */ - if (error && (error = emul_find_interp(l, epp, itp)) != 0) - return error; + if (itp && epp->ep_interp == NULL) { + extern const char machine32[]; + (void)compat_elf_check_interp(epp, itp, machine32); } epp->ep_flags |= EXEC_32; epp->ep_vm_minaddr = VM_MIN_ADDRESS; |
