Module Name: src
Committed By: mrg
Date: Mon Dec 14 07:13:31 UTC 2009
Modified Files:
src/sys/arch/mips/mips [matt-nb5-mips64]: cpu_exec.c
src/sys/compat/common [matt-nb5-mips64]: compat_util.c compat_util.h
src/sys/compat/netbsd32 [matt-nb5-mips64]: netbsd32_exec_elf32.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.50.54.1.4.10 -r1.50.54.1.4.11 \
src/sys/arch/mips/mips/cpu_exec.c
cvs rdiff -u -r1.41 -r1.41.18.1 src/sys/compat/common/compat_util.c
cvs rdiff -u -r1.20 -r1.20.14.1 src/sys/compat/common/compat_util.h
cvs rdiff -u -r1.29.14.1 -r1.29.14.2 \
src/sys/compat/netbsd32/netbsd32_exec_elf32.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/mips/mips/cpu_exec.c
diff -u src/sys/arch/mips/mips/cpu_exec.c:1.50.54.1.4.10 src/sys/arch/mips/mips/cpu_exec.c:1.50.54.1.4.11
--- src/sys/arch/mips/mips/cpu_exec.c:1.50.54.1.4.10 Tue Dec 8 02:21:16 2009
+++ src/sys/arch/mips/mips/cpu_exec.c Mon Dec 14 07:13:31 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_exec.c,v 1.50.54.1.4.10 2009/12/08 02:21:16 mrg Exp $ */
+/* $NetBSD: cpu_exec.c,v 1.50.54.1.4.11 2009/12/14 07:13:31 mrg Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu_exec.c,v 1.50.54.1.4.10 2009/12/08 02:21:16 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_exec.c,v 1.50.54.1.4.11 2009/12/14 07:13:31 mrg Exp $");
#include "opt_compat_netbsd.h"
#include "opt_compat_ultrix.h"
@@ -62,6 +62,8 @@
#include <machine/reg.h>
#include <mips/regnum.h> /* symbolic register indices */
+#include <compat/common/compat_util.h>
+
int mips_elf_makecmds(struct lwp *, struct exec_package *);
@@ -310,42 +312,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,
@@ -407,7 +373,8 @@
return ENOEXEC;
}
- return elf_check_itp(epp, itp, itp_suffix);
+ (void)compat_elf_check_interp(epp, itp, itp_suffix);
+ return 0;
}
void
@@ -500,7 +467,8 @@
return ENOEXEC;
}
- return elf_check_itp(epp, itp, itp_suffix);
+ (void)compat_elf_check_interp(epp, itp, itp_suffix);
+ return 0;
}
void
Index: src/sys/compat/common/compat_util.c
diff -u src/sys/compat/common/compat_util.c:1.41 src/sys/compat/common/compat_util.c:1.41.18.1
--- src/sys/compat/common/compat_util.c:1.41 Mon Apr 28 20:23:41 2008
+++ src/sys/compat/common/compat_util.c Mon Dec 14 07:13:31 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: compat_util.c,v 1.41 2008/04/28 20:23:41 martin Exp $ */
+/* $NetBSD: compat_util.c,v 1.41.18.1 2009/12/14 07:13:31 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.41 2008/04/28 20:23:41 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: compat_util.c,v 1.41.18.1 2009/12/14 07:13:31 mrg Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -148,3 +176,49 @@
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.
+ */
+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 nameidata nd;
+ char *path;
+
+ path = PNBUF_GET();
+ snprintf(path, MAXPATHLEN, "%s-%s", interp, interp_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) {
+ epp->ep_interp = nd.ni_vp;
+ snprintf(interp, MAXPATHLEN, "%s", path);
+ }
+ PNBUF_PUT(path);
+ }
+ }
+ return error;
+}
Index: src/sys/compat/common/compat_util.h
diff -u src/sys/compat/common/compat_util.h:1.20 src/sys/compat/common/compat_util.h:1.20.14.1
--- src/sys/compat/common/compat_util.h:1.20 Mon Apr 28 20:23:41 2008
+++ src/sys/compat/common/compat_util.h Mon Dec 14 07:13:31 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: compat_util.h,v 1.20 2008/04/28 20:23:41 martin Exp $ */
+/* $NetBSD: compat_util.h,v 1.20.14.1 2009/12/14 07:13:31 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,4 +80,6 @@
void compat_offseterr(struct vnode *, const char *);
+int compat_elf_check_interp(struct exec_package *, char *, const char *);
+
#endif /* !_COMPAT_UTIL_H_ */
Index: src/sys/compat/netbsd32/netbsd32_exec_elf32.c
diff -u src/sys/compat/netbsd32/netbsd32_exec_elf32.c:1.29.14.1 src/sys/compat/netbsd32/netbsd32_exec_elf32.c:1.29.14.2
--- src/sys/compat/netbsd32/netbsd32_exec_elf32.c:1.29.14.1 Sat Sep 12 17:45:08 2009
+++ src/sys/compat/netbsd32/netbsd32_exec_elf32.c Mon Dec 14 07:13:31 2009
@@ -1,8 +1,8 @@
-/* $NetBSD: netbsd32_exec_elf32.c,v 1.29.14.1 2009/09/12 17:45:08 matt Exp $ */
+/* $NetBSD: netbsd32_exec_elf32.c,v 1.29.14.2 2009/12/14 07:13:31 mrg Exp $ */
/* from: NetBSD: exec_aout.c,v 1.15 1996/09/26 23:34:46 cgd Exp */
/*
- * Copyright (c) 1998, 2001 Matthew R. Green.
+ * Copyright (c) 1998, 2001, 2008 Matthew R. Green.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -57,7 +57,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_exec_elf32.c,v 1.29.14.1 2009/09/12 17:45:08 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_exec_elf32.c,v 1.29.14.2 2009/12/14 07:13:31 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,11 @@
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 nameidata nd;
- char *path;
-
- if (epp->ep_interp != NULL)
- vrele(epp->ep_interp);
-
- path = PNBUF_GET();
- snprintf(path, MAXPATHLEN, "%s-%s", itp, machine32);
- NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, path);
- error = namei(&nd);
- /*
- * If that worked, save interpreter in case we
- * actually need to load it
- */
- if (error != 0)
- epp->ep_interp = NULL;
- else
- epp->ep_interp = nd.ni_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;