tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Adding a flag to sysctl_createv() to silence ARM warnings



Following Christos' idea I ended up with the patch below that works just fine.
I haven't even compile tested the mips part.

This removes #ifdef __mips__ in netbsd32 compat code, so I like it.

I'll commit this if no objections are raised.

Martin


Index: kern/init_sysctl_base.c
===================================================================
RCS file: /cvsroot/src/sys/kern/init_sysctl_base.c,v
retrieving revision 1.7
diff -u -r1.7 init_sysctl_base.c
--- kern/init_sysctl_base.c	25 Aug 2015 14:52:31 -0000	1.7
+++ kern/init_sysctl_base.c	30 Oct 2017 20:25:25 -0000
@@ -35,6 +35,7 @@
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/sysctl.h>
+#include <sys/proc.h>
 #include <sys/cpu.h>
 #include <sys/kernel.h>
 #include <sys/disklabel.h>
@@ -183,6 +184,19 @@
 		       CTL_KERN, KERN_RAWPARTITION, CTL_EOL);
 }
 
+static int
+sysctl_hw_machine_arch(SYSCTLFN_ARGS)
+{
+	struct sysctlnode node = *rnode;
+#ifndef PROC_MACHINE_ARCH
+#define PROC_MACHINE_ARCH(P)	machine_arch
+#endif
+
+	node.sysctl_data = PROC_MACHINE_ARCH(l->l_proc);
+	node.sysctl_size = strlen(node.sysctl_data) + 1;
+	return sysctl_lookup(SYSCTLFN_CALL(&node));
+}
+
 SYSCTL_SETUP(sysctl_hwbase_setup, "sysctl hw subtree base setup")
 {
 	u_int u;
@@ -202,10 +216,10 @@
 		       NULL, 0, machine, 0,
 		       CTL_HW, HW_MACHINE, CTL_EOL);
 	sysctl_createv(clog, 0, NULL, NULL,
-		       CTLFLAG_PERMANENT,
+		       CTLFLAG_PERMANENT|CTLFLAG_READONLY,
 		       CTLTYPE_STRING, "machine_arch",
 		       SYSCTL_DESCR("Machine CPU class"),
-		       NULL, 0, machine_arch, 0,
+		       sysctl_hw_machine_arch, 0, NULL, 0,
 		       CTL_HW, HW_MACHINE_ARCH, CTL_EOL);
 	sysctl_createv(clog, 0, NULL, NULL,
 		       CTLFLAG_PERMANENT,
Index: compat/netbsd32/netbsd32_sysctl.c
===================================================================
RCS file: /cvsroot/src/sys/compat/netbsd32/netbsd32_sysctl.c,v
retrieving revision 1.36
diff -u -r1.36 netbsd32_sysctl.c
--- compat/netbsd32/netbsd32_sysctl.c	17 May 2015 18:52:37 -0000	1.36
+++ compat/netbsd32/netbsd32_sysctl.c	30 Oct 2017 20:25:44 -0000
@@ -104,13 +104,24 @@
 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
 }
 
+static int
+sysctl_hw_machine_arch32(SYSCTLFN_ARGS)
+{
+	struct sysctlnode node = *rnode;
+#ifndef PROC_MACHINE_ARCH32
+	extern const char machine_arch32[];
+#define PROC_MACHINE_ARCH32(P)	machine_arch32
+#endif
+
+	node.sysctl_data = PROC_MACHINE_ARCH32(l->l_proc);
+	node.sysctl_size = strlen(node.sysctl_data) + 1;
+	return sysctl_lookup(SYSCTLFN_CALL(&node));
+}
+
 void
 netbsd32_sysctl_init(void)
 {
 	const struct sysctlnode *_root = &netbsd32_sysctl_root;
-#ifndef __mips__
-	extern const char machine_arch32[];
-#endif
 	extern const char machine32[];
 
 	sysctl_createv(&netbsd32_clog, 0, &_root, NULL,
@@ -152,19 +163,11 @@
 		       CTLTYPE_STRING, "machine", NULL,
 		       NULL, 0, __UNCONST(&machine32), 0,
 		       CTL_HW, HW_MACHINE, CTL_EOL);
-#ifdef __mips__
 	sysctl_createv(&netbsd32_clog, 0, &_root, NULL,
-		       CTLFLAG_PERMANENT,
+		       CTLFLAG_PERMANENT|CTLFLAG_READONLY,
 		       CTLTYPE_STRING, "machine_arch", NULL,
-		       cpu_machinearch32, 0, NULL, 0,
+		       sysctl_hw_machine_arch32, 0, NULL, 0,
 		       CTL_HW, HW_MACHINE_ARCH, CTL_EOL);
-#else
-	sysctl_createv(&netbsd32_clog, 0, &_root, NULL,
-		       CTLFLAG_PERMANENT,
-		       CTLTYPE_STRING, "machine_arch", NULL,
-		       NULL, 0, __UNCONST(&machine_arch32), 0,
-		       CTL_HW, HW_MACHINE_ARCH, CTL_EOL);
-#endif
 }
 
 void
