what is __init in linux kernel code.

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Hi,
I was looking in linux kernel file init/main.c
what is the __init in this declaration
"static void __init profile_setup(char *str, int *ints);"

also is there any special purpose to put underscore (_) or double
underscore (__) before varible or function name?

Thanks in Advance .
Anil Gupta


Re: what is __init in linux kernel code.
Quoted text here. Click to load it
I have no idea, but in python the __ (double underscore) preceding a
function name says.. "special function" .. you would do that for main
function (even though it would be "__main__").

Now __init__ in python is just the constructor of a class.

Now taking a better look at your question makes me think that what I
just said does not apply and that __init is just a gcc keyword which
does something... mysterious.

Re: what is __init in linux kernel code.

Quoted text here. Click to load it

__init is a makro defined in (/usr/src/linux/)include/linux/init.h
Read the comments there about the usage of __init.




Re: what is __init in linux kernel code.
Hi Anil,

Quoted text here. Click to load it

These are only macros to locate some parts of the linux code into special
areas in the final executing binary.
__init for example (or better the __attribute__ ((__section__
(".init.text"))) this macro expands to) instructs the compiler to mark this
function in a special way. At the end the linker collects all functions
with this mark at the end (or begin) of the binary file. When the kernel
starts, this code runs only once (initialization). After it runs, the
kernel can free this memory to reuse it and you will see the kernel
message:
  Freeing unused kernel memory: 108k freed

To use this feature, you need a special linker script file, that tells the
linker where to locate all the marked functions.
(see arch/arm/kernel/vmlinux.lds.S)

Quoted text here. Click to load it

Only to avoid name conflicts.

JB

Re: what is __init in linux kernel code.

Quoted text here. Click to load it

The __init macro tells the compiler that the associate function or
variable is used only upon initialization. The compiler places all code
marked with __init into a special memory section that is freed after
the initialization phase ends.

HTH

Zhen Wang


Site Timeline