Date: Wed, 21 Jul 2010 15:00:28 +0300 From: Kostik Belousov <kostikbel@gmail.com> To: Nathan Whitehorn <nwhitehorn@freebsd.org> Cc: amd64@freebsd.org, freebsd-arch@freebsd.org Subject: Re: uname -m/-p for compat32 binaries Message-ID: <20100721120028.GM2381@deviant.kiev.zoral.com.ua> In-Reply-To: <4C460BB9.1060009@freebsd.org> References: <20100719213054.GB2381@deviant.kiev.zoral.com.ua> <201007200907.24715.jhb@freebsd.org> <4C460BB9.1060009@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--anmYPbAsEPjx7802 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Jul 20, 2010 at 03:48:57PM -0500, Nathan Whitehorn wrote: > On 07/20/10 08:07, John Baldwin wrote: > >On Monday, July 19, 2010 5:30:54 pm Kostik Belousov wrote: > > =20 > >>Hi, > >>I intend to commit the following change, that makes sysctls > >>hw.machine_arch and hw.machine to return "i386" for 32 bit > >>binaries run on amd64. In particular, 32 bit uname -m and uname -p > >>print "i386", that is good for i386 jails on amd64 kernels. > >> > >>I find the change very useful for me, but I wonder why such trivial > >>modification is not yet done. Can anybody note a possible fallout from > >>it ? > >> =20 > >Presumably ia64 and powerpc64 would need a similar change as well? It= =20 > >looks > >fine to me. I suspect Y! used the UNAME_* approach as it didn't add yet- > >another local diff to maintain in the kernel, and the uname fixes at Y!= =20 > >might > >have predated SCTL_MASK32. > > =20 > Maybe it makes sense to define a MACHINE_ARCH32 in machine/param.h, as=20 > is done for ELF_ARCH32 in machine/elf.h? This would keep the MI code in= =20 > the kernel MI, and ever-so-slightly simplify implementation for ia64,=20 > mips, and powerpc64. Thanks for doing this! See below. Also, I painted red another wall, adding a sysctl to turn the adaptive behaviour off. diff --git a/sys/amd64/amd64/identcpu.c b/sys/amd64/amd64/identcpu.c index 52e7568..914f4d2 100644 --- a/sys/amd64/amd64/identcpu.c +++ b/sys/amd64/amd64/identcpu.c @@ -76,8 +76,28 @@ static void print_via_padlock_info(void); =20 int cpu_class; char machine[] =3D "amd64"; -SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD,=20 - machine, 0, "Machine class"); + +extern int adaptive_machine_arch; + +static int +sysctl_hw_machine(SYSCTL_HANDLER_ARGS) +{ +#ifdef SCTL_MASK32 + static const char machine32[] =3D "i386"; +#endif + int error; + +#ifdef SCTL_MASK32 + if ((req->flags & SCTL_MASK32) !=3D 0 && adaptive_machine_arch) + error =3D SYSCTL_OUT(req, machine32, sizeof(machine32)); + else +#endif + error =3D 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"); =20 static char cpu_model[128]; SYSCTL_STRING(_hw, HW_MODEL, model, CTLFLAG_RD,=20 diff --git a/sys/amd64/include/param.h b/sys/amd64/include/param.h index c940597..9a742f9 100644 --- a/sys/amd64/include/param.h +++ b/sys/amd64/include/param.h @@ -59,6 +59,9 @@ #ifndef MACHINE_ARCH #define MACHINE_ARCH "amd64" #endif +#ifndef MACHINE_ARCH32 +#define MACHINE_ARCH32 "i386" +#endif =20 #if defined(SMP) || defined(KLD_MODULE) #define MAXCPU 32 diff --git a/sys/ia64/include/param.h b/sys/ia64/include/param.h index ba26290..36b27e0 100644 --- a/sys/ia64/include/param.h +++ b/sys/ia64/include/param.h @@ -57,6 +57,9 @@ #ifndef MACHINE_ARCH #define MACHINE_ARCH "ia64" #endif +#ifndef MACHINE_ARCH32 +#define MACHINE_ARCH32 "i386" +#endif =20 #if defined(SMP) || defined(KLD_MODULE) #define MAXCPU 32 diff --git a/sys/kern/kern_mib.c b/sys/kern/kern_mib.c index 7ef580f..3bfecea 100644 --- a/sys/kern/kern_mib.c +++ b/sys/kern/kern_mib.c @@ -232,9 +232,28 @@ 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"); =20 -static char machine_arch[] =3D MACHINE_ARCH; -SYSCTL_STRING(_hw, HW_MACHINE_ARCH, machine_arch, CTLFLAG_RD, - machine_arch, 0, "System architecture"); +int adaptive_machine_arch =3D 1; +static int +sysctl_hw_machine_arch(SYSCTL_HANDLER_ARGS) +{ + int error; + static const char machine_arch[] =3D MACHINE_ARCH; +#ifdef SCTL_MASK32 + static const char machine_arch32[] =3D MACHINE_ARCH32; + + if ((req->flags & SCTL_MASK32) !=3D 0 && adaptive_machine_arch) + error =3D SYSCTL_OUT(req, machine_arch32, sizeof(machine_arch32)); + else +#endif + error =3D SYSCTL_OUT(req, machine_arch, sizeof(machine_arch)); + return (error); + +} +SYSCTL_PROC(_hw, HW_MACHINE_ARCH, machine_arch, CTLTYPE_STRING | CTLFLAG_R= D, + NULL, 0, sysctl_hw_machine_arch, "A", "System architecture"); +SYSCTL_INT(_debug, OID_AUTO, adaptive_machine_arch, CTLFLAG_RW, + &adaptive_machine_arch, 1, + "Adapt reported machine architecture to the ABI of the binary"); =20 static int sysctl_hostname(SYSCTL_HANDLER_ARGS) diff --git a/sys/powerpc/include/param.h b/sys/powerpc/include/param.h index 4aeabe7..91bb238 100644 --- a/sys/powerpc/include/param.h +++ b/sys/powerpc/include/param.h @@ -61,6 +61,11 @@ #endif #endif #define MID_MACHINE MID_POWERPC +#ifdef __powerpc64__ +#ifndef MACHINE_ARCH32 +#define MACHINE_ARCH32 "powerpc" +#endif +#endif =20 #if defined(SMP) || defined(KLD_MODULE) #define MAXCPU 2 --anmYPbAsEPjx7802 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (FreeBSD) iEYEARECAAYFAkxG4VwACgkQC3+MBN1Mb4hbGgCZAWr8jbD9YJ30/gAjd7up8ShA J6cAnROwLg7mlwmNpMjftFBgj/1UkYAN =4Gq8 -----END PGP SIGNATURE----- --anmYPbAsEPjx7802--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100721120028.GM2381>