Search code examples
linuxlinux-kernelkprobe

How to invoke any kernel function?


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.


Solution

  • 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