Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call functions and variables from the kernel module (A) in the kernel module (B) and then send notification to the user space?

Tags:

c

linux-kernel

I'm developing an application (user space) which send notifications of value changes via network.

I want to develop a kernel module (A) in order to notify my application (user space) in case of value change in a parameter in other kernel module (B).

  1. How to send signal from the kernel module (A) to my user space application ?
  2. How to send data from the kernel module (A) to my user space application ?
  3. How to call functions and variables from the kernel module (A) in the kernel module (B)?
like image 639
MOHAMED Avatar asked Nov 04 '22 02:11

MOHAMED


1 Answers

Accessing module B from module A

Define a header in module B like a normal C header that includes the variables/functions that A wants to use, and of course #include it in A.

In one of the source files of B, write:

EXPORT_SYMBOL(your_symbol);

for each of the variables/functions.

In the Makefile of module A, make sure you add the path to Module.symvers of B in the KBUILD_EXTRA_SYMBOLS to get rid of dependency warnings and be able to load the module if your kernel has been configured with CONFIG_MODVERSIONS

Signalling a user-land process

Honestly, this one I don't know much. I personally code with a real-time extension of Linux (RTAI) for my work and I have facilities that I don't think exist in plain Linux. These facilities are shared memory (between kernel and user), and shared semaphores (again between kernel and user) and the like. If you could find such a thing in Linux, then you can use it.

If those are not available (which I believe they are not), you can always simply write a /sys or /proc file that outputs a simple 0/1 showing whether the user-space application needs to be signalled or not. Then the user-space application can poll this file.

like image 194
Shahbaz Avatar answered Nov 09 '22 10:11

Shahbaz