Building a kernel module is different from a building any application. If not kernel source, at least you need the kernel headers. In order to build a kernel module, you need to have the kernel source code which is usually found at /usr/src/linux. These specify the module related information and form the module’s signature. This is included for the module version to be compatible with kernel into which the module will be loaded.Īpart from this, we have a macros beginning with MODULE_. File version.h contains the kernel version. Macros module_init() and module_exit() are defined here. module.h includes the module related data structures and APIs. Header file ‘ kernel.h’ is kernel space header file which includes the prototype for printk and other commonly used functions. Macros module_init() and module_exit() are used to specify the constructor and destructor for a module.Įquivalent of printf() in kernel is printk(). So, when will destructor be invoked? Of course, when the module is plugged out of the kernel. Now, as with object oriented programming, constructor is invoked when the the object is instantiated, similarly, over here, constructor is invoked when the module is dynamically loaded into the kernel. skm_init is the constructor and skm_exit is the destructor. Below is the simple kernel module:Īs can be seen, every module has a constructor and destruction function. This is evident from the very first module which we will try. One of the beautiful thing about the kernel is that, though its written in C, but it follows the object oriented concepts.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |