Presentation is loading. Please wait.

Presentation is loading. Please wait.

NCHU System & Network Lab Lab 3 System Call Operating System Lab.

Similar presentations


Presentation on theme: "NCHU System & Network Lab Lab 3 System Call Operating System Lab."— Presentation transcript:

1 NCHU System & Network Lab Lab 3 System Call Operating System Lab

2 NCHU System & Network 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

3 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

4 NCHU System & Network Lab What is a System Call? (3/3)

5 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

6 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.www.kernel.org –2. [root@localhost~ ]#tar -zxvf linux-2.6.22.6 tar.gz // Un-compress and un-archive

7 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:.data ENTRY(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 */

8 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 #include asmlinkage int sys_myservice(void) { printk(“********This is my new system call********\n”); return 0; }

9 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

10 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

11 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

12 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 #define __NR_myservice 324 _syscall0(int 、 myservice); int main () { myservice(); return 0; }

13 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

14 NCHU System & Network Lab Reference Operation system concepts sixth edition Wikipedia –http://en.wikipedia.org/wiki/System_callhttp://en.wikipedia.org/wiki/System_call 鳥哥的 Linux 私房菜 –http://linux.vbird.org/http://linux.vbird.org/ Google –Search key word “system call”


Download ppt "NCHU System & Network Lab Lab 3 System Call Operating System Lab."

Similar presentations


Ads by Google