5

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)?
Sam DeHaan
  • 10,246
  • 2
  • 40
  • 48
MOHAMED
  • 41,599
  • 58
  • 163
  • 268
  • Possible duplicate of [How to define a function in one linux kernel module and use it in another?](http://stackoverflow.com/questions/9820458/how-to-define-a-function-in-one-linux-kernel-module-and-use-it-in-another) – Ciro Santilli OurBigBook.com May 20 '17 at 12:26

1 Answers1

2

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.

Shahbaz
  • 46,337
  • 19
  • 116
  • 182