简体   繁体   English

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

[英]Where do I add a systemcall to the linux Kernel source

I am trying to add a new helloworld system call to a new version of the Linux Ubuntu kernel. 我正在尝试向新版本的Linux Ubuntu内核添加一个新的helloworld系统调用。 I have been looking through the web but I cannot find a consistent example to show me what files I will have to modify to enable a helloworld system call to be added to the kernel. 我一直在浏览网页,但是我找不到一个一致的例子来向我展示我将要修改的文件,以便将helloworld系统调用添加到内核中。

I have tried many and compile error have occurred. 我已经尝试了很多并且发生了编译错误。 I know how to compile the kernel, but I just don't know where I add my c program system call, and where I add this call to the system call table and anything else I have to do. 我知道如何编译内核,但我只是不知道我在哪里添加我的程序系统调用,以及我将此调用添加到系统调用表以及我必须做的任何其他事情。

I am working on the newest Linux Ubuntu kernel. 我正在研究最新的Linux Ubuntu内核。

I compiled the kernel with a new system call introduced, a simple call called mycall, now I am getting compile errors within the header file of my application that will test the call, below is my header file 我编译内核时引入了一个新的系统调用,一个名为mycall的简单调用,现在我在应用程序的头文件中得到编译错误,将测试调用,下面是我的头文件

#include<linux/unistd.h>

#define __NR_mycall 317

_syscall1(long, mycall, int, i)

This is the syntax error I am getting 这是我得到的语法错误

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

I got a lot of help from the below link from Nikolai N Fetissov 我从Nikolai N Fetissov的以下链接得到了很多帮助

The '_syscall1' macro that you are using is obsolete. 您正在使用的'_syscall1'宏已过时。 Use syscall(2) instead. 请改用syscall(2)。

Example: 例:

#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;
}

2nd chapter, Operating system principles- galvin. 第2章,操作系统原理 - 加文。 Straight forward procedure. 直接的程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM