mirror of
https://github.com/Hizenberg469/Driver-tutorial.git
synced 2026-04-20 00:42:25 +03:00
Character driver finished
This commit is contained in:
41
LKM/hello_func.c
Normal file
41
LKM/hello_func.c
Normal file
@@ -0,0 +1,41 @@
|
||||
#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);
|
||||
Reference in New Issue
Block a user