Module Name:    src
Committed By:   matt
Date:           Tue Sep 10 21:30:21 UTC 2013

Modified Files:
        src/sys/arch/arm/arm: cpu_exec.c
        src/sys/arch/arm/arm32: arm32_machdep.c vm_machdep.c
        src/sys/kern: exec_elf.c kern_exec.c kern_proc.c
        src/sys/sys: exec.h

Log Message:
Support an optional MARCH ELF tag.
Store the MACHINE_ARCH of the executable in mdproc and override sysctl
so that value returned.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/arm/arm/cpu_exec.c
cvs rdiff -u -r1.97 -r1.98 src/sys/arch/arm/arm32/arm32_machdep.c
cvs rdiff -u -r1.67 -r1.68 src/sys/arch/arm/arm32/vm_machdep.c
cvs rdiff -u -r1.46 -r1.47 src/sys/kern/exec_elf.c
cvs rdiff -u -r1.361 -r1.362 src/sys/kern/kern_exec.c
cvs rdiff -u -r1.187 -r1.188 src/sys/kern/kern_proc.c
cvs rdiff -u -r1.139 -r1.140 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/arch/arm/arm/cpu_exec.c
diff -u src/sys/arch/arm/arm/cpu_exec.c:1.4 src/sys/arch/arm/arm/cpu_exec.c:1.5
--- src/sys/arch/arm/arm/cpu_exec.c:1.4	Mon Aug  5 00:57:24 2013
+++ src/sys/arch/arm/arm/cpu_exec.c	Tue Sep 10 21:30:21 2013
@@ -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 @@ arm_netbsd_elf32_probe(struct lwp *l, st
 
 	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

Index: src/sys/arch/arm/arm32/arm32_machdep.c
diff -u src/sys/arch/arm/arm32/arm32_machdep.c:1.97 src/sys/arch/arm/arm32/arm32_machdep.c:1.98
--- src/sys/arch/arm/arm32/arm32_machdep.c:1.97	Sat Sep  7 23:10:02 2013
+++ src/sys/arch/arm/arm32/arm32_machdep.c	Tue Sep 10 21:30:21 2013
@@ -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 @@ sysctl_machdep_powersave(SYSCTLFN_ARGS)
 	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 @@ SYSCTL_SETUP(sysctl_machdep_setup, "sysc
 		       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

Index: src/sys/arch/arm/arm32/vm_machdep.c
diff -u src/sys/arch/arm/arm32/vm_machdep.c:1.67 src/sys/arch/arm/arm32/vm_machdep.c:1.68
--- src/sys/arch/arm/arm32/vm_machdep.c:1.67	Fri Aug 23 05:22:01 2013
+++ src/sys/arch/arm/arm32/vm_machdep.c	Tue Sep 10 21:30:21 2013
@@ -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 @@ cpu_proc_fork(struct proc *p1, struct pr
 		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));
 }
 
 /*

Index: src/sys/kern/exec_elf.c
diff -u src/sys/kern/exec_elf.c:1.46 src/sys/kern/exec_elf.c:1.47
--- src/sys/kern/exec_elf.c:1.46	Mon Aug 26 12:24:10 2013
+++ src/sys/kern/exec_elf.c	Tue Sep 10 21:30:21 2013
@@ -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 @@ bad:
 			    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;
 

Index: src/sys/kern/kern_exec.c
diff -u src/sys/kern/kern_exec.c:1.361 src/sys/kern/kern_exec.c:1.362
--- src/sys/kern/kern_exec.c:1.361	Sun Jun  9 01:13:47 2013
+++ src/sys/kern/kern_exec.c	Tue Sep 10 21:30:21 2013
@@ -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 @@ execve_loadvm(struct lwp *l, const char 
 	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);
 

Index: src/sys/kern/kern_proc.c
diff -u src/sys/kern/kern_proc.c:1.187 src/sys/kern/kern_proc.c:1.188
--- src/sys/kern/kern_proc.c:1.187	Mon Jun 10 14:53:52 2013
+++ src/sys/kern/kern_proc.c	Tue Sep 10 21:30:21 2013
@@ -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 @@ struct proc proc0 = {
 	.p_vmspace = &vmspace0,
 	.p_stats = &pstat0,
 	.p_sigacts = &sigacts0,
+#ifdef PROC0_MD_INITIALIZERS
+	PROC0_MD_INITIALIZERS
+#endif
 };
 kauth_cred_t cred0;
 

Index: src/sys/sys/exec.h
diff -u src/sys/sys/exec.h:1.139 src/sys/sys/exec.h:1.140
--- src/sys/sys/exec.h:1.139	Sun Aug  5 01:43:59 2012
+++ src/sys/sys/exec.h	Tue Sep 10 21:30:21 2013
@@ -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 @@ struct exec_package {
 	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 */

Reply via email to