在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++相关问答推荐

在x86汇编中,为什么当分子来自RDRAND时DIV会引发异常?

为什么在传输 Big Data 时共享内存段的运行时间比管道更长?

Apple Libm的罪恶功能

Ebpf内核代码:permission denied:invalid access to map value

如何在C中从函数返回指向数组的指针?

将常量转换为指针会增加.数据大小增加1000字节

C lang:当我try 将3个或更多元素写入数组时,出现总线错误

如何创建一个C程序来存储5种动物的名字,并在用户 Select 其中任何一种动物时打印内存地址?

当输入负数时,排序算法存在问题

Make Node函数.S有什么问题吗?

为什么我可以在GCC的标签后声明变量,但不能声明Clang?

使用TCL C API导航到列表中的元素

在libwget中启用Cookie会导致分段故障

为 struct 中的数组动态分配内存时出错

变量的作用域是否在C中的循环未定义行为或实现定义行为的参数中初始化?

试图创建一个基本的Word克隆,但遇到了障碍

如何将两个uint32_t值交织成一个uint64_t?

GETS()在C++中重复它前面的行

在printf()中用%.*S格式填充长度为0的字符串是否会调用任何UB?如果是,是哪一个?

将数组返回到链表