DEFINE的定义:
include/linux/kbuild.h
#define DEFINE(sym, val) \
asm volatile("\n->" #sym " %0 " #val : : "i" (val))
offsetof定义:
include/linux/stddef.h
#undef offsetof
#ifdef __compiler_offsetof
#define offsetof(TYPE,MEMBER) __compilter_offsetof(TYPE,MEMBER)
#else
#define offsetof(TYPE, MEMBER) ((SIZE_T) &((TYPE *)0)->MEMBER)
#endif
如果编译器支持offsetof,就直接返回TYPE的位置; 若不支持,则以接收的TYPE为基准位置,求出MEMBER的地址。
举一个例子:
struct machine_desc {
unsigned int nr;/* architecture number*/
const char *name; /* architecture name*/
unsigned long atag_offset; /* tagged list (relative) */
......
}
在arch/arm/kernel/asm-offset.c
DEFINE(MACHINFO_TYPE,offsetof(struct machine_desc,nr));
的含义是:
#define MACHINFO_TYPE 0
#define MACHINFO_NAME 1