From: Bernhard Ager <ager@in.tum.de>
To: vojtech@suse.cz
Cc: linux-joystick@atrey.karlin.mff.cuni.cz, linux-kernel@vger.kernel.org
Subject: [PATCH] Joystick on amd64 for 32bit programs
Date: Wed, 14 Sep 2005 12:02:44 +0200 [thread overview]
Message-ID: <20050914100244.GC9770@in.tum.de> (raw)
[-- Attachment #1: Type: text/plain, Size: 3627 bytes --]
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 #2: Type: application/pgp-signature, Size: 189 bytes --]
next reply other threads:[~2005-09-14 10:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-09-14 10:02 Bernhard Ager [this message]
2005-09-14 12:53 ` [PATCH] Joystick on amd64 for 32bit programs Brian Gerst
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20050914100244.GC9770@in.tum.de \
--to=ager@in.tum.de \
--cc=linux-joystick@atrey.karlin.mff.cuni.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=vojtech@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox