开发者

Where do I add a systemcall to the linux Kernel source

开发者 https://www.devze.com 2023-01-21 05:27 出处:网络
I am trying to add a new helloworld system call to a new version of the Linux Ubuntu kernel.I have been looking through the web but I cannot find a consistent example to show me what files I will have

I am trying to add a new helloworld system call to a new version of the Linux Ubuntu kernel. 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.

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.

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

#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: param开发者_如何学运维eter 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


The '_syscall1' macro that you are using is obsolete. Use syscall(2) instead.

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. Straight forward procedure.

0

精彩评论

暂无评论...
验证码 换一张
取 消