我遇到麻烦了,我不知道发生了什么。
使用SYSCALL_DEFINE时,我无法添加syscall。每个构建都去:
ld: arch/x86/entry/syscall_32.o:(.rodata+0xc18): undefined reference to 'sys_get_pid_info'
同样适用于64版本
当我做一个普通的原型时,代码实际上正在编译和运行:
asmlinkage long get_pid_info(void)
但是如果我正在使用:SYSCALL_DEFINE0(get_pid_info)
这是4.19版本的Master分支中diff的补丁。
diff --git a/Makefile b/Makefile
index 7a2a9a175756..fe78cd54b7ef 100644
--- a/Makefile
+++ b/Makefile
@@ -970,6 +970,7 @@ endif
ifeq ($(KBUILD_EXTMOD),)
core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/
+core-y += get_pid_info/
vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
$(core-y) $(core-m) $(drivers-y) $(drivers-m) \
diff --git a/arch/x86/entry/syscalls/syscall_32.tbl b/arch/x86/entry/syscalls/syscall_32.tbl
index 3cf7b533b3d1..08e6569134d6 100644
--- a/arch/x86/entry/syscalls/syscall_32.tbl
+++ b/arch/x86/entry/syscalls/syscall_32.tbl
@@ -398,3 +398,4 @@
384 i386 arch_prctl sys_arch_prctl __ia32_compat_sys_arch_prctl
385 i386 io_pgetevents sys_io_pgetevents __ia32_compat_sys_io_pgetevents
386 i386 rseq sys_rseq __ia32_sys_rseq
+387 i386 get_pid_info sys_get_pid_info
diff --git a/arch/x86/entry/syscalls/syscall_64.tbl b/arch/x86/entry/syscalls/syscall_64.tbl
index f0b1709a5ffb..da6c9d0f0c01 100644
--- a/arch/x86/entry/syscalls/syscall_64.tbl
+++ b/arch/x86/entry/syscalls/syscall_64.tbl
@@ -343,6 +343,7 @@
332 common statx __x64_sys_statx
333 common io_pgetevents __x64_sys_io_pgetevents
334 common rseq __x64_sys_rseq
+335 common get_pid_info sys_get_pid_info
#
# x32-specific system call numbers start at 512 to avoid cache impact
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 2ac3d13a915b..a0bff632b8fa 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -1296,4 +1296,7 @@ static inline unsigned int ksys_personality(unsigned int personality)
return old;
}
+
+asmlinkage long sys_get_pid_info(void);
+
#endif
注意:使用普通的protorype,我不需要将其添加到include/linux/syscalls.h
这是我的C Syscall函数:
#include <linux/kernel.h>
#include <linux/syscalls.h>
//asmlinkage long get_pid_info(void) <-- works with it
SYSCALL_DEFINE0(get_pid_info)
{
printk("Hello world !\n");
return 0;
}
现在这是构建的输出(包括我的syscall编译后打印的内容)
[...]
CC get_pid_info/get_pid_info.o
AR get_pid_info/built-in.a
[...]
LD vmlinux.o
MODPOST vmlinux.o
ld: arch/x86/entry/syscall_64.o:(.rodata+0xa78): undefined reference to `sys_get_pid_info'
ld: arch/x86/entry/syscall_32.o:(.rodata+0xc18): undefined reference to `sys_get_pid_info'
make: *** [Makefile:1036: vmlinux] Error 1
感谢您的帮助!我认为这并不难,但是我被困在这里。 最好的问候,巴斯蒂安