How to invoke any kernel function?

2019-05-26 01:17发布

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.

2条回答
SAY GOODBYE
2楼-- · 2019-05-26 01:37

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.

查看更多
时光不老,我们不散
3楼-- · 2019-05-26 01:40

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

查看更多
登录 后发表回答