--------------------------------------------------------------------------------- Steps to make own system call and compiling kernel --------------------------------------------------------------------------------- Make own system call ---------------------------------------------------------------------- 1) cd KERNELSOURSE/usr/src/linux 2.6.x.x.x/include/asm-x86 2) vi unistd_32.h Add your own systemcall as the last entry #define __NR_yoursyscallname 327 NB:327 if previous entry is 326 3) cd KERNELSOURSE/usr/src/linux 2.6.x.x.x/arch/x86/kernel 4) vi syscall_table_32.c add entry .long sys_yoursyscallname 327 5) cd KERNELSOURSE/usr/src/linux 2.6.x.x.x/kernel 6) vi sys.c write yourown systemm call in this file eg: asmlinkage long sys_yoursyscallname(char __user *name) { printk(KERN_EMERG"\nEntered name is:%s\n",name); return 0; } -------------------------------------------------------------------------------------------------------------- In order to execute your system call you must add it to kernel image. For that compilation of kernel needed. -------------------------------------------------------------------------------------------------------------- 1) Go to usr/src directory in kernel sourse 2) make mrproper //only first time 3) copy configuration file cp arch/x86/defconfig_32 ./.config 4) make clean 5) make cloneconfig Uses settings for already running kernel OR make oldconfig Expert level 6)[optional] make menuconfig menudrivel configuration 7) make 8) make modules_install 9) make install ----------------------------------------------------------------------------------- Reboot the system oopen in your new kernel ------------------------------------------------------------------------------------ create a new file for calling your own system call eg: 1) vi callmysyscall.c /************************************************************************/ /*callmysyscall.c */ /************************************************************************/ #define _GNU_SOURCE /* or _BSD_SOURCE or _SVID_SOURCE */ #include <unistd.h> #include <sys/syscall.h> /* For SYS_xxx definitions */ int main() { int a; syscall(__NR_yoursyscallname,arguments to systemcall[specific to our example a string name]); return 0; } 2) cc callmysyscall.c 3) ./a.out *4) dmesg NB: 4)Specific to our example To see the output Eg:- /************************************************************************/ /*callmysyscall.c */ /************************************************************************/ #define _GNU_SOURCE /* or _BSD_SOURCE or _SVID_SOURCE */ #include <unistd.h> #include <stdio.h> #include <sys/syscall.h> /* For SYS_xxx definitions */ int main(int argc,char* argv[]) { int a; if(argc!=2) { printf("Usage:Give command<space>Your name\n"); return 0; } syscall(__NR_pname_in_dmesg,argv[1]); return 0; }