Module Name: src
Committed By: pgoyette
Date: Wed Mar 7 09:33:26 UTC 2018
Modified Files:
src/sys/compat/common [pgoyette-compat]: compat_util.h
src/sys/kern [pgoyette-compat]: exec_elf.c files.kern
src/sys/sys [pgoyette-compat]: exec.h
Added Files:
src/sys/kern [pgoyette-compat]: subr_emul.c
Log Message:
Move the emul_find_root() and emul_find_interp() to a new file
subr_emul.c
The previous location was in exec_elf.c but that can get built
multiple times for a single kernel, so we could end up with
duplicate symbols.
Thanks to ,rg@ for the heads-up.
To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.23.36.1 src/sys/compat/common/compat_util.h
cvs rdiff -u -r1.93.2.1 -r1.93.2.2 src/sys/kern/exec_elf.c
cvs rdiff -u -r1.16.2.3 -r1.16.2.4 src/sys/kern/files.kern
cvs rdiff -u -r0 -r1.1.2.1 src/sys/kern/subr_emul.c
cvs rdiff -u -r1.152 -r1.152.2.1 src/sys/sys/exec.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/compat/common/compat_util.h
diff -u src/sys/compat/common/compat_util.h:1.23 src/sys/compat/common/compat_util.h:1.23.36.1
--- src/sys/compat/common/compat_util.h:1.23 Thu Feb 21 01:39:54 2013
+++ src/sys/compat/common/compat_util.h Wed Mar 7 09:33:26 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: compat_util.h,v 1.23 2013/02/21 01:39:54 pgoyette Exp $ */
+/* $NetBSD: compat_util.h,v 1.23.36.1 2018/03/07 09:33:26 pgoyette Exp $ */
/*-
* Copyright (c) 1994 The NetBSD Foundation, Inc.
@@ -71,10 +71,6 @@ struct emul_flags_xtab {
unsigned long nval;
};
-void emul_find_root(struct lwp *, struct exec_package *);
-
-int emul_find_interp(struct lwp *, struct exec_package *, const char *);
-
unsigned long emul_flags_translate(const struct emul_flags_xtab *tab,
unsigned long in, unsigned long *leftover);
Index: src/sys/kern/exec_elf.c
diff -u src/sys/kern/exec_elf.c:1.93.2.1 src/sys/kern/exec_elf.c:1.93.2.2
--- src/sys/kern/exec_elf.c:1.93.2.1 Tue Mar 6 10:37:41 2018
+++ src/sys/kern/exec_elf.c Wed Mar 7 09:33:26 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: exec_elf.c,v 1.93.2.1 2018/03/06 10:37:41 pgoyette Exp $ */
+/* $NetBSD: exec_elf.c,v 1.93.2.2 2018/03/07 09:33:26 pgoyette Exp $ */
/*-
* Copyright (c) 1994, 2000, 2005, 2015 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.93.2.1 2018/03/06 10:37:41 pgoyette Exp $");
+__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.93.2.2 2018/03/07 09:33:26 pgoyette Exp $");
#ifdef _KERNEL_OPT
#include "opt_pax.h"
@@ -1084,77 +1084,3 @@ elf_free_emul_arg(void *arg)
KASSERT(ap != NULL);
kmem_free(ap, sizeof(*ap));
}
-
-void
-emul_find_root(struct lwp *l, struct exec_package *epp)
-{
- struct vnode *vp;
- const char *emul_path;
-
- if (epp->ep_emul_root != NULL)
- /* We've already found it */
- return;
-
- emul_path = epp->ep_esch->es_emul->e_path;
- if (emul_path == NULL)
- /* Emulation doesn't have a root */
- return;
-
- if (namei_simple_kernel(emul_path, NSM_FOLLOW_NOEMULROOT, &vp) != 0)
- /* emulation root doesn't exist */
- return;
-
- epp->ep_emul_root = vp;
-}
-
-/*
- * Search the alternate path for dynamic binary interpreter. If not found
- * there, check if the interpreter exists in within 'proper' tree.
- */
-int
-emul_find_interp(struct lwp *l, struct exec_package *epp, const char *itp)
-{
- int error;
- struct pathbuf *pb;
- struct nameidata nd;
- unsigned int flags;
-
- pb = pathbuf_create(itp);
- if (pb == NULL) {
- return ENOMEM;
- }
-
- /* If we haven't found the emulation root already, do so now */
- /* Maybe we should remember failures somehow ? */
- if (epp->ep_esch->es_emul->e_path != 0 && epp->ep_emul_root == NULL)
- emul_find_root(l, epp);
-
- if (epp->ep_interp != NULL)
- vrele(epp->ep_interp);
-
- /* We need to use the emulation root for the new program,
- * not the one for the current process. */
- if (epp->ep_emul_root == NULL)
- flags = FOLLOW;
- else {
- nd.ni_erootdir = epp->ep_emul_root;
- /* hack: Pass in the emulation path for ktrace calls */
- nd.ni_next = epp->ep_esch->es_emul->e_path;
- flags = FOLLOW | TRYEMULROOT | EMULROOTSET;
- }
-
- NDINIT(&nd, LOOKUP, flags, pb);
- error = namei(&nd);
- if (error != 0) {
- epp->ep_interp = NULL;
- pathbuf_destroy(pb);
- return error;
- }
-
- /* Save interpreter in case we actually need to load it */
- epp->ep_interp = nd.ni_vp;
-
- pathbuf_destroy(pb);
-
- return 0;
-}
Index: src/sys/kern/files.kern
diff -u src/sys/kern/files.kern:1.16.2.3 src/sys/kern/files.kern:1.16.2.4
--- src/sys/kern/files.kern:1.16.2.3 Tue Mar 6 10:37:41 2018
+++ src/sys/kern/files.kern Wed Mar 7 09:33:26 2018
@@ -1,4 +1,4 @@
-# $NetBSD: files.kern,v 1.16.2.3 2018/03/06 10:37:41 pgoyette Exp $
+# $NetBSD: files.kern,v 1.16.2.4 2018/03/07 09:33:26 pgoyette Exp $
#
# kernel sources
@@ -103,6 +103,7 @@ file kern/subr_device.c kern
file kern/subr_devsw.c kern
file kern/subr_disk.c kern
file kern/subr_disk_open.c kern
+file kern/subr_emul.c kern
file kern/subr_evcnt.c kern
file kern/subr_exec_fd.c kern
file kern/subr_extent.c kern
Index: src/sys/sys/exec.h
diff -u src/sys/sys/exec.h:1.152 src/sys/sys/exec.h:1.152.2.1
--- src/sys/sys/exec.h:1.152 Tue Nov 7 19:44:05 2017
+++ src/sys/sys/exec.h Wed Mar 7 09:33:26 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: exec.h,v 1.152 2017/11/07 19:44:05 christos Exp $ */
+/* $NetBSD: exec.h,v 1.152.2.1 2018/03/07 09:33:26 pgoyette Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -314,6 +314,12 @@ int do_posix_spawn(struct lwp *, pid_t *
extern int maxexec;
+/*
+ * Utility functions
+ */
+void emul_find_root(struct lwp *, struct exec_package *);
+int emul_find_interp(struct lwp *, struct exec_package *, const char *);
+
#endif /* _KERNEL */
#endif /* !_SYS_EXEC_H_ */
Added files:
Index: src/sys/kern/subr_emul.c
diff -u /dev/null src/sys/kern/subr_emul.c:1.1.2.1
--- /dev/null Wed Mar 7 09:33:26 2018
+++ src/sys/kern/subr_emul.c Wed Mar 7 09:33:26 2018
@@ -0,0 +1,146 @@
+/* $NetBSD: subr_emul.c,v 1.1.2.1 2018/03/07 09:33:26 pgoyette Exp $ */
+
+/*-
+ * Copyright (c) 1994, 2000, 2005, 2015 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas and Maxime Villard.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 FOUNDATION OR CONTRIBUTORS
+ * 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.
+ */
+
+/*
+ * Copyright (c) 1996 Christopher G. Demetriou
+ * 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(1, "$NetBSD: subr_emul.c,v 1.1.2.1 2018/03/07 09:33:26 pgoyette Exp $");
+
+#ifdef _KERNEL_OPT
+#include "opt_pax.h"
+#endif /* _KERNEL_OPT */
+
+#include <sys/param.h>
+#include <sys/proc.h>
+#include <sys/vnode.h>
+#include <sys/namei.h>
+#include <sys/exec.h>
+
+#include <compat/common/compat_util.h>
+
+void
+emul_find_root(struct lwp *l, struct exec_package *epp)
+{
+ struct vnode *vp;
+ const char *emul_path;
+
+ if (epp->ep_emul_root != NULL)
+ /* We've already found it */
+ return;
+
+ emul_path = epp->ep_esch->es_emul->e_path;
+ if (emul_path == NULL)
+ /* Emulation doesn't have a root */
+ return;
+
+ if (namei_simple_kernel(emul_path, NSM_FOLLOW_NOEMULROOT, &vp) != 0)
+ /* emulation root doesn't exist */
+ return;
+
+ epp->ep_emul_root = vp;
+}
+
+/*
+ * Search the alternate path for dynamic binary interpreter. If not found
+ * there, check if the interpreter exists in within 'proper' tree.
+ */
+int
+emul_find_interp(struct lwp *l, struct exec_package *epp, const char *itp)
+{
+ int error;
+ struct pathbuf *pb;
+ struct nameidata nd;
+ unsigned int flags;
+
+ pb = pathbuf_create(itp);
+ if (pb == NULL) {
+ return ENOMEM;
+ }
+
+ /* If we haven't found the emulation root already, do so now */
+ /* Maybe we should remember failures somehow ? */
+ if (epp->ep_esch->es_emul->e_path != 0 && epp->ep_emul_root == NULL)
+ emul_find_root(l, epp);
+
+ if (epp->ep_interp != NULL)
+ vrele(epp->ep_interp);
+
+ /* We need to use the emulation root for the new program,
+ * not the one for the current process. */
+ if (epp->ep_emul_root == NULL)
+ flags = FOLLOW;
+ else {
+ nd.ni_erootdir = epp->ep_emul_root;
+ /* hack: Pass in the emulation path for ktrace calls */
+ nd.ni_next = epp->ep_esch->es_emul->e_path;
+ flags = FOLLOW | TRYEMULROOT | EMULROOTSET;
+ }
+
+ NDINIT(&nd, LOOKUP, flags, pb);
+ error = namei(&nd);
+ if (error != 0) {
+ epp->ep_interp = NULL;
+ pathbuf_destroy(pb);
+ return error;
+ }
+
+ /* Save interpreter in case we actually need to load it */
+ epp->ep_interp = nd.ni_vp;
+
+ pathbuf_destroy(pb);
+
+ return 0;
+}