对unistd_XX.h感到困惑

时间:2013-07-07 14:59:58

标签: c linux kernel

我正在尝试获取所有系统调用的常量,但内核源代码中include/asm/unistd.hinclude/asm/unistd_XX.hinclude/asm-generic/unistd.h之间似乎存在巨大混乱。

他们每个人之间有什么区别?

如果我想获得,我应该使用哪一个:

a) x86 syscalls
b) x64 syscalls
c) IA32 emulation syscalls

1 个答案:

答案 0 :(得分:0)

因此,正确的方法是将unistd.h用于x64和/或unistd_32.h用于x86ia32。 这些文件位于linux发行版的标题中。但请记住,路径在发行版之间(甚至在内核之间)发生变化,因此找出 正是这些文件的最佳方法是:

uni_hack.h

#if defined(CONFIG_X86)  <---- replace with whatever you want, #ifdef CONFIG_IA32_EMULATION for example
#   include <asm/unistd_32.h>
#endif

-

Kbuild file

obj-m += kernel_module_example.o

$(obj)/kernel_module_example.o: $(obj)/real_unistd.h

$(obj)/real_unistd.h: $(src)/uni_hack.h FORCE
    cpp $(c_flags) -E -dM <$< >$@  <---- this will generate "real_unistd.h" in the directory of your kernel module, and it will contain the content of unistd_32.h

使用unistd.h x64只需#include来源于您的源代码。

相关问题