Index: arch/arm/arm32/arm32_machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/arm/arm32/arm32_machdep.c,v
retrieving revision 1.114
diff -u -r1.114 arm32_machdep.c
--- arch/arm/arm32/arm32_machdep.c	2 Jul 2017 16:16:44 -0000	1.114
+++ arch/arm/arm32/arm32_machdep.c	30 Oct 2017 20:25:56 -0000
@@ -402,15 +402,6 @@
 	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")
 {
 
@@ -532,18 +523,6 @@
 		       SYSCTL_DESCR("Do SIGBUS for fixed unaligned accesses"),
 		       NULL, 0, &cpu_unaligned_sigbus, 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|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: arch/arm/include/netbsd32_machdep.h
===================================================================
RCS file: /cvsroot/src/sys/arch/arm/include/netbsd32_machdep.h,v
retrieving revision 1.1
diff -u -r1.1 netbsd32_machdep.h
--- arch/arm/include/netbsd32_machdep.h	3 Aug 2012 07:59:23 -0000	1.1
+++ arch/arm/include/netbsd32_machdep.h	30 Oct 2017 20:25:56 -0000
@@ -45,6 +45,9 @@
 
 typedef netbsd32_pointer_t			netbsd32_sigcontextp_t;
 
+/* Support varying ABI names for netbsd32 */
+#define	PROC_MACHINE_ARCH32(P)	((P)->p_md.md_march)
+
 /*
  * The sigcode is ABI neutral.
  */
Index: arch/arm/include/proc.h
===================================================================
RCS file: /cvsroot/src/sys/arch/arm/include/proc.h,v
retrieving revision 1.17
diff -u -r1.17 proc.h
--- arch/arm/include/proc.h	24 Feb 2014 16:57:57 -0000	1.17
+++ arch/arm/include/proc.h	30 Oct 2017 20:25:56 -0000
@@ -59,6 +59,7 @@
 	char	md_march[12];		/* machine arch of executable */
 };
 
-#define	PROC0_MD_INITIALIZERS .p_md = { .md_march = MACHINE_ARCH },
+#define	PROC_MACHINE_ARCH(P)	((P)->p_md.md_march)
+#define	PROC0_MD_INITIALIZERS	.p_md = { .md_march = MACHINE_ARCH },
 
 #endif /* _ARM_PROC_H_ */
Index: arch/mips/include/netbsd32_machdep.h
===================================================================
RCS file: /cvsroot/src/sys/arch/mips/include/netbsd32_machdep.h,v
retrieving revision 1.4
diff -u -r1.4 netbsd32_machdep.h
--- arch/mips/include/netbsd32_machdep.h	17 May 2015 18:52:37 -0000	1.4
+++ arch/mips/include/netbsd32_machdep.h	30 Oct 2017 20:26:05 -0000
@@ -44,6 +44,10 @@
 
 typedef netbsd32_pointer_t			netbsd32_sigcontextp_t;
 
+/* Support varying ABI names for netbsd32 */
+#define	PROC_MACHINE_ARCH32(P)	((P)->p_md.md_abi == _MIPS_BSD_API_O32) ? \
+	machine_arch32 : machine_arch
+
 /*
  * The sigcode is ABI neutral.
  */
@@ -69,6 +73,4 @@
 	int ctl;
 };
 
-int cpu_machinearch32(SYSCTLFN_PROTO);
-
 #endif /* _MACHINE_NETBSD32_H_ */
Index: arch/mips/mips/netbsd32_machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/mips/mips/netbsd32_machdep.c,v
retrieving revision 1.14
diff -u -r1.14 netbsd32_machdep.c
--- arch/mips/mips/netbsd32_machdep.c	16 Mar 2017 16:13:20 -0000	1.14
+++ arch/mips/mips/netbsd32_machdep.c	30 Oct 2017 20:26:05 -0000
@@ -343,14 +343,3 @@
 	    chdr->c_cpusize);
 }
 #endif
-
-int
-cpu_machinearch32(SYSCTLFN_ARGS)
-{
-	struct sysctlnode node = *rnode;
-	const char *march = l->l_proc->p_md.md_abi == _MIPS_BSD_API_O32
-	    ? machine_arch32 : machine_arch;
-	node.sysctl_data = __UNCONST(march);
-	node.sysctl_size = strlen(march) + 1;
-	return sysctl_lookup(SYSCTLFN_CALL(&node));
-}



Home | Main Index | Thread Index | Old Index