分类: LINUX
2011-04-26 14:59:01
Linux symbol export method:
[1] If we want export the symbol in a module, just use the EXPORT_SYMBOL(xxxx) in the C or H file.
And compile the module by adding the compile flag -DEXPORT_SYMTAB.
Then we can use the xxxx in the other module.
[2] If we want export some symbol in Kernel that is not in a module such as xxxx in the /arch/ppc/fec.c.
Firstly, define the xxxx in the fec.c;
Secondly, make a new file which contain the "extern" define the xxxx(for example, extern int xxxx);
Lastly, in the ppc_ksyms.c we includes the new file, and add the EXPORT_SYMBOL(xxxx).
Then we can use the xxxx.
使用时注意事项:
在使用EXPORT_SYMBOL 的.c文件中 需要 #include
// 先写函数
func_a ()
{
}
//再使用EXPORT_SYMBOL
EXPORT_SYMBOL(func_a);
linux2.6的“/prob/kallsyms”文件对应着内核符号表,记录了符号以及符号所在的内存地址。
模块可以使用如下宏导出符号到内核符号表:
导出的符号可以被其他模块使用,不过使用之前一定要声明一下。EXPORT_SYMBOL_GPL()只适用于包含GPL许可权的模块。
代码演示:
make后,先加在hello模块,再加载test模块。
然后cat /proc/kallsyms | grep integer
显示: