什么是__KERNEL__用于linux内核?

DaV*_*Vid 14 linux-kernel

谁可以解释下面的代码是什么意思?

如果__KERNEL__未定义,请定义以下宏.何时何地定义__KERNEL__

/* only for userspace compatibility */
#ifndef __KERNEL__

/* IP6 Hooks */
/* After promisc drops, checksum checks. */
#define NF_IP6_PRE_ROUTING  0
/* If the packet is destined for this box. */
#define NF_IP6_LOCAL_IN     1
/* If the packet is destined for another interface. */
#define NF_IP6_FORWARD      2
/* Packets coming from a local process. */
#define NF_IP6_LOCAL_OUT        3
/* Packets about to hit the wire. */
#define NF_IP6_POST_ROUTING 4
#define NF_IP6_NUMHOOKS     5
#endif /* ! __KERNEL__ */
Run Code Online (Sandbox Code Playgroud)

Kar*_*tan 27

编译内核时,__KERNEL__在命令行中定义.

用户空间程序需要访问内核头文件,但内核头文件中的某些信息仅适用于内核.在#ifdef __KERNEL__/#endif块中包装一些语句可确保用户空间程序不会看到这些语句.


ta.*_*.is 7

我用Google搜索__KERNEL__并找到了这个.

__KERNEL__宏被定义,因为还有比包括内核代码的程序(如图书馆),而且是你不希望他们有很多东西.因此大多数模块都希望__KERNEL__启用宏.