Re: Module programming - Basic query !

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

 



On Tue, Mar 30, 2004 at 15:30:54 +0530, amith wrote:
> Hi all,
>         Some more module related queries .
> 
> 1)
> i found this declaration   -     extern struct module *module_list;
> (or is it a definition i'am always confused :-) ) in module.h . Now

It's a definition if and only if it creates the object.

(hint: this is a declaration)

> when i include <linux/module.h> this symbol would be part of my
> module . i checked "cat /proc/ksyms | grep "module_list" and
> didnt find it in /proc/ksyms.My question is is it ok to have an
> extern declaration if doesnt exist at all or if it isnt referenced in my 
> program ?

A declaration only says, what type it will be when it's encountered. It
does not generate any output.

> when i insmoded my module "insmod proc1.o" there were no errors so i 
> assume it is ok .
> if no please let me know when it is not ok .

So your module does not have a reference to the symbol (check with nm or
objdump), so there is nothing for insmod to choke on.

> 
> 2)
> My usecount somehow went up and i couldnt rmmod my module so i did this :
> 
> int
> init_module(void)
> {
>    struct module *temp = THIS_MODULE;
>    atomic_t zero;
>    zero.counter = 0;
>    while(temp) {
>    if(strcmp(temp->name,"proc1")==0) /* my module was name proc1.o */
>           {   
>        temp->uc.usecount=zero;
>            return 0;
>       }
>    temp = temp->next;
>       }
> return 0;
> }

This code is a bug. Expect kernel to crash promptly.

Note: THIS_MODULE is guaranteed to be the module structure for your
module, so the while is redundant.

> THIS_MODULE i found was #define THIS_MODULE    (&__this_module)
> Now, how does this (i.e &__this_module) finally point to my modules
> struct module ? How is this done ?

I suppose it's either actualy a function (like current is) or it's
a magical symbol, that is resolved specialy in the loader. I don't know
which one however.

The module use count can be incremented in several ways:

1) Symbol from your module is used when resolving symbols from other
   module.
2) You registered something that has an owner field and it is in use.
3) You incremented the module's count manualy.

I assume that the 3 is not true (you would have known that). So the
first two remain...

If it's the first one, then the module that uses your symbols is named
in square brackets after the use count in lsmod output.

If it's the second one, then you must make sure, that all devices (and
proc files) handled by your module are closed (for a fs driver
filesystems unmounted, for a network driver interfaces deconfigured etc.)

-------------------------------------------------------------------------------
						 Jan 'Bulb' Hudec <bulb@ucw.cz>

Attachment: signature.asc
Description: Digital signature


[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