[PATCH] dix: Really align valuators on doubles.

Cyril Brulebois kibi at debian.org
Tue May 17 23:03:19 PDT 2011


Hi,

Peter Hutterer <peter.hutterer at who-t.net> (18/05/2011):
> 678f5396c91b3d0c7572ed579b0a4fb62b2b4655 introduced alignment on doubles for
> the valuators, 419a27b5219a739f2fbd50cc96a1b54c469e4a88 blindly copied it.
> Alas, it doesn't actually align on doubles.
> 
> 678f5396c works on 64 bit because it switched the assignments of axes and
> axisVals around to have axisVals always point to the first byte after the
> struct. On 64 bit ValuatorClassRec is size 96, so we're aligned anyway.
> All the machines that triggered the previous bug were 64 bit machines.
> 
> On 32 bit server 1.10, ValuatorClassRec is size 52 and no-one noticed except
> one test case that inconveniently kept blowing up.
> 
> Replace with a union that is forced to N * sizeof(double) where N is defined
> by the current size of ValuatorClassRec.
> 

I guess you could mention the bug:
  http://bugs.freedesktop.org/show_bug.cgi?id=36986

> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> ---
>  dix/devices.c |    6 +++++-
>  1 files changed, 5 insertions(+), 1 deletions(-)
> 
> diff --git a/dix/devices.c b/dix/devices.c
> index 9a4498b..367dccd 100644
> --- a/dix/devices.c
> +++ b/dix/devices.c
> @@ -1234,8 +1234,12 @@ ValuatorClassPtr
>  AllocValuatorClass(ValuatorClassPtr src, int numAxes)
>  {
>      ValuatorClassPtr v;
> +    const int sz_dbl = sizeof(double);
>      /* force alignment with double */
> -    union align_u { ValuatorClassRec valc; double d; } *align;
> +    union align_u {
> +        ValuatorClassRec valc;
> +        double d[(sizeof(ValuatorClassRec) + sz_dbl - 1)/sz_dbl];
> +    } *align;
>      int size;
>  
>      size = sizeof(union align_u) + numAxes * (sizeof(double) + sizeof(AxisInfo));

Build-tested on i386 (linux32 chroot on amd64), on top of 1.10 and on
top of master, seems to make the build failure go away, thanks. If
that's enough (as opposed to actually running the server), you can add
my:

Tested-by: Cyril Brulebois <kibi at debian.org>

Mraw,
KiBi.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.x.org/archives/xorg-devel/attachments/20110518/3f0a17e6/attachment.pgp>


More information about the xorg-devel mailing list