Utkal Sinha
Utkal Sinha

Reputation: 1041

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.

Upvotes: 2

Views: 1513

Answers (2)

Jeyaram
Jeyaram

Reputation: 9504

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

Upvotes: 1

terence hill
terence hill

Reputation: 3454

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.

Upvotes: 2

Related Questions