How to create a linux system call

October 14, 2008

Creating a system call in the kernel to be used by a user-space application isn’t that exotic but requires three basic steps.

The first step is to create the function, to update the header files and to update the system call table.

We will create the function with the asmlinkage modifier, which tells the compiler to pass all function argument on the stack.

A simple system call function could be

asmlinkage int calculate (int a, int b)  { printk (“total\n”); return a+b; }

Now we need to update the header files for the new function in the system call table.

Open the unistd.h file in linux/include/asm/ and add


#define __NR_calculate 110

[/sourcecode]** **

** remember 110 here is the next in numerical order - would be different everytime

After making space for the system call in the header file, we need to now update the system call table “syscall_tables.S” (linux/arch/i386||x86_64/kernel/syscall_table.S


.long sys_getjiffies


recompile the kernel, make the image and reboot // and use your system call :-)