From owner-svn-src-all@FreeBSD.ORG Thu Jul 22 09:13:50 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 140C0106566B; Thu, 22 Jul 2010 09:13:50 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id EBB5B8FC12; Thu, 22 Jul 2010 09:13:49 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o6M9DnSe000351; Thu, 22 Jul 2010 09:13:49 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o6M9Dnm9000347; Thu, 22 Jul 2010 09:13:49 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201007220913.o6M9Dnm9000347@svn.freebsd.org> From: Konstantin Belousov Date: Thu, 22 Jul 2010 09:13:49 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r210369 - in head/sys: amd64/amd64 amd64/include ia64/include kern powerpc/include X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Jul 2010 09:13:50 -0000 Author: kib Date: Thu Jul 22 09:13:49 2010 New Revision: 210369 URL: http://svn.freebsd.org/changeset/base/210369 Log: When compat32 binary asks for the value of hw.machine_arch, report the name of 32bit sibling architecture instead of the host one. Do the same for hw.machine on amd64. Add a safety belt debug.adaptive_machine_arch sysctl, to turn the substitution off. Reviewed by: jhb, nwhitehorn MFC after: 2 weeks Modified: head/sys/amd64/amd64/identcpu.c head/sys/amd64/include/param.h head/sys/ia64/include/param.h head/sys/kern/kern_mib.c head/sys/powerpc/include/param.h Modified: head/sys/amd64/amd64/identcpu.c ============================================================================== --- head/sys/amd64/amd64/identcpu.c Thu Jul 22 08:30:14 2010 (r210368) +++ head/sys/amd64/amd64/identcpu.c Thu Jul 22 09:13:49 2010 (r210369) @@ -76,8 +76,30 @@ static void print_via_padlock_info(void) int cpu_class; char machine[] = "amd64"; -SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD, - machine, 0, "Machine class"); + +#ifdef SCTL_MASK32 +extern int adaptive_machine_arch; +#endif + +static int +sysctl_hw_machine(SYSCTL_HANDLER_ARGS) +{ +#ifdef SCTL_MASK32 + static const char machine32[] = "i386"; +#endif + int error; + +#ifdef SCTL_MASK32 + if ((req->flags & SCTL_MASK32) != 0 && adaptive_machine_arch) + error = SYSCTL_OUT(req, machine32, sizeof(machine32)); + else +#endif + error = SYSCTL_OUT(req, machine, sizeof(machine)); + return (error); + +} +SYSCTL_PROC(_hw, HW_MACHINE, machine, CTLTYPE_STRING | CTLFLAG_RD, + NULL, 0, sysctl_hw_machine, "A", "Machine class"); static char cpu_model[128]; SYSCTL_STRING(_hw, HW_MODEL, model, CTLFLAG_RD, Modified: head/sys/amd64/include/param.h ============================================================================== --- head/sys/amd64/include/param.h Thu Jul 22 08:30:14 2010 (r210368) +++ head/sys/amd64/include/param.h Thu Jul 22 09:13:49 2010 (r210369) @@ -59,6 +59,9 @@ #ifndef MACHINE_ARCH #define MACHINE_ARCH "amd64" #endif +#ifndef MACHINE_ARCH32 +#define MACHINE_ARCH32 "i386" +#endif #if defined(SMP) || defined(KLD_MODULE) #define MAXCPU 32 Modified: head/sys/ia64/include/param.h ============================================================================== --- head/sys/ia64/include/param.h Thu Jul 22 08:30:14 2010 (r210368) +++ head/sys/ia64/include/param.h Thu Jul 22 09:13:49 2010 (r210369) @@ -57,6 +57,9 @@ #ifndef MACHINE_ARCH #define MACHINE_ARCH "ia64" #endif +#ifndef MACHINE_ARCH32 +#define MACHINE_ARCH32 "i386" +#endif #if defined(SMP) || defined(KLD_MODULE) #define MAXCPU 32 Modified: head/sys/kern/kern_mib.c ============================================================================== --- head/sys/kern/kern_mib.c Thu Jul 22 08:30:14 2010 (r210368) +++ head/sys/kern/kern_mib.c Thu Jul 22 09:13:49 2010 (r210369) @@ -232,9 +232,31 @@ sysctl_hw_pagesizes(SYSCTL_HANDLER_ARGS) SYSCTL_PROC(_hw, OID_AUTO, pagesizes, CTLTYPE_ULONG | CTLFLAG_RD, NULL, 0, sysctl_hw_pagesizes, "LU", "Supported page sizes"); -static char machine_arch[] = MACHINE_ARCH; -SYSCTL_STRING(_hw, HW_MACHINE_ARCH, machine_arch, CTLFLAG_RD, - machine_arch, 0, "System architecture"); +#ifdef SCTL_MASK32 +int adaptive_machine_arch = 1; +SYSCTL_INT(_debug, OID_AUTO, adaptive_machine_arch, CTLFLAG_RW, + &adaptive_machine_arch, 1, + "Adapt reported machine architecture to the ABI of the binary"); +#endif + +static int +sysctl_hw_machine_arch(SYSCTL_HANDLER_ARGS) +{ + int error; + static const char machine_arch[] = MACHINE_ARCH; +#ifdef SCTL_MASK32 + static const char machine_arch32[] = MACHINE_ARCH32; + + if ((req->flags & SCTL_MASK32) != 0 && adaptive_machine_arch) + error = SYSCTL_OUT(req, machine_arch32, sizeof(machine_arch32)); + else +#endif + error = SYSCTL_OUT(req, machine_arch, sizeof(machine_arch)); + return (error); + +} +SYSCTL_PROC(_hw, HW_MACHINE_ARCH, machine_arch, CTLTYPE_STRING | CTLFLAG_RD, + NULL, 0, sysctl_hw_machine_arch, "A", "System architecture"); static int sysctl_hostname(SYSCTL_HANDLER_ARGS) Modified: head/sys/powerpc/include/param.h ============================================================================== --- head/sys/powerpc/include/param.h Thu Jul 22 08:30:14 2010 (r210368) +++ head/sys/powerpc/include/param.h Thu Jul 22 09:13:49 2010 (r210369) @@ -61,6 +61,11 @@ #endif #endif #define MID_MACHINE MID_POWERPC +#ifdef __powerpc64__ +#ifndef MACHINE_ARCH32 +#define MACHINE_ARCH32 "powerpc" +#endif +#endif #if defined(SMP) || defined(KLD_MODULE) #define MAXCPU 2