From owner-freebsd-current Mon Jul 15 4:25:27 2002 Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 17D4F37B400; Mon, 15 Jul 2002 04:25:25 -0700 (PDT) Received: from snipe.mail.pas.earthlink.net (snipe.mail.pas.earthlink.net [207.217.120.62]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9CB7643E42; Mon, 15 Jul 2002 04:25:24 -0700 (PDT) (envelope-from tlambert2@mindspring.com) Received: from pool0003.cvx40-bradley.dialup.earthlink.net ([216.244.42.3] helo=mindspring.com) by snipe.mail.pas.earthlink.net with esmtp (Exim 3.33 #1) id 17U3yl-00061R-00; Mon, 15 Jul 2002 04:25:23 -0700 Message-ID: <3D32B0F1.27EA45EE@mindspring.com> Date: Mon, 15 Jul 2002 04:24:33 -0700 From: Terry Lambert X-Mailer: Mozilla 4.79 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: Luigi Rizzo Cc: Mike Barcroft , current@FreeBSD.org Subject: Re: different packing of structs in kernel vs. userland ? References: <20020714011810.A72236@iguana.icir.org> <20020714203642.GD314@crow.dom2ip.de> <20020714230821.C64412@espresso.q9media.com> <20020715105158.GA314@crow.dom2ip.de> <20020715040008.A85276@iguana.icir.org> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Luigi Rizzo wrote: > sorry but all this just does not make sense to me. > > sizeof(foo) should give the same result irrespective of > where you use it. > > Perhaps the best thing would be to put a > > printf("struct ip_fw has size %d\n", sizeof(struct ip_fw)); > > both in ipfw2.c and somewhere in ip_fw2.c and see if there is > a mismatch between the two numbers. I have to assume that what didn't make sense was that his patch worked? 8-). He's making the valid point that for: struct foo *fee; It's possible that: sizeof(struct foo) != (((char *)&fee[1]) - ((char *)&fee[0])) because of end-padding, which is not accounted for in arrays, and that inter-structure padding depends on ordering of elements (for a good example of this, see the struct direct name element reference macro, which is also padding independent). Basically, end-padding happens because arrays of structures need to have their first element properly aligned, so there is a pad added after each element to ensure that the following element starts on an alignment boundary. I still say that on 486 and higher, the "disallow unaligned access" bit in the processor control register should be enabled, so your kernel will panic if you try this. 8-). -- Terry To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message