Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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: 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

like image 911
molleman Avatar asked Nov 05 '22 07:11

molleman


1 Answers

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;
}
like image 136
Oleksandr Kravchuk Avatar answered Nov 10 '22 18:11

Oleksandr Kravchuk