Registering a System Call

Prepare the kernel 3.8.8 source code. First, add the name of the system call you want to add to the end of syscalls_32.tbl as shown below. Remember the number at this time (351 here). Next, write the prototype at the end of syscalls.h.

$ cd /usr/src/linux-3.8.8
$ sudo vim arch/x86/syscalls/syscall_32.tbl

351   i356   kanako   sys_kanako # Add at the end

$ sudo vim include/linux/syscalls.h

asmlinkage long sys_kanako(void); # Add at the end

System Call Implementation

Write the system call implementation at the end of sys.c. This time, I used printk() to output a message to the console log.

$ sudo vim kernel/sys.c

asmlinkage long sys_kanako(void){
    printk("Cinderella of tea plantation\n")
    return 0;
}

Compilation and Installation

sudo fakeroot make-kpkg --initrd --revision=1.0.mysyscall kernel-image kernel-headers
sudo dpkg -i linux-image-3.8.8_1.0.mysyscall_i386.deb
sudo dpkg -i linux-headers-3.8.8_1.0.mysyscall_i386.deb
sudo reboot

Verification

Call the registered system call using syscall(). After execution, using the dmesg command shows that the message is correctly output.

#include<linux/unistd.h>
#define __KANAKO__ 351 # The number decided at the beginning

int main(void){
    syscall(__KANAKO__);
    return 0;
}
$ dmesg

[ 3197.037948] Cinderella of tea plantation

Reference: Adding a new system call in Linux kernel 3.8.2