140 likes | 318 Views
Lab 3 System Call. Operating System Lab. What is a System Call? (1/3). System call provide the interface between a process and an operation system . The mechanism used by an application program to request service from the operating system. What is a System Call? (2/3).
E N D
Lab 3System Call Operating System Lab
What is a System Call? (1/3) • System call provide the interface between a process and an operation system. • The mechanism used by an application program to request service from the operating system NCHU System & Network Lab
What is a System Call? (2/3) • System calls can be grouped roughly into five major categories: • Process control • File management • Device management • Information maintenance • Communications NCHU System & Network Lab
What is a System Call? (3/3) NCHU System & Network Lab
How to Add a System Call (1/9) • STAGE 1: Add system call and then make kernel • The implementation of system calls is within the kernel • Thus, if we add a new system call • Kernel is changed • Re-make and re-install the kernel • STAGE 2 : Add a user program and call system call • Test the correction of our new system call NCHU System & Network Lab
How to add a system call(2/9) • STAGE 1: Make Kernel and add system call • 1. Downlaod new Source Code from www.kernel.org to /usr/src. • 2. [root@localhost~ ]#tar -zxvf linux-2.6.22.6 tar.gz // Un-compress and un-archive NCHU System & Network Lab
How to Add a System Call (3/9) • 3. • Edit file /usr/src/ linux-2.6.22.6 /arch/i386/kernel/syscall_table.S • Put a new system call into system_call_table[root@localhost~ ]#vim /usr/src/ linux-2.6.22.6 /arch/i386/kernel/syscall_table.S • We will see the code like this in this file:.dataENTRY(sys_call_table) .long sys_ni_call /* 0 */ …… • At the bottom of sys_call_table, create a new system call name • For example: • .long sys_myservice/* 324 */ NCHU System & Network Lab
How to Add a System Call(4/9) • 4. • Write the code of the new system call [root@localhost~ ]# vim /usr/src/linux-2.6.22.6/arch/i386/kernel/myservice.c • We want to print “*******This is my new system call********” #include <linux/linkage.h>#include <linux/kernel.h> asmlinkage int sys_myservice(void){printk(“********This is my new system call********\n”);return 0;} NCHU System & Network Lab
How to Add a System Call (5/9) • 5. • Edit file /usr/src/ linux-2.6.22.6 /arch/i386/kernel/Makefile • We need to re-make our kernel so that the new system call can be in effect • Add our new system call file into the kernel’s makefile. • Also compiler the code of new system call when compiling the kernel • [root@localhost~ ]# vim /usr/src/linux-2.6.22.6/arch/i386/kernel/Makefile obj-y += myservice.o NCHU System & Network Lab
How to Add a System Call (6/9) • 6. • build system call 「stub」to allow user program call this system call • [root@localhost~ ]#vim /usr/src/linux-2.6.22.6/include/asm-i386/unistd.h • The content of this file likes this: … #define __NR_io_destroy 246 #define __NR_io_getevents 247 #define __NR_io_submit 248 #define __NR_io_cancel 249…. • Add #define __NR_(name) #define __NR_myservice 324 • The number of total system call is added one#define __NR_syscalls 325 NCHU System & Network Lab
How to Add a System Call (7/9) • 7. • Make new kernel contaning the new system call • make mrproper • remove all generated files + config + various backup files • make menuconfig • Use text mode to select what drivers or modules that we want to use. • make modules • Compile modules • make modules_install • Install modules in /lib/modules/linux-2.6.22 • make • Compile kernel • make install • Install kernel • [root@localhost~ ]# make modules && make modules_install && make && make install NCHU System & Network Lab
How to Add a System Call (8/9) • STAGE 2 : Write a new user program to test the system call • 1. • Write a new user program [root@localhost~ ]#vim testsyscall.c #include <linux/unistd.h>#define __NR_myservice 324 _syscall0(int、myservice); int main (){myservice();return 0;} NCHU System & Network Lab
How to Add a System Call (9/9) • 2. • Compile this file • [root@localhost~ ]#gcc -Wall testsyscall.c -o testsyscall.o • 3. • It’s show time • [root@localhost~ ]#./testsyscall.o NCHU System & Network Lab
Reference • Operation system concepts sixth edition • Wikipedia • http://en.wikipedia.org/wiki/System_call • 鳥哥的 Linux 私房菜 • http://linux.vbird.org/ • Google • Search key word “system call” NCHU System & Network Lab