1
votes

I am newbie on Kernel Development techniques. I was wondering if there is a way to establish communication between Kernel and Kernel Modules (LKM), once Kernel Modules are dynamically loaded. What I want to do is to call a function from a specific part of the Kernel to send some data, while the kernel module is waiting for it. If the module isn't loaded yet, I was thinking it would cause some trouble because the function isn't yet defined too. So my question is, there is a way of calling a function defined on kernel module from somewhere on the kernel? I couldn't find any sources for this question, so I also wanted to ask you if what I'm trying to do is a bad practice and if there's another way of doing this.

This is what I am trying to do:

  • I have a function on my LKM called "foo (mesg)"
  • I wish to call this function "foo" inside "arch/x86/mm/fault.c" code
  • The purpose is to store these "mesgs" and then collect them in user-space using /proc. That's why I am building a LKM.
2

2 Answers

1
votes

So my question is, there is a way of calling a function defined on kernel module from somewhere on the kernel?

You can do it by creating a callback function in your module and call it using its address. You need to create a function that receives and locally stores a method pointer in arch/x86/mm/fault.c and export it using EXPORT_SYMBOL, lets call it "init_foo(void* fn_ptr)".

In your module, create your callback function and call init_foo to pass its address. Now when ever you want to call your callback function just check to see if you have its address first (!= null), if so, then use it to invoke your callback function.

0
votes

You cannot call functions directly from the user space to the kernel module (like with libc calls and unless your kernel module implements a new system call). However, you can call any function implemented within the kernel or another module which has been exported. (EXPORT_SYMBOL()).

Its best if you are more specific on what your kernel module does, if you intend to get more help.