0
votes

I write a LKM (loadable kernel module), which needs to call functions in another kernel driver module under /linux/driver. I don't know how to import these functions into LKM. As the /lib/modules/linux/ (as make -C option) doesn't contain the header files of the kernel driver, I can't directly include them as the header files. Is there any way to do that?

2

2 Answers

0
votes

Basically, you can only call a function from another module or the kernel if it's explicitly exported by the driver using the EXPORT macro in the source code.

Which kernel driver exactly did you think of ? can't you just copy the code to your driver ?

0
votes

a) As @stdcall points out reg macros, the macros names are EXPORT_SYMBOL and EXPORT_SYMBOL_GPL actually

b) Reg the particular call you'd like to use, I found this as the closest match on kernel ver 4.6 : arch/x86/include/asm/xen/hypercall.h

208 static inline long
209 privcmd_call(unsigned call,
210              unsigned long a1, unsigned long a2,
211              unsigned long a3, unsigned long a4,
212              unsigned long a5)
...

The call is 'static' and not exported; hence you cannot use it in an LKM.

c) As @stdcall points out, you could try copying it, but in my experience this isn't always going to work out as there may be too many dependencies. Some things are delibrately meant to be done only in the inline tree and not as kernel modules..