From owner-freebsd-sparc64@FreeBSD.ORG Mon Sep 3 19:45:51 2007 Return-Path: Delivered-To: freebsd-sparc64@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 27ECC16A468 for ; Mon, 3 Sep 2007 19:45:51 +0000 (UTC) (envelope-from mailnull@mips.inka.de) Received: from mail-in-08.arcor-online.net (mail-in-08.arcor-online.net [151.189.21.48]) by mx1.freebsd.org (Postfix) with ESMTP id D709613C483 for ; Mon, 3 Sep 2007 19:45:50 +0000 (UTC) (envelope-from mailnull@mips.inka.de) Received: from mail-in-13-z2.arcor-online.net (mail-in-13-z2.arcor-online.net [151.189.8.30]) by mail-in-08.arcor-online.net (Postfix) with ESMTP id 4147E2F291C for ; Mon, 3 Sep 2007 21:45:47 +0200 (CEST) Received: from mail-in-03.arcor-online.net (mail-in-03.arcor-online.net [151.189.21.43]) by mail-in-13-z2.arcor-online.net (Postfix) with ESMTP id 30BE61B8E46 for ; Mon, 3 Sep 2007 21:45:47 +0200 (CEST) Received: from kemoauc.mips.inka.de (dslb-088-066-050-226.pools.arcor-ip.net [88.66.50.226]) by mail-in-03.arcor-online.net (Postfix) with ESMTP id DAFDB30ABD2 for ; Mon, 3 Sep 2007 21:45:42 +0200 (CEST) Received: from kemoauc.mips.inka.de (localhost [127.0.0.1]) by kemoauc.mips.inka.de (8.13.8/8.13.8) with ESMTP id l83JjeWC079855 for ; Mon, 3 Sep 2007 21:45:40 +0200 (CEST) (envelope-from mailnull@kemoauc.mips.inka.de) Received: (from mailnull@localhost) by kemoauc.mips.inka.de (8.13.8/8.13.8/Submit) id l83Jjeum079854 for freebsd-sparc64@freebsd.org; Mon, 3 Sep 2007 21:45:40 +0200 (CEST) (envelope-from mailnull) From: naddy@mips.inka.de (Christian Weisgerber) Date: Mon, 3 Sep 2007 19:45:39 +0000 (UTC) Message-ID: References: <20070901165653.GA38448@saturn.kn-bremen.de> Originator: naddy@mips.inka.de (Christian Weisgerber) To: freebsd-sparc64@freebsd.org X-Virus-Scanned: ClamAV 0.91.2/4140/Mon Sep 3 19:59:33 2007 on mail-in-03.arcor-online.net X-Virus-Status: Clean Subject: Re: weird sparc64/-current issue!? (p7zip) X-BeenThere: freebsd-sparc64@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting FreeBSD to the Sparc List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Sep 2007 19:45:51 -0000 Christian Weisgerber wrote: > > UInt32 GetNumberOfProcessors() { > > int nbcpu = 1; > > size_t value; > > size_t len = sizeof(value); > > if (sysctlbyname("hw.ncpu", &value, &len, NULL, 0) == 0) > > nbcpu = value; > > return nbcpu; > > } > > Are you sure that value is of type size_t here? I think it is an > int. (Remember, size_t is 64 bits on all our 64-bit platforms, int > is 32 bits.) I should expand on this, because it is a really tricky LP64 bug. sysctlbyname() writes a 32-bit value to the supplied address, but we then read a 64-bit value. On a little-endian machine (alpha, amd64) we get the actual value in the lower 32 bits and random garbage in the upper 32. Then the assignment nbcpu=value drops the upper 32 bits. Quite by accident, we always end up with the correct result. On a big-endian machine (sparc64), it's the other way around: We get the actual value in the upper 32 bits and random garbage in the lower 32. Then the assignment nbcpu=value drops the upper 32 bits. Thus we always end up with a garbage result. -- Christian "naddy" Weisgerber naddy@mips.inka.de