I experienced similar problem, but the solution from Joseph's comment didn't work out for me. So, this answer is for those who tried Joseph's one but had not made progress.
Here's steps that I took based on Kernel document
After you put __x64_
in front of the entry point, if you got an error such as
ld: arch/x86/entry/syscall_64.o:(.rodata+0xdc8): undefined reference to `__x64___x64_sys_my_syscall'
ld: arch/x86/entry/syscall_x32.o:(.rodata+0xdc8): undefined reference to `__x64___x64_sys_my_syscall'
make: *** [Makefile:1179: vmlinux] Error 1
then rather then put __x64_
in front of entry point of your syscall, put syscall into both of your arch/x86/entry/syscalls/syscall_64.tbl
and arch/x86/entry/syscalls/syscall_32.tbl
without any prefix such as
- At the `arch/x86/entry/syscalls/syscall_64.tbl`,
441 common my_syscall sys_my_syscall
- At the arch/x86/entry/syscalls/syscall_32.tbl`
441 i386 my_syscall sys_my_syscall
After this, if you still have same problem, then add your syscall into general syscall table: syscall list that shared among several architectures.
Put following in include/uapi/asm-generic/unistd.h
:
#define __NR_my_syscall 441
__SYSCALL(__NR_my_syscall, sys_my_syscall)
Note that the kernel version I used is WSL2-Linux-Kernel-linux-msft-wsl-5.10.60.1
and it's built in x64 architechture.
I'm quite novice in OS and linux kernel, so this is just what worked for me and I don't know the exact mechanisim of it; sorry for no mechanisim explanation.