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

在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)

https://stackoverflow.com/questions/8832114/

相关文章:

linux - 如何在不保留目录结构的情况下 tar 目录?

linux - 提取并删除目录中的所有.gz - Linux

python - UnicodeEncodeError : 'charmap' codec can'

linux - 使用 Bash 按列拆分命令输出?

linux - 如何在登录后将 SSH 用户限制为一组预定义的命令?

.net - Raspberry Pi 上的单声道

python - 如何计算 NumPy bool 数组中真实元素的数量

python - 资源,客户端和 session 之间的boto3差异?

python - 为什么两个相同的列表有不同的内存占用?

linux - 我应该使用 libc++ 还是 libstdc++?