遍历内核模块中的所有模块 [英] Iterate over all modules in a kernel module
问题描述
我对内核内部可用的变量有些困惑.我该如何遍历自己内核模块中的所有模块?我发现内核代码中使用了modules
.我可以按照以下方式做些什么吗?
I'm a bit confused by the variables available inside the Kernel. How would I go about iterating over all modules inside my own kernel module? I found modules
being used in the kernel code. Can I do something along the lines of
struct module *mod;
list_for_each_entry(mod, &modules, list) {
printk(KERN_INFO "%s\n", mod->name);
}
推荐答案
没有没有直接方法可以遍历模块列表.
There is no direct way for iterate over list of modules.
Head of the module's list is modules
variable, which is statically defined in kernel/module.c, so it is not accessible for code outside of this file.
如果出于调试目的需要模块名称列表,则可以使用WARN_ON()宏或类似的代码:
If list of module's name is needed for debugging purposes, you may use WARN_ON() macro or similar:
WARN_ON(0);
这将打印有关警告的消息和一些其他信息,其中包括模块列表.
this will print message about warning and some additional information, which among other things will contain list of modules.
这篇关于遍历内核模块中的所有模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!