64位Android系统驱动兼容32位库调用ioctl接口

现在越来越多的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
 };

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值