ioctl返回-1解决方法

ioctl返回值为-1,明明很正常的一个驱动,在别的地方都能正常跑,居然有问题;一直百思不得其解,开内核log,居然没有执行到驱动设备Ioctl函数里面,第一时间想到的就是参数对不上,继续查找,发现没有问题,参数注册都正常,char驱动open\read\write接口都没有问题,居然只有这个ioctl有问题;继续跟踪file_operations结构,发现在这个结构中存在compat_ioctl,自从ioctl随着BKL退出历史的舞台之后,一直用到的是unlock_ioctl,这个compat_ioctl到底是干嘛的呢?本着对问题的研究精神,不放过任何一个可能性,我决定扒一扒compat_ioctl来历;
long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
在./Documentation/filesystems/vfs.txt中有一段描述:compat_ioctl: called by the ioctl(2) system call when 32 bit system calls are used on 64 bit kernels.
正常的情况下,对Ioctl的调用,会走unlock_ioctl,但在32位系统64位的内核上面会走compat_ioctl接口,这就是compat_ioctl存在的意义,由于我使用的Android系统位32位,内核编译的是Arm64,这应该就是这个Bug产生的原因,果断替换位compat_ioctl,问题解决

猜你喜欢

转载自blog.csdn.net/bhj1119/article/details/77994043
今日推荐