问题
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.
Does extern declaration work here. extern DEFINE_HASHTABLE(...,...)
回答1:
DEFINE_HASHTABLE
is variable's definition. For declare variable (without defining it) use DECLARE_HASHTABLE
:
extern DECLARE_HASHTABLE(my_hash_table, HASH_TABLE_BITS);
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);
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
来源:https://stackoverflow.com/questions/32947545/how-can-we-share-a-hash-table-between-two-different-kernel-modules