从内核空间执行用户空间函数 [英] Executing a user-space function from the kernel space

查看:38
本文介绍了从内核空间执行用户空间函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 linux 中编写一个自定义设备驱动程序,它必须能够非常快速地响应中断.处理此问题的代码已存在于用户空间实现中,但速度太慢,因为它依赖于软件不断检查中断线的状态.经过一番研究,我发现可以从内核模块中注册这些中断线,并执行由函数指针给出的函数.但是我们要执行的代码是在用户空间中,有没有办法从内核空间模块调用用户空间中的函数?

Im writing a custom device driver in linux that has to be able to respond very rapidly on interrupts. Code to handle this already exists in a user-space implementation but that is too slow as it relies on software constantly checking the state of the interrupt line. After doing some research, I found that you can register these interrupt lines from a kernel module, and execute a function given by a function pointer. However the code we want to execute is in the user-space, is there a way to call a function in the user-space from a kernel space module?

推荐答案

您在从内核调用用户空间函数时不走运,因为内核不知道也不应该知道单个用户空间应用程序函数和逻辑,更不用说每个用户空间应用程序都有自己的内存布局,不允许其他进程或内核以这种方式侵入(共享对象是这里的例外,但您仍然无法利用它来自内核空间).安全模型怎么样,你不应该首先在内核上下文中运行用户空间代码(在内核上下文中它被自动认为是不安全的代码),因为这会破坏内核的安全模型那一瞬间.现在考虑到上述所有内容,再加上许多其他动机,您可能想要重新考虑您的方法并专注于内核 <->用户空间 IPC 和接口、文件系统或用户-mode helper API(阅读下文).

You are out of luck with invoking user-space functions from the kernel since the kernel doesn't and isn't supposed to know about individual user-space application functions and logic, not to mention that each user-space application has its own memory layout, that no other process nor the kernel is allowed to invade in that way (shared objects are the exception here, but still you can't tap into that from the kernel space). What about the security model, you aren't supposed to run user-space code (which is automatically considered unsafe code in the kernel context) in the kernel context in the first place since that will break the security model of a kernel right there in that instant. Now considering all of the above mentioned, plus many other motives you might want to reconsider your approach and focus on Kernel <-> User-space IPC and Interfaces, the file system or the user-mode helper API(read bellow).

不过,您可以使用 用户模式助手 API.以下 IBM DeveloperWorks 文章应该可以帮助您开始使用 usermode-helper Linux 内核 API:

You can invoke user space apps from the kernel though, that using the usermode-helper API. The following IBM DeveloperWorks article should get you started on using the usermode-helper Linux kernel API:

内核 API,第 1 部分:从内核调用用户空间应用程序

这篇关于从内核空间执行用户空间函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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