Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/pgoyette-compat]: src/sys Move the emul_find_root() and emul_find_interp...
details: https://anonhg.NetBSD.org/src/rev/8b193c9e82c2
branches: pgoyette-compat
changeset: 320969:8b193c9e82c2
user: pgoyette <pgoyette%NetBSD.org@localhost>
date: Wed Mar 07 09:33:26 2018 +0000
description:
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.
diffstat:
sys/compat/common/compat_util.h | 6 +-
sys/kern/exec_elf.c | 78 +--------------------
sys/kern/files.kern | 3 +-
sys/kern/subr_emul.c | 146 ++++++++++++++++++++++++++++++++++++++++
sys/sys/exec.h | 8 +-
5 files changed, 158 insertions(+), 83 deletions(-)
diffs (truncated from 305 to 300 lines):
diff -r 3a8a7fa86cf0 -r 8b193c9e82c2 sys/compat/common/compat_util.h
--- a/sys/compat/common/compat_util.h Wed Mar 07 08:56:44 2018 +0000
+++ b/sys/compat/common/compat_util.h Wed Mar 07 09:33:26 2018 +0000
@@ -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 @@
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);
diff -r 3a8a7fa86cf0 -r 8b193c9e82c2 sys/kern/exec_elf.c
--- a/sys/kern/exec_elf.c Wed Mar 07 08:56:44 2018 +0000
+++ b/sys/kern/exec_elf.c Wed Mar 07 09:33:26 2018 +0000
@@ -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 @@
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;
-}
diff -r 3a8a7fa86cf0 -r 8b193c9e82c2 sys/kern/files.kern
--- a/sys/kern/files.kern Wed Mar 07 08:56:44 2018 +0000
+++ b/sys/kern/files.kern Wed Mar 07 09:33:26 2018 +0000
@@ -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_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
diff -r 3a8a7fa86cf0 -r 8b193c9e82c2 sys/kern/subr_emul.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/kern/subr_emul.c Wed Mar 07 09:33:26 2018 +0000
@@ -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;
+}
diff -r 3a8a7fa86cf0 -r 8b193c9e82c2 sys/sys/exec.h
--- a/sys/sys/exec.h Wed Mar 07 08:56:44 2018 +0000
+++ b/sys/sys/exec.h Wed Mar 07 09:33:26 2018 +0000
@@ -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 @@
extern int maxexec;
+/*
+ * Utility functions
+ */
+void emul_find_root(struct lwp *, struct exec_package *);
Home |
Main Index |
Thread Index |
Old Index