On 28-11-07 11:46, Robert P. J. Day wrote:

  based on a book i'm reading, apparently i can write a loadable
module whose entire source file is nothing more than:

=====
#include <linux/module.h>
#include <linux/jiffies.h>

module_param(jiffies, uint, 444) ;

MODULE_LICENSE("Dual BSD/GPL");
=====

  as you can see, its entire purpose is to make the internal value
"jiffies" available to me under /sys/module and, sure enough, using
the standard kbuild structure, it builds and loads and seems to work.

  but i wasn't aware that you could write a valid loadable module
without at least a call to module_init().  in fact, from
include/linux/init.h:

/* Each module must use one module_init(), or one no_module_init */

  clearly, i'm not doing that.  so, should i have been surprised that
the above is a valid loadable module?  why does it load without a call
to module_init() that returns a success value of zero?

Due to:

=== kernel/module.c

asmlinkage long sys_init_module(...)
{
        [ ... ]

        int ret = 0;

        [ ... ]

        /* Start the module */
        if (mod->init != NULL)
                ret = mod->init();
        if (ret < 0) {
                [ ... ]
        }

        /* Now it's a first class citizen! */
        mutex_lock(&module_mutex);

        [ ... ]
}

That is --- the above quoted comment is incorrect. A module can certainly do without a module_init() function (mod->init == NULL).

(mod->init is set from the module struct in the .gnu.linkonce.this_module section inside the module itself).

Rene.


--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to [EMAIL PROTECTED]
Please read the FAQ at http://kernelnewbies.org/FAQ

Reply via email to