所以,正确的方法是使用unistd.h
用于x64
和/或unistd_32.h
为x86
和ia32
。这些文件位于你的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 <$< >[email protected] <---- 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
上的事情 - 在你的源代码中。