Question

I'm investigating the Linux kernel where I came across multiple functions that have the following syntax. I'm confused about what this syntax means. I'm not interested what the function does, but what the syntax means.

static int __init customize_machine(void)
{
    ...
    return 0;
}

Here, __init is a macro. It says return 0, so it returns an int, but what is the __init macro doing there?

Also, the macros are found at the end of the function name declaration:

static noinline void __init_refok rest_init(void) __releases(kernel_lock)
{
    ...
}

Same question: what is the purpose of this macro?

Was it helpful?

Solution

This function is a part of a linux kernel module. The __init macro can be found in linux/module.h. Use it like module_init(customize_machine) and becomes the init function of the module. Returning 0 means the module is loaded successfully.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top