c - Linux内核代码中的__init是什么意思?

标签 c linux

在Linux内核源代码中我找到了这个函数:

static int __init clk_disable_unused(void) 
{
   // some code
}

这里看不懂__init是什么意思。

最佳答案

include/linux/init.h

/* These macros are used to mark some functions or 
 * initialized data (doesn't apply to uninitialized data)
 * as `initialization' functions. The kernel can take this
 * as hint that the function is used only during the initialization
 * phase and free up used memory resources after
 *
 * Usage:
 * For functions:
 * 
 * You should add __init immediately before the function name, like:
 *
 * static void __init initme(int x, int y)
 * {
 *    extern int z; z = x * y;
 * }
 *
 * If the function has a prototype somewhere, you can also add
 * __init between closing brace of the prototype and semicolon:
 *
 * extern int initialize_foobar_device(int, int, int) __init;
 *
 * For initialized data:
 * You should insert __initdata between the variable name and equal
 * sign followed by value, e.g.:
 *
 * static int init_variable __initdata = 0;
 * static const char linux_logo[] __initconst = { 0x32, 0x36, ... };
 *
 * Don't forget to initialize data not at file scope, i.e. within a function,
 * as gcc otherwise puts the data into the bss section and not into the init
 * section.
 * 
 * Also note, that this data cannot be "const".
 */

/* These are for everybody (although not all archs will actually
   discard it in modules) */
#define __init      __section(.init.text) __cold notrace
#define __initdata  __section(.init.data)
#define __initconst __section(.init.rodata)
#define __exitdata  __section(.exit.data)
#define __exit_call __used __section(.exitcall.exit)

关于c - Linux内核代码中的__init是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8832114/

相关文章:

c - 用 C 实现指标类型概率函数

c - 主函数中的函数原型(prototype)?

将 X 字节写入文件描述符的正确方法,其中 X 是无符号 64 位整数

c - 如何循环通过标准输入和管道输出到 C 中的子 execl 命令?

c - 对 www.httpbin.org 的错误请求?

linux - 递归查找并复制到其他目录

linux - Windows 与 Linux 缓冲区溢出

c# - 如何 P/调用分配并返回指向新数组的指针的函数

linux - 在函数中维护变量——全局变量

linux - glWindowPos2i 未在此范围内声明