Mon Dec 14 04:09:38 2009 UTC ()
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.58 -r1.59 src/sys/arch/mips/mips/cpu_exec.c
diff -r1.42 -r1.43 src/sys/compat/common/compat_util.c
diff -r1.21 -r1.22 src/sys/compat/common/compat_util.h
diff -r1.31 -r1.32 src/sys/compat/netbsd32/netbsd32_exec_elf32.c
--- src/sys/arch/mips/mips/cpu_exec.c 2009/12/14 00:46:05 1.58
+++ src/sys/arch/mips/mips/cpu_exec.c 2009/12/14 04:09:38 1.59
@@ -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 @@
#include <uvm/uvm_extern.h>
+#include <compat/common/compat_util.h>
+
#ifdef EXEC_ECOFF
#include <sys/exec_ecoff.h>
#endif
@@ -241,42 +243,6 @@
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 @@
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 @@
return ENOEXEC;
}
- return elf_check_itp(epp, itp, itp_suffix);
+ (void)compat_elf_check_interp(epp, itp, itp_suffix);
+ return 0;
}
void
--- src/sys/compat/common/compat_util.c 2009/06/29 05:08:15 1.42
+++ src/sys/compat/common/compat_util.c 2009/12/14 04:09:38 1.43
@@ -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>
@@ -146,4 +174,50 @@
log(LOG_ERR, "%s: dir offset too large on fs %s (mounted from %s)\n",
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;
}
--- src/sys/compat/common/compat_util.h 2008/11/19 18:36:02 1.21
+++ src/sys/compat/common/compat_util.h 2009/12/14 04:09:38 1.22
@@ -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
@@ -78,6 +79,8 @@
unsigned long in, unsigned long *leftover);
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);
--- src/sys/compat/netbsd32/netbsd32_exec_elf32.c 2009/12/14 00:47:11 1.31
+++ src/sys/compat/netbsd32/netbsd32_exec_elf32.c 2009/12/14 04:09:38 1.32
@@ -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 @@
#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 @@
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;