Re: kernel module -> non-module

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

 



On Tue, Jul 01, 2003 at 09:53:42PM +0530, Omanakuttan wrote:
> Please don't send me personal mails.
> >
> >I was thinking about to compile the module not as a module rather
> >statically into the kernel.
> >(I don't want to load it with insmod rather is shall be part of vmlinuz.)
> For both modules and statically linked ones, code will remain same.
> you will have to put your module_init and module_exit functions like
> 
> #ifdef MODULE
> module_init(my_mod_init)
> module_exit(my_mod_exit)
> #endif

*WRONG*!
You MUST NOT do that. The code remains _exactly_ the same.

> You will have to call the module init function in one of the 
> initialization functions. I forgot which one is it. Somebody will be 
> able to do this.

Linker script takes care of that. For module, initializer is whatever
is called init_module and destructor whatever is called cleanup_module.
For in-kernel code, initializer is whatever has pointer to it put int
the __initcall.int section. module_init and module_done expand to
apropriate definitions depending on MODULE preprocessor symbol.

You should add __init modifier to your init function and __exit modifier
to your cleanup function. That tells kernel to free the init function
after booting and to not compile the cleanup function at all, while it's
nop when MODULE is defined. Like following:

int __init my_mod_init(void) ...
void __exit my_mod_exit(void) ...

> >>go to the directory in which you want to put your module in linux kernel
> >>source. open Config.in, and add you module's script.
> >>Modify the makefile in the directory to reflect your module addition.
> >>
> 
> To get a choce of module statically linked/dynamically linked, please 
> follow this procedure

-------------------------------------------------------------------------------
						 Jan 'Bulb' Hudec <bulb@ucw.cz>
--
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