From owner-freebsd-net@FreeBSD.ORG Fri Jun 6 07:36:40 2008 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id ED37F1065673 for ; Fri, 6 Jun 2008 07:36:40 +0000 (UTC) (envelope-from marc.loerner@hob.de) Received: from mailgate.hob.de (mailgate.hob.de [212.185.199.3]) by mx1.freebsd.org (Postfix) with ESMTP id 9B9CE8FC14 for ; Fri, 6 Jun 2008 07:36:40 +0000 (UTC) (envelope-from marc.loerner@hob.de) Received: from imap.hob.de (mail2.hob.de [172.25.1.102]) by mailgate.hob.de (Postfix) with ESMTP id 6739C52006F; Fri, 6 Jun 2008 09:36:39 +0200 (CEST) Received: from [172.22.0.190] (linux03.hob.de [172.22.0.190]) by imap.hob.de (Postfix on SuSE eMail Server 2.0) with ESMTP id 42F98FD2A5; Fri, 6 Jun 2008 09:36:39 +0200 (CEST) From: Marc =?iso-8859-1?q?L=F6rner?= Organization: hob To: "Bruce M. Simpson" Date: Fri, 6 Jun 2008 09:36:20 +0200 User-Agent: KMail/1.6.2 References: <200806051712.47048.marc.loerner@hob.de> <48480FA5.3020800@FreeBSD.org> In-Reply-To: <48480FA5.3020800@FreeBSD.org> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit Message-Id: <200806060936.20113.marc.loerner@hob.de> Cc: freebsd-net@freebsd.org Subject: Re: Probable Bug in tcp.h X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Jun 2008 07:36:41 -0000 On Thursday 05 June 2008 18:09, Bruce M. Simpson wrote: > Marc Lörner wrote: > > .. > > First of all I have the problam of misalignment of th_off. Because in > > this way always 4 bytes are read and the the bits of th_off are replaced. > > Then the 4 bytes are written back. > > > > But should (th_x and th_off) not only be 1 byte in whole -> only read and > > write 1 byte? > > Which machine architecture are you attempting to compile this code on? > ia64/itanium > On FreeBSD Tier 1 platforms, the access is probably going to come out of > L2 cache anyway, so the fields in question will be read by a burst cycle. > I know! But the problem (on itanium) is that bitfields are always accessed as integers => 4-byte access But th_x/th_off may not always be aligned to 4-bytes => I get an unalignment reference fault If access of th_x/th_off could be changed to 1-byte => 1-byte aligned => my unaligned reference fault would go away > It is worth noting that NetBSD changed the base type of tcphdr's > bitfields to uint8_t, however this shuffles the compiler dependency into > the treatment of the "char" type. Most modern C compilers support > "unsigned char". Does this really change the access to 1-byte? As in "Programming in C" by Kernighan and Ritchie is stated that bitfields must and will always be defined as ints.