I'm trying to write a system call in Linux. I modified the unistd.h
, syscall_32.tbl
and sys.c
as follows respectively:
/*
#define __NR3264_fadvise64 223
__SC_COMP(__NR3264_fadvise64, sys_fadvise64_64, compat_sys_fadvise64_64)
*/
#define __NR_zslhello 223
__SYSCALL(__NR_zslhello, sys_zslhello)
223 i386 zslhello sys_zslhello
asmlinkage int sys_zslhello(int ret)
{
printk("Hello, my syscall!\n");
return ret;
}
After compiling the kernel, I use syscall(223, 10000);
, the return value is -1
, and the errno
is 38
, i.e., the function is not implemented. Do you have any ideas about this?
This is because the syscall
was not implemented as the name suggests. Probably in your case your machine is a 64-bit one. So you have to change the file syscall_64.tbl
not syscall_32.tbl
.
In the last line of the file where the common syscalls are defined add a line
x common zslhello sys_zslhello
Where x
is 1 plus the last value in common area. This is how a snippet of my syscall_64.tbl
looks like.
330 common pkey_alloc sys_pkey_alloc
331 common pkey_free sys_pkey_free
#
# x32-specific system call numbers start at 512 to avoid cache impact
# for native 64-bit operation.
#
512 x32 rt_sigaction compat_sys_rt_sigaction
513 x32 rt_sigreturn sys32_x32_rt_sigreturn
In my case x
is 332. Cheers!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With