Re: [PATCH] Introduce compat_u64 and compat_s64 types

From: Arnd Bergmann
Date: Fri Jun 15 2007 - 08:04:27 EST

On Friday 15 June 2007, Andi Kleen wrote:
> On Friday 15 June 2007 11:31:37 Arnd Bergmann wrote:
> > One common problem with 32 bit system call and ioctl emulation
> > is the different alignment rules between i386 and 64 bit machines.
> > A number of drivers work around this by marking the compat
> > structures as 'attribute((packed))', which is not the right
> > solution because it breaks all the non-x86 architectures that
> > want to use the same compat code.
> Why does it break them? It should just make them a little slower.
> The network code requires unaligned accesses to work
> anyways so if your architecture doesn't support them it is already
> remotely crashable.

It doesn't break in all cases, but quite often, you have
something like:

struct foo {
__u32 a;
__u64 b;

If you define a

struct compat_foo {
__u32 a;
__u64 b;
} __attribute__((packed));

That is broken on all non-x86 architectures, because it removes the
padding that is inserted on the respective 32 bit platforms, while

struct compat_foo {
__u32 a;
compat_u64 b;

Is a correct definition on all architectures. It also produces
somewhat better code if the architecture does not support unaligned
data access, but that is just an unintended side-effect.

Arnd <><
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at