Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define a function in one linux kernel module and use it in another?

Tags:

linux-kernel

I developed two simple modules to the kernel. Now i want to define a function in one module and after that use it in the other.

How i can do that?

Just define the function and caller in the other module without problems?

like image 788
Ricardo Avatar asked Mar 22 '12 10:03

Ricardo


People also ask

How a module can be used with a kernel?

Kernel modules are pieces of code that can be loaded and unloaded into the kernel upon demand. They extend the functionality of the kernel without the need to reboot the system. A module can be configured as built-in or loadable.

Why we Cannot use C standard library function in kernel module?

Because the GNU C Library which you are familiar with is implemented for user mode, not kernel mode. The kernel cannot access a userspace API (which might invoke a syscall to the Linux kernel).

What is a Linux kernel module and how do you load a new module?

A kernel module is a program which can loaded into or unloaded from the kernel upon demand, without necessarily recompiling it (the kernel) or rebooting the system, and is intended to enhance the functionality of the kernel.

Which command is used to add a loadable kernel module to the Linux kernel or to remove a laudable kernel module from the kernel?

The lsmod command displays the loadable kernel modules that are currently loaded.


1 Answers

Define it in module1.c:

#include <linux/module.h>

int fun(void);
EXPORT_SYMBOL(fun);

int fun(void)
{
    /* ... */
}

And use it in module2.c:

extern int fun(void);
like image 190
cnicutar Avatar answered Sep 20 '22 05:09

cnicutar