1. You all Must have root access when login to linux if not then do following.
Login as user in linux. Open new terminal and type this command sudo passwd root o enter user passward, o enter new password, o confirm new password, Reboot and select others from list at login time. enter username = root password = you set new password for root above
When you login from root the administrative rights are open for you 2. Download the latest version of the 3.2.9 Linux kernel, I provided a copy at xeon\Spring 2012\OS-Lab also. 3. Uncompress the kernel and place it in /usr/src/.
4. Create a NewFolder In /usr/src/Linux-3.2.9/
5. Create new C file that would contain new system call lets say “myservice.c” in NewFolder. 6. Define your system call in file myservice.c #include //for linking a system call #include //for the printk asmlinkage long sys_myservice (int arg1) { printk(KERN_EMERG “My Service is Running”); return 1; }
7. Create a Makefile and add following code in it in Newfolder. #####Makefile Start##### obj-y += myservice.o #####Makefile End#######
8. In /usr/src/linux-3.2.9/arch/x86/include/asm/unistd_32.h, define an index for system call. #define __NR_myservice 349
9.
Increment the system call count in same file of step 8. #define NR_syscalls 350
10. /usr/src/linux-3.2.9/arch/x86/kernel/syscall_table_32.S, define a pointer to hold a reference to your system call routine. .long sys_myservice
11. In /usr/src/linux-3.2.9/include/linux/syscalls.h contain the declarations for system calls. Add the following line at the end of the file: asmlinkage long sys_myservice (int arg1);
12. Add directory path of the NewFolder to the Makefile (/usr/src/Linux-3.2.9/Makefile) core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ NewFolder/
13.
Compile Kernel cd usr/src/linux-3.2.9 Enter (make config) Start compiling to create a compressed kernel image (make) Start compiling to kernel modules (make modules) Install kernel modules (make modules_install) Install kernel (make install) Reboot System (reboot)
14. Make a new C file for testing in home directory. 15. Enter following code #include #include #include #include
/* for _syscallX macros/related stuff */ /* for struct sysinfo */
#define __NR_my 349 /* No of your system call in unistd list*/ int main() { int error; error=syscall( __NR_my); /* if return -1 syscall fails*/ printf("code error = %d\n ", error); return 0; }
16. 17. 18. 19.
Compile the file using following command on terminal. gcc file.c –o file.exe Run the file using following command. ./file.exe If your system call executes then it will return 1 else -1. Check in var/log/kern.log file for output.
1. You all Must have root access when login to ... -
Login as user in linux. ⢠Open new terminal and type this command sudo passwd root o enter user passward, o enter new password, o confirm new password,.