I write kernel module which lists all modules loaded in system. But when is end list of modules, loop are working. I tried everything to stop this loop, but finally I cant do this. I added function printk which write module name (it makes kernel oops when tries write name module which doesn`t exist). Can anyone help me? I need list of modules to continue write this module. Source:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/list.h>
struct list_head modules_list;
struct list_head *m;
struct module *ops_mod;
int agh = 0;
char *x = (char) 0;
void list_module(void)
{
modules_list = THIS_MODULE->list;
for(m = (&modules_list)->next; m != (&modules_list); m = m->next) {
printk(KERN_INFO "List iteration %d", agh);
ops_mod = list_entry(m, struct module, list);
if ((m)->next == NULL) {
printk(KERN_WARNING "MISC list: NULL pointer");
return;
}
printk(KERN_INFO "after iteration %d", agh);
printk(KERN_INFO "print name %d", agh);
agh++;
if (&ops_mod->mkobj.kobj.name == NULL)
return;
else {
printk("Adress: %d", ops_mod);
printk("MISC: ok %s", ops_mod->mkobj.kobj.name);
}
//ops_mod = NULL;
}
}
int init_module(void)
{
list_module();
return 0;
}
void cleanup_module(void){}
MODULE_LICENSE("GPL");
m != (&modules_list)). is this a circular list? - Arashlist_for_each(),list_for_each_entry()or similar macro. But all these macros requires head of the list, and you have no access to it (see question stackoverflow.com/questions/43558217/…).THIS_MODULE->listis an element of the list, not a head. - Tsyvarev