[Bro-Dev] Alignment check in RPC code

Gregor Maier gregor at icir.org
Sat Dec 11 10:50:26 PST 2010


On 12/11/10 8:59 , Robin Sommer wrote:
>> Mac OS X is fine with doing un-aligned reads.
> 
> This surprises me. Isn't that a CPU property rather than a OS property?

IIRC that depends. The CPU could generate an alignment fault on
unaligned load/store and the OS can then recover. But x86 have always
been able to handle unaligned memory access.
(I was actually just saying that on my system unaligned reads worked,
not that Mac OS X did the recovery).


>> 	uint32 bits32 = XDR_aligned(buf) ? ntohl(*(uint32*) buf) :
>> 		((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]);
> 
> I'm wondering how much benefit we get by doing this if-else clause
> vs. just always doing the safe version that doesn't care about
> alignment? Is it worth it?

I'm also wondering alignment checks should be done higher up in the
analyzer tree? E.g., to guarantee to protocol analyzers that the buffer
in DeliverStream() and DeliverPacket() calls are 4- or 8-byte aligned
(e.g., by copying the data into an aligned buffer). OTOH, if we use
binpac++ in the future, than binpacc++ can do alignment checks.

BTW, It seems that binpac doesn't do alignment-safe data extraction. Is
it worth filing a ticket for that?


cu
Gregor
-- 
Gregor Maier                                             gregor at icir.org
Int. Computer Science Institute (ICSI)          gregor at icsi.berkeley.edu
1947 Center St., Ste. 600                    http://www.icir.org/gregor/
Berkeley, CA 94704
USA


More information about the bro-dev mailing list