Follow by Email

Total Pageviews

Friday, March 23, 2012

Adding System Call


These are the steps to add system call to the linux kernel

  1. Download source code

  2. Open file linux-2.6.39/arch/x86/kernel/syscall_table_32.S

    add line

    .long sys_add2

  1. Open linux-2.6.39/arch/x86/include/asm/unistd_32.h

After Line

#define __NR_syncfs 344

Add line

#define __NR_add2 345

and also change NR_syscalls to

#define NR_syscalls 346

  1. Now edit linux-2.6.39/arch/x86/include/asm/unistd_64.h

    Find Lines

    #define __NR_syncfs 306

    __SYSCALL(__NR_syncfs, sys_syncfs)

    Add Line

    #define __NR_add2 307


  1. open file linux-2.6.39/include/linux/syscalls.h

    before #endif add

    asmlinkage long sys_add2(int i,int j);

  1. Now create add2.c



    asmlinkage long sys_add2(int i,int j)


    return i+j;


  2. Now open the Makefile in this folder(linux-2.6.39/kernel/Makefile) and find out

    obj-y += groups.o

    Add a new line before this line :

    obj-y += add2.o

  3. Now its Time to compile kernel

    Go to linux-2.6.39/


  4. Start compiling to kernel modules:

$make modules

  1. Install kernel modules

    su -

    $make modules_install

  2. It is time to install kernel itself

    $make install

  3. $update-grub

No comments:

Post a Comment