staging: android: ashmem: Add support for 32bit ashmem calls in a 64bit kernel
authorSerban Constantinescu <serban.constantinescu@arm.com>
Tue, 5 Mar 2013 15:27:38 +0000 (15:27 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 6 Mar 2013 00:49:43 +0000 (08:49 +0800)
Android's shared memory subsystem, Ashmem, does not support calls from a
32bit userspace in a 64 bit kernel. This patch adds support for syscalls
coming from a 32bit userspace in a 64bit kernel.

The patch has been successfully tested on ARMv8 AEM(64bit
platform model) and Versatile Express A9(32bit platform).

v2: Fix missing compat.h include.

Signed-off-by: Serban Constantinescu <serban.constantinescu@arm.com>
Acked-by: Arve Hjønnevåg <arve@android.com>
Acked-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/android/ashmem.c
drivers/staging/android/ashmem.h

index 38a9135a2f6dbe50cd840376d96b75dec55430b1..e681bdd9aa5f46fb31e2a1390c3559387b333bf2 100644 (file)
@@ -702,6 +702,23 @@ static long ashmem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        return ret;
 }
 
+/* support of 32bit userspace on 64bit platforms */
+#ifdef CONFIG_COMPAT
+static long compat_ashmem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
+{
+
+       switch (cmd) {
+       case COMPAT_ASHMEM_SET_SIZE:
+               cmd = ASHMEM_SET_SIZE;
+               break;
+       case COMPAT_ASHMEM_SET_PROT_MASK:
+               cmd = ASHMEM_SET_PROT_MASK;
+               break;
+       }
+       return ashmem_ioctl(file, cmd, arg);
+}
+#endif
+
 static const struct file_operations ashmem_fops = {
        .owner = THIS_MODULE,
        .open = ashmem_open,
@@ -710,7 +727,9 @@ static const struct file_operations ashmem_fops = {
        .llseek = ashmem_llseek,
        .mmap = ashmem_mmap,
        .unlocked_ioctl = ashmem_ioctl,
-       .compat_ioctl = ashmem_ioctl,
+#ifdef CONFIG_COMPAT
+       .compat_ioctl = compat_ashmem_ioctl,
+#endif
 };
 
 static struct miscdevice ashmem_misc = {
index 1976b10ef93ebedf06b587ee8b6956b99d685e9c..8dc0f0d3adf310b651cf6b17742795ae5269600d 100644 (file)
@@ -14,6 +14,7 @@
 
 #include <linux/limits.h>
 #include <linux/ioctl.h>
+#include <linux/compat.h>
 
 #define ASHMEM_NAME_LEN                256
 
@@ -45,4 +46,10 @@ struct ashmem_pin {
 #define ASHMEM_GET_PIN_STATUS  _IO(__ASHMEMIOC, 9)
 #define ASHMEM_PURGE_ALL_CACHES        _IO(__ASHMEMIOC, 10)
 
+/* support of 32bit userspace on 64bit platforms */
+#ifdef CONFIG_COMPAT
+#define COMPAT_ASHMEM_SET_SIZE         _IOW(__ASHMEMIOC, 3, compat_size_t)
+#define COMPAT_ASHMEM_SET_PROT_MASK    _IOW(__ASHMEMIOC, 5, unsigned int)
+#endif
+
 #endif /* _LINUX_ASHMEM_H */