Joystick on amd64 for 32bit programs
PATCH 1/1 Joystick on amd64 for 32bit programs
Hi,
the patch below makes the joystick on amd64 work for 32bit applications. It was successfully tested by myself with X-Plane [1], SilentWings [2], Quake 3 [3] and quite some other applications.
How it works: as the parameters in 32bit userspace ioctl are compatible with the 64bit kernel, it is sufficient to declare them compatible in ia32_ioctl.c. The JSIOCGNAME ioctl causes a problem as it encodes the length of the return buffer into the ioctl number. This is solved by mapping all of the JSIOCGNAME ioctls to JSIOCGNAME(0).
Patch is below and works for vanilla kernels at least up to 2.6.13.
Bernhard
[1] http://www.x-plane.com/
[2] http://www.silentwings.no/
[3] http://www.idsoftware.com/games/quake/quake3-arena/
arch/x86_64/ia32/ia32_ioctl.c +4 -0
@@ -174,6 +174,10 @@ COMPATIBLE_IOCTL(0x4B50) /* KDGHWCLK - not in the kernel, but don't complain */ COMPATIBLE_IOCTL(0x4B51) /* KDSHWCLK - not in the kernel, but don't complain */ COMPATIBLE_IOCTL(FIOQSIZE) +COMPATIBLE_IOCTL(JSIOCGVERSION) +COMPATIBLE_IOCTL(JSIOCGAXES) +COMPATIBLE_IOCTL(JSIOCGBUTTONS) +COMPATIBLE_IOCTL(JSIOCGNAME(0)) /* And these ioctls need translation */ HANDLE_IOCTL(TIOCGDEV, tiocgdev)
fs/compat.c +11 -2
@@ -49,6 +49,7 @@#include <asm/uaccess.h> #include <asm/mmu_context.h> #include <asm/ioctls.h> +#include <linux/joystick.h> /* * Not all architectures have sys_utime, so implement this in terms
@@ -264,6 +265,8 @@/* ioctl32 stuff, used by sparc64, parisc, s390x, ppc64, x86_64, MIPS */ #define IOCTL_HASHSIZE 256 +#define IOCTL_MASK 0xFFFFFFFF +static struct ioctl_trans *ioctl32_hash_table[IOCTL_HASHSIZE ];static DECLARE_RWSEM (ioctl32_sem);
@@ -272,6 +275,8 @@static inline unsigned long ioctl32_hash (unsigned long cmd) { +if ((cmd & ~IOCSIZE_MASK &IOCTL_MASK ) ==JSIOCGNAME (0 )) + cmd =JSIOCGNAME (0 );return (((cmd >>6 ) ^ (cmd >>4 ) ^ cmd)) %IOCTL_HASHSIZE ; }
@@ -434,6 +439,7 @@int error = -EBADF ;struct ioctl_trans *t;int fput_needed; +unsigned int scmd; filp =fget_light (fd, &fput_needed);if (!filp)
@@ -477,11 +483,14 @@break ; } + scmd = ((cmd & ~IOCSIZE_MASK &IOCTL_MASK ) ==JSIOCGNAME (0 )) ? +JSIOCGNAME (0 ) : cmd; +/* When register_ioctl32_conversion is finally gone remove this lock! -AK */ down_read (&ioctl32_sem); -for (t = ioctl32_hash_table[ioctl32_hash (cmd)]; t; t = t->next) { -if (t->cmd == cmd) +for (t = ioctl32_hash_table[ioctl32_hash (scmd)]; t; t = t->next) { +if (t->cmd == scmd) goto found_handler; }up_read (&ioctl32_sem);
fs/compat_ioctl.c +1 -0
@@ -11,7 +11,8 @@*/ #ifdef INCLUDES +#include <linux/joystick.h> #include <linux/config.h> #include <linux/types.h> #include <linux/compat.h>
Signature · 2 lines
Isn't making a smoking section in a restaurant like making a peeing section in a swimming pool?
Quoted 6 lines · Bernhard Ager
Hi,
the patch below makes the joystick on amd64 work for 32bit applications. It was successfully tested by myself with X-Plane [1], SilentWings [2], Quake 3 [3] and quite some other applications.
Quoted 8 lines
How it works: as the parameters in 32bit userspace ioctl are compatible with the 64bit kernel, it is sufficient to declare them compatible in
ia32_ioctl.c. The JSIOCGNAME ioctl causes a problem as it encodes the length of the return buffer into the ioctl number. This is solved by mapping all of the JSIOCGNAME ioctls to JSIOCGNAME(0).Patch is below and works for vanilla kernels at least up to 2.6.13.
This patch uses the obsolete method of defining compat ioctls. The joydev ioctls are already fixed (using ->compat_ioctl) in more recent kernels.
--
Brian Gerst