Driver skeletons
Let's consider the following helloworld
module. It will be the basis for our work during the rest of this chapter.
The helloworld.c
file is as follows:
#include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> static int __init helloworld_init(void) { pr_info("Hello world!\n"); return 0; } static void __exit helloworld_exit(void) { pr_info("End of the world\n"); } module_init(helloworld_init); module_exit(helloworld_exit); MODULE_AUTHOR("John Madieu <[email protected]>"); MODULE_LICENSE("GPL");
Module entry and exit point
Kernel drivers all have entry and exit points: the former correspond to the function called when the module is loaded (modprobe
, insmod
) and the latter are the function executed at module unloading (at rmmod or modprobe -r
).
We all remember the main()
function, which is the entry point for every user space program written in C/C++; it exits when that same function returns. With kernel...