Probable Bug in tcp.h

Marc Lörner marc.loerner at hob.de
Fri Jun 6 07:36:41 UTC 2008


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.


More information about the freebsd-net mailing list