在Linux内核空间中执行程序
如果我想在 Linux 内核空间中执行用户程序(而不是内核模块),我有什么选择?
我看过 KML(内核模式 Linux),但那是特定于 IA-32 架构的。我想要一个跨平台并且可以在嵌入式Linux系统上工作的解决方案。
If I want to execute a user program (not a kernel module) in Linux kernel space, what options do I have?
I have looked at KML(kernel mode linux) but that is specific to IA-32 architecture. I want a solution which is cross platform and can work on embedded linux systems.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
用户程序不在内核空间中执行——这就是它们成为用户程序的原因。
如果您想在内核空间中执行代码,您有两个选择:将其构建到内核中,或使用内核模块加载它。
User programs don't execute in kernel space - that's what makes them user programs.
If you want to execute code in kernel space you have two options: build it in to the kernel, or load it with a kernel module.
call_usr模式助手
call_usrmodehelper
您在另一个问题中写道,您是内核编程的新手。使用 KML 是非常非常规的,并且比以标准方式做事要复杂得多。这会让你的学习变得更加困难。我建议您最好的选择是重新评估为什么要在内核空间中运行用户空间应用程序,并找到不这样做的方法。
做这样的事情可能有充分的理由,但我不清楚这个理由是什么。对于内核开发,您应该了解的一件事是,仅仅因为某件事是可能的,它不一定是应该做的事情。
如果您确实想要一个跨平台解决方案,则必须自己编写。 KML 支持的唯一架构是 IA32 和 AMD64。
You wrote in another question that you are a newcomer to kernel programming. Using KML is highly unconventional, and will be far more complicated that doing things in the standard way. That will make your learning that much more difficult. I would suggest that your best option is reevaluate why you want to run a user space app in kernel space and find way not to do it.
There may be a good reason to do such a thing, but it's not clear to me what that reason could be. One thing you should understand with kernel development is that just because something is possible, it's not necessarily something that should be done.
If you really want a cross platform solution, you'll have to write it yourself. The only architectures supported by KML are IA32 and AMD64.
根据定义,内核编程几乎是特定于平台的,因为不同平台的内核都是不同的。
Kernel programming is pretty much by definition platform specific, since kernels for different platforms are all different.
看看 FemtoLinux。基本上,它是用于嵌入式系统和嵌入式处理器(例如 ARM 和 MIPS)的 KML
Take a look at FemtoLinux. Basically, it is a KML for embedded systems and embedded processors such as ARM and MIPS
如果你想从内核空间启动用户程序,请看一下
run_init_process()。这是内核运行 init 程序的方式。
If you want to start a user program from kernel space, take a look at
run_init_process(). It's the way kernel run the init program.
您可以像引导加载程序执行操作系统一样执行它(请记住,操作系统只是在内核之上执行的一个或多个程序)。按照标准操作,引导加载程序将执行过程连同选择的参数一起传输到内核程序,就像 CLI 程序一样,然后加载
/init
可执行文件或由rdinit< 指定的任何内容。 /code> 参数作为操作系统的主要应用;实际上,这可以是任何程序,只要该应用程序所需的所有并发进程(也称为“服务”)都在运行,正如原始
/init
程序是一个 shell 脚本这一事实所证明的那样同时启动那些必需的进程。另请参阅:
仅供参考:我很清楚这个问题已有十多年历史了,因此要么回答或放弃,尽管这个解决方案当时甚至可用,所以“这是为了后代......”
You could execute it the same way the bootloader executes the operating system (remember, an operating system is just one or more programs executed on top of the kernel). Per standard operation, the bootloader transfers execution to the kernel program along with a selection of parameters, just like a CLI program, and then loads the
/init
executable or whatever is specified by therdinit
parameter as the main application of the operating system; in reality this could be any program, provided that all required concurrent processes (a.k.a. "services") for that application are running, as is demonstrated by the fact that the original/init
program was a shell script that concurrently launched those required processes.See also:
FYI: I'm well aware that this question is more than ten years old and thus either answered or dropped, despite that this solution was even available at that time, so "this is for posterity..."