是否可以从Linux(ioctl)的内核空间调用用户空间回调函数? [英] Is it possible to call a user-space callback function from kernel space in Linux (ioctl)?

查看:422
本文介绍了是否可以从Linux(ioctl)的内核空间调用用户空间回调函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Linux中扩展ioctl接口,以便用户空间应用程序可以将指向函数的指针发送到内核空间驱动程序?

Is it possible to expand the ioctl interface in Linux so that the user-space application can send a pointer to a function to the kernel space driver?

我特别在考虑以用户可控制的方式处理流的方法,但要在内核中进行处理.这些操作可以附加到内核模块,但这将使开发变得容易得多,因为在开发过程中我不需要弄乱内核.

I'm in particular thinking of ways to handle the stream in user-controllable way but doing it in the kernel. Those operations could be attached to the kernel module but this would make development a lot easier as I wouldn't need to mess with the kernel during development.

更具体地说,这将是以下过程:

More specifically, this would be the process:

  1. 驱动程序将数据读取到缓冲区.
  2. 数据由这些用户定义的函数适当地处理.
  3. 完成了更多处理,可能还包含一些硬件块.
  4. 用户空间应用程序使用数据.

推荐答案

我认为您可以通过让驱动程序提供一个或多个用户空间应用程序打开的字符设备(或块设备)来实现您想要的.

I think you can achieve what you want by having your driver provide one or more character devices (or block devices) that your user space applications opens.

然后,您可以使用 inotify (

Then you could use inotify (linux journal article) for kernel->user space event communication. Ioctl or writing to the device for user space->kernel event communication. Data exchange could also be achieved by reading/writing to one or more device files.

或者,您可以提供/proc或/sys文件系统条目或使用netlink.

Alternatively you can provide /proc or /sys filesystem entries or use netlink.

您还可以考虑 ksocket :

Ksocket是linux 2.6内核模块 提供bsd样式的套接字 接口(即套接字,绑定, 听,连接,接受...) 内核开发人员,以方便他们 Linux内核中的网络编程 空间. ksocket呈现的接口与其等效接口几乎相同 在glibc中,因此即使是新开发人员 内核空间将没有障碍 开发与内核网络相关的 程序.

Ksocket is a linux 2.6 kernel module that provides bsd-style socket interfaces (namely socket, bind, listen, connect, accept, ...) for kernel developers to facilitate their network progaramming in linux kernel space. The interfaces ksocket presents are much the same as their equivalent in glibc, so even new developers for kernel space will have no barrier in developing kernel network-related programms.

这篇关于是否可以从Linux(ioctl)的内核空间调用用户空间回调函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