[PATCH] Joystick on amd64 for 32bit programs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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/


diff -ru linux-2.6.11/arch/x86_64/ia32/ia32_ioctl.c linux-2.6.11-gentoo-r9-joystick/arch/x86_64/ia32/ia32_ioctl.c
--- linux-2.6.11/arch/x86_64/ia32/ia32_ioctl.c	2005-03-02 08:38:09.000000000 +0100
+++ linux-2.6.11-gentoo-r9-joystick/arch/x86_64/ia32/ia32_ioctl.c	2005-05-19 11:28:11.000000000 +0200
@@ -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)
diff -ru linux-2.6.11/fs/compat.c linux-2.6.11-gentoo-r9-joystick/fs/compat.c
--- linux-2.6.11/fs/compat.c	2005-03-02 08:38:08.000000000 +0100
+++ linux-2.6.11-gentoo-r9-joystick/fs/compat.c	2005-05-24 15:54:59.000000000 +0200
@@ -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);
diff -ru linux-2.6.11/fs/compat_ioctl.c linux-2.6.11-gentoo-r9-joystick/fs/compat_ioctl.c
--- linux-2.6.11/fs/compat_ioctl.c	2005-03-02 08:38:38.000000000 +0100
+++ linux-2.6.11-gentoo-r9-joystick/fs/compat_ioctl.c	2005-05-19 11:28:11.000000000 +0200
@@ -11,7 +11,8 @@
  */
 
 #ifdef INCLUDES
+#include <linux/joystick.h>
 #include <linux/config.h>
 #include <linux/types.h>
 #include <linux/compat.h>


-- 
Isn't making a smoking section in a restaurant like making a peeing
section in a swimming pool?

Attachment: pgplCGeHRSwyv.pgp
Description: PGP signature


[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]
  Powered by Linux