私のPython(2.7.3)コードでは、long int(64ビット)を引数として受け入れるioctl呼び出しを使用しようとしています。私は64ビットシステム上にあるので、64ビットintはポインタと同じサイズです。fcntl.ioctl()の64ビット引数
私の問題は、Pythonは、fcntl.ioctl()呼び出しの引数として64ビットintを受け入れていないようです。それはうれしく32ビットのintまたは64ビットのポインタ - を受け入れますが、私が必要とするのは64ビットのintを渡すことです。
ここに私のioctlハンドラがあります:既存のCコードで
static long trivial_driver_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
long err = 0;
switch (cmd)
{
case 1234:
printk("=== (%u) Driver got arg %lx; arg<<32 is %lx\n", cmd, arg, arg<<32);
break;
case 5678:
printk("=== (%u) Driver got arg %lx\n", cmd, arg);
break;
default:
printk("=== OH NOES!!! %u %lu\n", cmd, arg);
err = -EINVAL;
}
return err;
}
、私はこのような呼び出しを使用:Pythonで
static int trivial_ioctl_test(){
int ret;
int fd = open(DEV_NAME, O_RDWR);
unsigned long arg = 0xffff;
ret = ioctl(fd, 1234, arg); // ===(1234) Driver got arg ffff; arg<<32 is ffff00000000
arg = arg<<32;
ret = ioctl(fd, 5678, arg); // === (5678) Driver got arg ffff00000000
close(fd);
}
を、私は、デバイスファイルを開き、私が取得します以下の結果:Pythonはメートルを渡すことができます任意の方法は
>>> from fcntl import ioctl
>>> import os
>>> fd = os.open (DEV_NAME, os.O_RDWR, 0666)
>>> ioctl(fd, 1234, 0xffff)
0
>>> arg = 0xffff<<32
>>> # Kernel log: === (1234) Driver got arg ffff; arg<<32 is ffff00000000
>>> # This demonstrates that ioctl() happily accepts a 32-bit int as an argument.
>>> import struct
>>> ioctl(fd, 5678, struct.pack("L",arg))
'\x00\x00\x00\x00\xff\xff\x00\x00'
>>> # Kernel log: === (5678) Driver got arg 7fff9eb1fcb0
>>> # This demonstrates that ioctl() happily accepts a 64-bit pointer as an argument.
>>> ioctl(fd, 5678, arg)
Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
ioctl(fd, 5678, arg)
OverflowError: signed integer is greater than maximum
>>> # Kernel log: (no change - OverflowError is within python)
>>> # Oh no! Can't pass a 64-bit int!
>>>
ありますy ioctl()の64ビット引数?
可能であれば、再現可能な例を提供するのに役立ちます。'ioctl()'コールがデバイス固有であることを考えると、実際のリクエストコードに 'IOC_GET_VAL'を代入することで、これをテストするのが難しくなります。 – Aya
@Aya:コメントありがとう。私はデバイス・ドライバーが初めてで、些細でありながら機能的な例を構築するのに少し問題があります。しかし、私は何ができるかを見ていきます。 :) – Ziv
その間、私は 'ctypes'ベースのソリューションを投稿しました。 – Aya