Linux 设备驱动程序:是否可以将 char* 传递给 unlocked_ioctl?
Linux Device Driver: Is it possible to pass a char* to unlocked_ioctl?
是否可以在不使用包含 char* 大小的结构的情况下将 char* 传递给 unlocked_ioctl?
参数是什么由驱动程序决定。 KDGETLED is one that already exists and is documented as taking char *
. It ends up in vt_do_kdskled 将一个字节写入参数指向的地址。
更新
unlocked_ioctl
是ioctl(2)
系统调用的内部实现。 ioctl(2) 的手册指出:
The third argument is an untyped pointer to memory.
It's traditionally char *argp (from the days before void * was valid C),
因此在具有签名 long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
的 unlocked_ioctl
中,第三个参数被转换为驱动程序指定的任何内容。
您可以在我上面引用的 vt_do_kdskled
示例中看到这一点,其中此参数是接受第 2099 行的单字节结果的情况:
int vt_do_kdskled(int console, int cmd, unsigned long arg, int perm)
{
....
case KDGETLED:
ucval = getledstate();
return put_user(ucval, (char __user *)arg);
这个 arg
参数是通过 vt_ioctl 的 ioctl 调用获得的。它刚刚传递给实现。
是否可以在不使用包含 char* 大小的结构的情况下将 char* 传递给 unlocked_ioctl?
参数是什么由驱动程序决定。 KDGETLED is one that already exists and is documented as taking char *
. It ends up in vt_do_kdskled 将一个字节写入参数指向的地址。
更新
unlocked_ioctl
是ioctl(2)
系统调用的内部实现。 ioctl(2) 的手册指出:
The third argument is an untyped pointer to memory. It's traditionally char *argp (from the days before void * was valid C),
因此在具有签名 long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
的 unlocked_ioctl
中,第三个参数被转换为驱动程序指定的任何内容。
您可以在我上面引用的 vt_do_kdskled
示例中看到这一点,其中此参数是接受第 2099 行的单字节结果的情况:
int vt_do_kdskled(int console, int cmd, unsigned long arg, int perm)
{
....
case KDGETLED:
ucval = getledstate();
return put_user(ucval, (char __user *)arg);
这个 arg
参数是通过 vt_ioctl 的 ioctl 调用获得的。它刚刚传递给实现。