THIS_MODULE in Linux Device Drivers

What is THIS_MODULE?

Whenever you create a kernel module, the kernel's build machinery generates a struct module object for you, and makes THIS_MODULE point to it.

This struct contains many fields, some of which can be set with module macros such as MODULE_VERSION.



You can see from the definition of THIS_MODULE macro that it is referring to '__this_module'. This is defined when we build the module file by running 'make'

Let's write a sample module which prints the module name and version using THIS_MODULE.

Output:



You can see from the above screenshot, after running "make", it generated temporary files as well as the module(.ko). The *.mod.c file has struct module __this_module defined.


Comments

  1. Hi thanks, could you please give information on udev structure also.

    ReplyDelete
    Replies
    1. Sure will post a series on udev. Thanks for your comment

      Delete

Post a Comment

Popular posts from this blog

bb.utils.contains yocto

make config vs oldconfig vs defconfig vs menuconfig vs savedefconfig

PR, PN and PV Variable in Yocto