Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Support an optional MARCH ELF tag.
details: https://anonhg.NetBSD.org/src/rev/b533296cdd8f
branches: trunk
changeset: 789859:b533296cdd8f
user: matt <matt%NetBSD.org@localhost>
date: Tue Sep 10 21:30:21 2013 +0000
description:
Support an optional MARCH ELF tag.
Store the MACHINE_ARCH of the executable in mdproc and override sysctl
so that value returned.
diffstat:
sys/arch/arm/arm/cpu_exec.c | 12 ++++++++++--
sys/arch/arm/arm32/arm32_machdep.c | 29 +++++++++++++++++++++++++++--
sys/arch/arm/arm32/vm_machdep.c | 8 ++++++--
sys/kern/exec_elf.c | 22 ++++++++++++++++++++--
sys/kern/kern_exec.c | 6 ++++--
sys/kern/kern_proc.c | 7 +++++--
sys/sys/exec.h | 3 ++-
7 files changed, 74 insertions(+), 13 deletions(-)
diffs (234 lines):
diff -r de779cb4e444 -r b533296cdd8f sys/arch/arm/arm/cpu_exec.c
--- a/sys/arch/arm/arm/cpu_exec.c Tue Sep 10 20:36:08 2013 +0000
+++ b/sys/arch/arm/arm/cpu_exec.c Tue Sep 10 21:30:21 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_exec.c,v 1.4 2013/08/05 00:57:24 matt Exp $ */
+/* $NetBSD: cpu_exec.c,v 1.5 2013/09/10 21:30:21 matt Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu_exec.c,v 1.4 2013/08/05 00:57:24 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_exec.c,v 1.5 2013/09/10 21:30:21 matt Exp $");
#include "opt_compat_netbsd.h"
#include "opt_compat_netbsd32.h"
@@ -102,6 +102,14 @@
if (itp_suffix != NULL)
(void)compat_elf_check_interp(epp, itp, itp_suffix);
+
+ /*
+ * Copy (if any) the machine_arch of the executable to the proc.
+ */
+ if (epp->ep_machine_arch[0] != 0) {
+ strlcpy(l->l_proc->p_md.md_march, epp->ep_machine_arch,
+ sizeof(l->l_proc->p_md.md_march));
+ }
return 0;
}
#endif
diff -r de779cb4e444 -r b533296cdd8f sys/arch/arm/arm32/arm32_machdep.c
--- a/sys/arch/arm/arm32/arm32_machdep.c Tue Sep 10 20:36:08 2013 +0000
+++ b/sys/arch/arm/arm32/arm32_machdep.c Tue Sep 10 21:30:21 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: arm32_machdep.c,v 1.97 2013/09/07 23:10:02 matt Exp $ */
+/* $NetBSD: arm32_machdep.c,v 1.98 2013/09/10 21:30:21 matt Exp $ */
/*
* Copyright (c) 1994-1998 Mark Brinicombe.
@@ -42,7 +42,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: arm32_machdep.c,v 1.97 2013/09/07 23:10:02 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: arm32_machdep.c,v 1.98 2013/09/10 21:30:21 matt Exp $");
#include "opt_modular.h"
#include "opt_md.h"
@@ -376,6 +376,15 @@
return (0);
}
+static int
+sysctl_hw_machine_arch(SYSCTLFN_ARGS)
+{
+ struct sysctlnode node = *rnode;
+ node.sysctl_data = l->l_proc->p_md.md_march;
+ node.sysctl_size = strlen(l->l_proc->p_md.md_march) + 1;
+ return sysctl_lookup(SYSCTLFN_CALL(&node));
+}
+
SYSCTL_SETUP(sysctl_machdep_setup, "sysctl machdep subtree setup")
{
@@ -480,6 +489,22 @@
CTLTYPE_INT, "simdex_present", NULL,
NULL, 0, &cpu_simdex_present, 0,
CTL_MACHDEP, CTL_CREATE, CTL_EOL);
+
+ /*
+ * We need override the usual CTL_HW HW_MACHINE_ARCH so we
+ * return the right machine_arch based on the running executable.
+ */
+ sysctl_createv(clog, 0, NULL, NULL,
+ CTLFLAG_PERMANENT,
+ CTLTYPE_NODE, "hw", NULL,
+ NULL, 0, NULL, 0,
+ CTL_HW, CTL_EOL);
+ sysctl_createv(clog, 0, NULL, NULL,
+ CTLFLAG_PERMANENT|CTLFLAG_READONLY,
+ CTLTYPE_STRING, "machine_arch",
+ SYSCTL_DESCR("Machine CPU class"),
+ sysctl_hw_machine_arch, 0, NULL, 0,
+ CTL_HW, HW_MACHINE_ARCH, CTL_EOL);
}
void
diff -r de779cb4e444 -r b533296cdd8f sys/arch/arm/arm32/vm_machdep.c
--- a/sys/arch/arm/arm32/vm_machdep.c Tue Sep 10 20:36:08 2013 +0000
+++ b/sys/arch/arm/arm32/vm_machdep.c Tue Sep 10 21:30:21 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vm_machdep.c,v 1.67 2013/08/23 05:22:01 matt Exp $ */
+/* $NetBSD: vm_machdep.c,v 1.68 2013/09/10 21:30:21 matt Exp $ */
/*
* Copyright (c) 1994-1998 Mark Brinicombe.
@@ -44,7 +44,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.67 2013/08/23 05:22:01 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.68 2013/09/10 21:30:21 matt Exp $");
#include "opt_armfpe.h"
#include "opt_pmap_debug.h"
@@ -93,6 +93,10 @@
p2->p_md.pmc_state = NULL;
}
#endif
+ /*
+ * Copy machine arch string (it's small so just memcpy it).
+ */
+ memcpy(p2->p_md.md_march, p1->p_md.md_march, sizeof(p2->p_md.md_march));
}
/*
diff -r de779cb4e444 -r b533296cdd8f sys/kern/exec_elf.c
--- a/sys/kern/exec_elf.c Tue Sep 10 20:36:08 2013 +0000
+++ b/sys/kern/exec_elf.c Tue Sep 10 21:30:21 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: exec_elf.c,v 1.46 2013/08/26 12:24:10 martin Exp $ */
+/* $NetBSD: exec_elf.c,v 1.47 2013/09/10 21:30:21 matt Exp $ */
/*-
* Copyright (c) 1994, 2000, 2005 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.46 2013/08/26 12:24:10 martin Exp $");
+__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.47 2013/09/10 21:30:21 matt Exp $");
#ifdef _KERNEL_OPT
#include "opt_pax.h"
@@ -946,6 +946,24 @@
sizeof(epp->ep_pax_flags));
break;
+ case ELF_NOTE_TYPE_MARCH_TAG:
+ /*
+ * Copy the machine arch into the package.
+ */
+ if (np->n_namesz == ELF_NOTE_MARCH_NAMESZ
+ && memcmp(ndata, ELF_NOTE_MARCH_NAME,
+ ELF_NOTE_MARCH_NAMESZ) == 0) {
+ strlcpy(epp->ep_machine_arch,
+ ndata + roundup(ELF_NOTE_MARCH_NAMESZ, 4),
+ sizeof(epp->ep_machine_arch));
+ break;
+ }
+
+ /*
+ * Dunno, warn for diagnostic
+ */
+ goto bad;
+
case ELF_NOTE_TYPE_SUSE_VERSION_TAG:
break;
diff -r de779cb4e444 -r b533296cdd8f sys/kern/kern_exec.c
--- a/sys/kern/kern_exec.c Tue Sep 10 20:36:08 2013 +0000
+++ b/sys/kern/kern_exec.c Tue Sep 10 21:30:21 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_exec.c,v 1.361 2013/06/09 01:13:47 riz Exp $ */
+/* $NetBSD: kern_exec.c,v 1.362 2013/09/10 21:30:21 matt Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.361 2013/06/09 01:13:47 riz Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.362 2013/09/10 21:30:21 matt Exp $");
#include "opt_exec.h"
#include "opt_execfmt.h"
@@ -657,6 +657,8 @@
data->ed_pack.ep_interp = NULL;
data->ed_pack.ep_esch = NULL;
data->ed_pack.ep_pax_flags = 0;
+ memset(data->ed_pack.ep_machine_arch, 0,
+ sizeof(data->ed_pack.ep_machine_arch));
rw_enter(&exec_lock, RW_READER);
diff -r de779cb4e444 -r b533296cdd8f sys/kern/kern_proc.c
--- a/sys/kern/kern_proc.c Tue Sep 10 20:36:08 2013 +0000
+++ b/sys/kern/kern_proc.c Tue Sep 10 21:30:21 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_proc.c,v 1.187 2013/06/10 14:53:52 pooka Exp $ */
+/* $NetBSD: kern_proc.c,v 1.188 2013/09/10 21:30:21 matt Exp $ */
/*-
* Copyright (c) 1999, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.187 2013/06/10 14:53:52 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.188 2013/09/10 21:30:21 matt Exp $");
#ifdef _KERNEL_OPT
#include "opt_kstack.h"
@@ -201,6 +201,9 @@
.p_vmspace = &vmspace0,
.p_stats = &pstat0,
.p_sigacts = &sigacts0,
+#ifdef PROC0_MD_INITIALIZERS
+ PROC0_MD_INITIALIZERS
+#endif
};
kauth_cred_t cred0;
diff -r de779cb4e444 -r b533296cdd8f sys/sys/exec.h
--- a/sys/sys/exec.h Tue Sep 10 20:36:08 2013 +0000
+++ b/sys/sys/exec.h Tue Sep 10 21:30:21 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: exec.h,v 1.139 2012/08/05 01:43:59 matt Exp $ */
+/* $NetBSD: exec.h,v 1.140 2013/09/10 21:30:21 matt Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -216,6 +216,7 @@
char *ep_path; /* absolute path of executable */
void (*ep_emul_arg_free)(void *);
/* free ep_emul_arg */
+ char ep_machine_arch[12]; /* from MARCH note */
};
#define EXEC_INDIR 0x0001 /* script handling already done */
#define EXEC_HASFD 0x0002 /* holding a shell script */
Home |
Main Index |
Thread Index |
Old Index