How to invoke any kernel function?

夙愿已清 提交于 2019-12-22 14:47:42

问题


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.

How can I achieve that?

Updated:

Note: I want to invoke any kernel function inside my kernel module and not from any user space application.


回答1:


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.

Example

Function definition (i2c_smbus_read_byte_data)
http://lxr.free-electrons.com/source/drivers/i2c/i2c-core.c#L2689

Used here
http://lxr.free-electrons.com/source/drivers/i2c/i2c-core.c#L350




回答2:


Kernel functions cannot be simply invoked from applications that live in user space. System calls are the only functions in user space that can request kernel services.

To call kernel functions directly, if you are interested in kernel programming, you must implement a kernel module. This is a starting point.

EDIT


As you have specified that you want to call kernel functions from within a module, then there is no problem at all. Just follow the link I posted above for the documentation.



来源:https://stackoverflow.com/questions/34977233/how-to-invoke-any-kernel-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!