From: George France <france@handhelds.org>
To: axp-list@redhat.com, alvin <alvin@iplink.net>
Subject: Re: unaligned traps question
Date: Wed, 16 Oct 2002 15:18:29 -0400 [thread overview]
Message-ID: <02101615182900.18457@shadowfax.middleearth> (raw)
In-Reply-To: <3DADACDB.8000401@iplink.net>
Hello Alvin,
On Wednesday 16 October 2002 14:15, alvin wrote:
> I have spent a good chunk of the last day or so trying to generate a
> case where this problem does actually exist. Sadly I cannot recreate a
> simple bug. I have a program (l2tpd) that runs a network tunneling
> protocol. Anyway. This program works on streams of bytes that are the
> control packets. Some of the packets have 16bit words that are unaligned
> when they are going to be written.
>
> So I have a chunk of code like this:
>
> int add_message_type_avp(struct buffer *buf, _u16 type) {
> _u16 *raw = (_u16 *)(buf->start + buf->len);
> raw[0] = htons(0x8 | MBIT);
> raw[1] = htons(VENDOR_ID);
> raw[2] = 0;
> raw[3] = htons(type);
> buf->len += 8;
> return 0;
> }
>
> I end up converting it to this:
>
> int add_message_type_avp(struct buffer *buf, _u16 type) {
> _u16 raw[32];
> raw[0] = htons(0x8 | MBIT);
> raw[1] = htons(VENDOR_ID);
> raw[2] = 0;
> raw[3] = htons(type);
> memcpy((char *)(buf->start + buf->len), (char *)&raw,8);
> buf->len += 8;
> return 0;
> }
>
>
> This is not pretty but it does work.
Your converted code makes sense. A prettier method is used by the
kernel in asm/unaligned.h via:
get_unaligned(ptr);
put_unaligned(val, ptr);
More information can be found at:
http://www.xml.com/ldd/chapter/book/ch10.html
under the section titled "Data Alignment".
>
> I spent a lot of time tracking this one down and could only come to the
> conclusion that the unaligned trap handler was not working correctly.
If I had to take a wild guess, then I think that the unaligned trap handler
is working correctly and that it is more likely that you have found a compiler
optimization bug, which would explain your difficulty in reproducing the
problem. Have you tried rebuilding your application with -O1, '-O2
-fno-sched-interblock' or '-O2 -fno-strength-reduce'???
> I was hoping to come up with a nice small proveable case but I just
> could not seem to make things break on demand. and the only other way to
> get this to break would involve kicking 40 customers off line(Not to
> likely).
I hope this helps.
Best Regards,
--George
next prev parent reply other threads:[~2002-10-16 19:18 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-10-15 0:50 unaligned traps question Ram Viswanadha
2002-10-15 1:38 ` Michal Jaegermann
2002-10-15 2:03 ` Uncle George
2002-10-15 15:39 ` George France
2002-10-15 16:46 ` Michal Jaegermann
2002-10-15 18:24 ` alvin
2002-10-15 19:33 ` George France
2002-10-15 19:40 ` Falk Hueffner
[not found] ` <3DAC6EF2.BC962839@voicenet.com>
2002-10-16 18:15 ` alvin
2002-10-16 19:18 ` George France [this message]
2002-10-16 19:45 ` Falk Hueffner
2002-10-16 20:08 ` George France
2002-10-17 18:37 ` Falk Hueffner
2002-10-16 20:23 ` Michal Jaegermann
2002-10-16 21:30 ` alvin
2002-10-17 1:47 ` Uncle George
2002-10-15 18:08 ` Uncle George
2002-10-15 19:29 ` George France
2002-10-15 20:10 ` Uncle George
2002-10-15 20:46 ` George France
2002-10-15 15:33 ` George France
2002-10-17 22:17 ` Ram Viswanadha
2002-10-18 15:36 ` Michal Jaegermann
2002-10-18 17:17 ` Ram Viswanadha
2002-10-18 18:47 ` Michal Jaegermann
[not found] <673E0A4C-E1DF-11D6-AC80-000393768D2C@mcgillsociety.org>
2002-10-17 15:50 ` George France
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox