[PATCH libXi] Fix bus error on MIPS N32 for bug #38331.
Mark Kettenis
mark.kettenis at xs4all.nl
Mon Feb 20 12:54:48 PST 2012
> From: =?UTF-8?q?Micha=C5=82=20Mas=C5=82owski?= <mtjm at mtjm.eu>
> Date: Mon, 20 Feb 2012 20:09:30 +0100
>
> XIValuatorClassInfo might have an address of 4 bytes modulo 8, while
> it contains a double which needs 8Â byte alignment. This is fixed by
> adding extra padding before instances of this structure in
> size_classes and copy_classes.
>
> Padding added by other commits probably prevents unaligned accesses on
> all architectures with 8Â byte longs and 8Â byte double alignment
> requirement, so this error occurs only on ABIs with 4Â byte longs and
> 8Â byte required double alignment. I don't know any other such ABI
> than MIPSÂ N32, so the change uses conditionals on ABI-specific macro.
This is issue is by no means MIPS N32-specific. Most 32-bit
architectures will suffer from the same issue. A very similar issue
popped up in the xserver/test/xinput.c, where we eventually settled
for assuming double-alignment on all platforms except __i386__ and
__sh__.
It probably is best to use "sizeof(double)" instead of "8" since that
is a bit more xpressive.
> Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=38331
> Signed-off-by: MichaÅ MasÅowski <mtjm at mtjm.eu>
> ---
> src/XExtInt.c | 13 +++++++++++++
> 1 files changed, 13 insertions(+), 0 deletions(-)
>
> diff --git a/src/XExtInt.c b/src/XExtInt.c
> index b12886d..297b95c 100644
> --- a/src/XExtInt.c
> +++ b/src/XExtInt.c
> @@ -1495,6 +1495,11 @@ size_classes(xXIAnyInfo* from, int nclasses)
> ((xXIKeyInfo*)any_wire)->num_keycodes);
> break;
> case XIValuatorClass:
> +#ifdef _ABIN32
> + /* Avoid a bus error on MIPS N32. */
> + if (len % 8 != 0)
> + len += 8 - len % 8;
> +#endif
> l = sizeDeviceClassType(XIValuatorClass, 0);
> break;
> case XIScrollClass:
> @@ -1598,6 +1603,14 @@ copy_classes(XIDeviceInfo* to, xXIAnyInfo* from, int *nclasses)
> XIValuatorClassInfo *cls_lib;
> xXIValuatorInfo *cls_wire;
>
> +#ifdef _ABIN32
> + /* On MIPS n32 doubles must be 8Â byte aligned, but
> + longs take 4Â bytes, so ptr_lib might be
> + unaligned, causing a bus error when setting
> + cls_lib->min. */
> + if (((size_t) ptr_lib) % 8 != 0)
> + *(unsigned char**) &ptr_lib += 8 - ((size_t) ptr_lib) % 8;
> +#endif
> cls_lib = next_block(&ptr_lib, sizeof(XIValuatorClassInfo));
> cls_wire = (xXIValuatorInfo*)any_wire;
>
> --
> 1.7.9.1
>
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
>
>
More information about the xorg-devel
mailing list