How can we share a Hash table between two different kernel modules

假装没事ソ 提交于 2019-12-24 13:53:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!