lkml.org 
[lkml]   [2013]   [Jan]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: ABI violations eventually caused by short sighted coding style
On 01/31/2013 02:20 PM, Jon Pry wrote:
>
> I believe changes should be made to the coding style forcing developers to take
> action. There are a couple of solutions I can think of:
>
> 1. Put the unions at the beginning of structures if possible, or at least put
> them in a position that would ensure 8 byte offset from the beginning of
> the struct. Such as after a u64. Multiple unions should ensure the data[]
> of the preceding unions to be a multiple of 8 bytes.
> 2. Require the data element to be declared as u64[size/8].
> 3. Pack the ioctl structures
>
> My preference is for the former since it does not cause any
> unnecessary padding.
>

"The former" doesn't work when you are talking about a choice of three
elements.

packed structures are *very* expensive to use on some architectures, so
that is not a good solution.

In many, if not most cases, this is actually better handled by having
different ioctl numbers for each version/interface, but if you have to
make it self-contained, it makes most sense to make the common portion a
u64 or explicitly align the union to u64.

Another thing to keep in mind is that it often makes a lot more sense to
have a length member, and skip the problematic union. That way a future
version of the kernel can simply memset() the part of the structure that
isn't initialized, and doesn't need a huge apparatus to keep track of
each individual version.

-hpa





\
 
 \ /
  Last update: 2013-02-01 01:02    [W:0.023 / U:0.132 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site