Files
Driver-tutorial/LKM/hello_func.c

42 lines
1.1 KiB
C

#include <linux/module.h> // included for all kernel module
#include <linux/kernel.h> // included for KERN_INFO
#include <linux/init.h> // included for __init and __exit macros
void func(void);
EXPORT_SYMBOL_GPL(func);
/**
* EXPORT_SYMBOL_GPL:
* Since, in user space to use variable/function of one
* file to another file we use extern or header file. But
* for kernel space such thing is not allowed. But to use
* variable or function in another module/file we use
* EXPORT_SYMBOL_GPL(<fun or var name>) to export the
* function or variable to global scope for all the modules.
*/
int val = 300;
void func(){
printk(KERN_INFO"func invoked\n ");
printk(KERN_INFO" val = %d \n", val);
}
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Junet Hossain");
MODULE_DESCRIPTION("A Simple Hello World module");
static int __init hello_init(void){
printk(KERN_INFO "Init Hello func module\n");
return 0; // Non-zero return means that the module couldn't be loaded.
}
static void __exit hello_cleanup(void){
printk(KERN_INFO "Cleaning up hello func module.\n");
}
module_init(hello_init);
module_exit(hello_cleanup);