Linux Device Driver Code to print all the loaded modules along with number of exported symbols
Kernel module in Linux is represented by 'struct module'
The module structure is defined in <linux/module.h>
struct module {
enum module_state state;
/* Member of list of modules */
struct list_head list;
/* Unique handle for this module */
char name[MODULE_NAME_LEN];
.....
unsigned int num_syms;
....
};
The above structure has a linked list embedded in it, through which we can traverse to all the modules present in it
Code:
Output:
The module structure is defined in <linux/module.h>
struct module {
enum module_state state;
/* Member of list of modules */
struct list_head list;
/* Unique handle for this module */
char name[MODULE_NAME_LEN];
.....
unsigned int num_syms;
....
};
The above structure has a linked list embedded in it, through which we can traverse to all the modules present in it
Code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <linux/kernel.h> | |
#include <linux/module.h> | |
MODULE_LICENSE("GPL"); | |
static int module_print_init(void) | |
{ | |
struct module *m = THIS_MODULE; | |
struct list_head *modules; | |
int j = 0; | |
modules = &m->list; | |
modules = modules->prev; | |
printk("%s\n", __func__); | |
pr_info("\n"); | |
list_for_each_entry(m, modules, list) { | |
pr_info("%3d MOD:%20s, symbol exported= %u\n", j++, m->name, m->num_syms); | |
} | |
return 0; | |
} | |
static void module_print_exit(void) | |
{ | |
printk("%s\n", __func__); | |
} | |
module_init(module_print_init); | |
module_exit(module_print_exit); |
Output:
Comments
Post a Comment