Never forget, kernel modules are, after all, kernel code running with kernel privileges. It's not an application and thus does not have it's entry point as the familiar main() function (that we know well and love). This, of course, begs the question: what are the entry and exit points of the kernel module? Notice, at the bottom of our simple kernel module, the following lines:
module_init(helloworld_lkm_init);
module_exit(helloworld_lkm_exit);
The module_[init|exit]() code is macros specifying the entry and exit points, respectively. The parameter to each is a function pointer. With modern C compilers, we can just specify the name of the function. Thus, in our code, the following applies:
- The helloworld_lkm_init() function is the entry point.
- The helloworld_lkm_exit() function is the exit point.
You can almost think of these entry and exit points as a constructor/destructor pair for a kernel module. Technically...