现在越来越多的android系统采用64位的kernel,部分外设采用提供so库和jar包的方式给客户进行app的开发。如果早期提供过去的是32位的so库,后期其他项目采用的是64位库,app开发可能会出现不兼容的情况。我们这边就有客户遇到调用我们驱动层的IOCTL一直返回-1,为解决这个问题,我们需要驱动中的IOCTL兼容32位so,具体实现如下:
kernel/msm-4.9/drivers/misc/test-gpio/test_gpio.c
+#ifdef CONFIG_COMPAT
+#include <linux/compat.h>
+#endif
+#ifdef CONFIG_COMPAT
+static long testio_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
+{
+ unsigned long arg64 = (unsigned long)compat_ptr(arg);
+ int err = -1;
+
+ if(!filp->f_op || !filp->f_op->unlocked_ioctl)
+ {
+ printk(KERN_ERR "%s %d: f_op or unlocked_ioctl is null\n", __func__,__LINE__);
+ return -ENOTTY;
+ }
+
+ err = filp->f_op->unlocked_ioctl(filp,cmd,(unsigned long)arg64); // 调用64位的ioctl
+ if(err<0){
+ printk(KERN_ERR "%s %d: unlocked_ioctl fail\n", __func__,__LINE__);
+ }
+
+ return err;
+}
+#endif
static const struct file_operations testio_dev_fops =
.open = testio_open,
.release = testio_release,
.unlocked_ioctl = testio_ioctl,
+#ifdef CONFIG_COMPAT
+ .compat_ioctl = testio_compat_ioctl,
+#endif
};