我在哪里添加系统调用到linux内核源代码

mol*_*man 5 linux operating-system linux-kernel

我正在尝试向新版本的Linux Ubuntu内核添加一个新的helloworld系统调用.我一直在浏览网页,但是我找不到一个一致的例子来向我展示我将要修改的文件,以便将helloworld系统调用添加到内核中.

我已经尝试了很多并且发生了编译错误.我知道如何编译内核,但我只是不知道我在哪里添加我的程序系统调用,以及我将此调用添加到系统调用表以及我必须做的任何其他事情.

我正在研究最新的Linux Ubuntu内核.

我编译内核时引入了一个新的系统调用,一个名为mycall的简单调用,现在我在应用程序的头文件中得到编译错误,将测试调用,下面是我的头文件

#include<linux/unistd.h>

#define __NR_mycall 317

_syscall1(long, mycall, int, i)
Run Code Online (Sandbox Code Playgroud)

这是我得到的语法错误

stef@ubuntu:~$ gcc -o testmycall testmycall.c
In file included from testmycall.c:3:
testmycall.h:7: error: expected declaration specifiers or ‘...’ before ‘mycall’
testmycall.h:7: error: expected declaration specifiers or ‘...’ before ‘i’
testmycall.c: In function ‘_syscall1’:
testmycall.c:7: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
testmycall.h:7: error: parameter name omitted
testmycall.h:7: error: parameter name omitted
testmycall.c:11: error: expected ‘{’ at end of in
Run Code Online (Sandbox Code Playgroud)

我从Nikolai N Fetissov的以下链接得到了很多帮助

Ole*_*huk 3

您使用的“_syscall1”宏已过时。请改用 syscall(2)。

例子:

#include <stdio.h>
#include <linux/unistd.h>
#include <sys/syscall.h>

#define __NR_mysyscall     317

int main(void)
{
        long return_value;

        return_value = syscall(__NR_syscall);

        printf("The return value is %ld.\n", return_value);

        return 0;
}
Run Code Online (Sandbox Code Playgroud)