5

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

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
molleman
  • 2,934
  • 16
  • 61
  • 92
  • What did you try? What compile errors occurred? [Is this still homework?](http://stackoverflow.com/questions/3977675/i-need-information-on-system-calls-and-understanding-them) - please tag as such if so. The article linked in the answer to that question is good for general principles, I think, although a bit out-of-date, as kernel development tends to moves rapidly. A tip: things that used to be in `arch/i386` in older versions are now in `arch/x86` (the 32-bit and 64-bit stuff got merged). [LXR](http://lxr.linux.no/linux) is useful for searching either current or old kernel versions. – Matthew Slattery Oct 22 '10 at 23:06
  • http://tldp.org/HOWTO/html_single/Implement-Sys-Call-Linux-2.6-i386/ – Nikolai Fetissov Oct 22 '10 at 23:07
  • i got rid of the compile error by accident , i will try again and if it comes up i will edit the post with the error, ok cheers for the advice on arch/x86, will be trying this now, will be back in about an hour when i get all this done and the compiling aswell!!!!! – molleman Oct 22 '10 at 23:12

2 Answers2

3

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;
}
Oleksandr Kravchuk
  • 5,963
  • 1
  • 20
  • 31
-1

2nd chapter, Operating system principles- galvin. Straight forward procedure.

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
Abhijit
  • 19
  • 5
  • 1
    Please do not include a 'signature' when posting; your user box already shows your name. Also... I'm not sure what this answer means. – Andrew Barber Oct 30 '12 at 12:21