Linux Kernel module cannot be called after symbol Export
There are many communication methods between Linux modules. The most convenient method is to export function symbols and then directly call them. However, the module symbol export in the kernel after linux2.6.26 often fails, and the export symbol in one module cannot be called by another module. This makes it a headache to process dependency modules.
1. symbol export Function
Export_symbol ()
The function defined in the export_symbol label applies to all kernels.CodePublic, you can directly call it in your kernel module without modifying the kernel code.
Export_symbol_gpl ()
Export_symbol_gpl is similar to the previous one, but this range is only suitable for calling by GPL-licensed modules.
2. Usage
Add B to call the export function in
[1] Use export_symbol (XXXX) to export functions in the C file or header file of module.
Some compilation options need to be added-dexport_symtab.
[2] using "extern" in Module B to declare a function (for example, extern int XXXX );
Declare that the exported function can be used directly.
In addition, after the export function, you can use Cat proc/kallsyms to view all the export symbols. The T attribute cannot be called. Therefore, if the export symbol is of the T type, therefore, it cannot be directly used by other modules.
3. The problem cannot be exported.
Method 1: After module A is compiled, the module_symvers symbol table file is generated, which contains the correspondence between the function address and the function name. copy the file to B'sSource code.
Then re-compile Module B. In this way, B can call the function A. In the future, the order of Loading modules must be a and B, and the opposite is uninstalled.
Method 2: Put the two modules in a directory for compilation. In fact, it is similar to method 1.
In this way, function calls between two modules can be successfully implemented. For example, if KVM needs to call each other with the driver module, this method can be used. If two modules need to call each other, the driver module function can be exported. The KVM module transmits the function pointer As a callback function to the driver for function call communication.
I remember that this problem has not been well solved since it came out, and it may be a system requirement, and the Linux development team has no intention to deal with it.