Re: #define THIS_MODULE - related query ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tuesday 30 March 2004 08:22 am, Amith wrote:
> hi ,
>            but the question still remains - how does THIS_MODULE convert
> itself into the struct module * of the module where
>            it is declared ?  .
> 
>           #define THIS_MODULE (&__this_module).  /* from
> <linux/module.h> */
> 
> 
> 
>           int init_module (void)
>         {
>                 struct module *mine = THIS_MODULE ;
>                 ......
>          }
> 
> could someone explain ?
> 

If you look further down in include/linux/module.h you will see the
definition of __this_module:

#ifdef MODULE
extern struct module __this_module;
#ifdef KBUILD_MODNAME
/* We make the linker do some of the work. */
struct module __this_module
__attribute__((section(".gnu.linkonce.this_module"))) = {
        .name = __stringify(KBUILD_MODNAME),
        .init = init_module,
#ifdef CONFIG_MODULE_UNLOAD
        .exit = cleanup_module,
#endif
};
#endif /* KBUILD_MODNAME */
#endif /* MODULE */

KBUILD_MODNAME is set to the name of the resulting module (like psmouse)
and "linkonce" stuff takes care of multiple copies.

-- 
Dmitry

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux