没有类型声明的linux内核代码不是注释,这是什么意思?

joa*_*ira 2 c linux linux-kernel

我正在阅读 Linux 的源代码,并且遇到了以下部分:

/*
 * This begins the randomizable portion of task_struct. Only
 * scheduling-critical items should be added above here.
 */
randomized_struct_fields_start

void                *stack;
refcount_t          usage;
/* Per task flags (PF_*), defined further below: */
unsigned int            flags;
unsigned int            ptrace;
Run Code Online (Sandbox Code Playgroud)

我对“randomized_struct_fields_start”感到困惑,它只是一些没有“;”的松散文本,没有数据类型声明,“//”或“/**/”...有人知道这是什么吗?我相信我的问题是关于c语言的,而不是linux,如果我错了,请告诉我,我会在其他地方问这个问题。

Kam*_*Cuk 5

Linux 内核在线索引https://elixir.bootlin.com/linux/latest/ident/randomized_struct_fields_start。来自https://elixir.bootlin.com/linux/latest/source/include/linux/compiler-gcc.h#L73:

#if defined(RANDSTRUCT_PLUGIN) && !defined(__CHECKER__)
#define __randomize_layout __attribute__((randomize_layout))
#define __no_randomize_layout __attribute__((no_randomize_layout))
/* This anon struct can add padding, so only enable it under randstruct. */
#define randomized_struct_fields_start  struct {
#define randomized_struct_fields_end    } __randomize_layout;
#endif
Run Code Online (Sandbox Code Playgroud)

来自https://elixir.bootlin.com/linux/latest/source/include/linux/compiler_types.h#L254:

#ifndef randomized_struct_fields_start
# define randomized_struct_fields_start
# define randomized_struct_fields_end
#endif
Run Code Online (Sandbox Code Playgroud)

这是什么?

struct {它是一个在 gcc 编译器上使用展开的宏RANDSTRUCT_PLUGIN,否则不会展开任何内容。

在这种情况下,“扩展”字面意思是“替换”。