我正在尝试在 Linux 中编写系统调用。我修改了unistd.h , syscall_32.tbl和 sys.c分别如下:
/*
#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;
}
编译内核后,我使用
syscall(223, 10000); ,返回值为
-1 ,以及
errno是
38 ,即该功能未实现。你对此有什么想法吗?
请您参考如下方法:
这是因为 syscall没有像名字所暗示的那样实现。在您的情况下,您的机器可能是 64 位的。所以你必须更改文件syscall_64.tbl不是 syscall_32.tbl .
在定义通用系统调用的文件的最后一行添加一行
x common zslhello sys_zslhello
在哪里
x是 1 加上公共(public)区域中的最后一个值。这就是我的
syscall_64.tbl 的片段好像。
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
就我而言
x是 332。干杯!




