如何调用任何内核函数? [英] How to invoke any kernel function?
问题描述
我知道Kprobes可用于探测任何内核功能.但是,在阅读了其文档之后,我意识到它主要是一种被动实体.它只是将探针放在执行序列的中间.
I know that Kprobes can be used to probe any kernel function. But after going through its documents I realise that it is mostly a kind of passive entity. It simply puts a probe in the middle of an execution sequence.
但是,如果我想直接调用任何内核函数而不用担心执行顺序该怎么办.
But what if I want to invoke any kernel function directly without bothering about the execution sequence.
我该如何实现?
已更新:
注意:我想在我的内核模块中调用任何内核函数,而不是从任何用户空间应用程序中调用.
Note: I want to invoke any kernel function inside my kernel module and not from any user space application.
推荐答案
如果我想直接调用任何内核函数怎么办
what if I want to invoke any kernel function directly
并非所有功能都至少可以直接使用.
Not all functions can be used directly at least.
在您的情况下调用内核函数时,请考虑以下几点.
Consider the following points when calling a kernel function in your case.
-
只有使用 静态函数不能在该文件外部直接使用.
- kernel function from different module can be used only if it is exported using EXPORT_SYMBOL family of macros.
- static functions can't be used directly outside of that file.
示例
函数定义(i2c_smbus_read_byte_data)
http://lxr.free-electrons.com/源/驱动程序/i2c/i2c-core.c#L2689
Function definition (i2c_smbus_read_byte_data)
http://lxr.free-electrons.com/source/drivers/i2c/i2c-core.c#L2689
在这里使用
http://lxr.free-electrons.com/源/驱动程序/i2c/i2c-core.c#L350
Used here
http://lxr.free-electrons.com/source/drivers/i2c/i2c-core.c#L350
这篇关于如何调用任何内核函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!