我们如何在两个不同的内核模块之间共享哈希表 [英] How can we share a Hash table between two different kernel modules
问题描述
是否可以在另一个内核模块中共享一个内核模块中定义的Hash_table.
Is it possible to share a Hash_table defined in one kernel module in another kernel module.
/*Hash table declarartion and definition*/
DEFINE_HASHTABLE(my_hash_table, HASH_TABLE_BITS);
我正在一个模块中填充此表,但是我也想在另一个模块中访问此表.
I am populating this table in one module, however I would like to access this table in another module as well.
外部声明在这里起作用吗? extern DEFINE_HASHTABLE(...,...)
Does extern declaration work here. extern DEFINE_HASHTABLE(...,...)
推荐答案
DEFINE_HASHTABLE
是变量的定义.对于 declare 变量(未定义),请使用DECLARE_HASHTABLE
:
DEFINE_HASHTABLE
is variable's definition. For declare variable (without defining it) use DECLARE_HASHTABLE
:
extern DECLARE_HASHTABLE(my_hash_table, HASH_TABLE_BITS);
请注意,在Linux内核中,您需要其他步骤才能使一个模块中定义的make变量在另一模块中可用.
Note, that in the Linux Kernel you need additional steps for make variable defined in one module to be usable in the other one.
首先,您需要从模块中导出符号,该符号已定义变量:
First, you need to export symbol from the module, which defined variable:
EXPORT_SYMBOL(my_hash_table);
第二,直到在单个目录(带有单个makefile)中构建两个模块之前,您需要在用于编译其他模块的Makefile
中指定应使用第一个模块中的Module.symvers
文件:
Second, until you build both modules in the single directory(with single makefile) you need to specify in the Makefile
, used for compile other module, that, that it should use Module.symvers
file from the first module:
KBUILD_EXTRA_SYMBOLS := <dir-with-symbol-provider-module>/Module.symvers
这篇关于我们如何在两个不同的内核模块之间共享哈希表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!