nchu system & network lab lab 3 system call operating system lab

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

Upload: cornelius-barnett

Post on 25-Dec-2015

214 views

Category:

Documents


1 download

TRANSCRIPT

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

NCHU System & Network LabNCHU System & Network Lab

Lab 3Lab 3System CallSystem Call

Operating System Lab

Page 2: NCHU System & Network Lab Lab 3 System Call Operating System Lab

NCHU System & Network LabNCHU System & Network Lab

What is a System Call? (1/3)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

Page 3: NCHU System & Network Lab Lab 3 System Call Operating System Lab

NCHU System & Network LabNCHU System & Network Lab

What is a System Call? (2/3)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

Page 4: NCHU System & Network Lab Lab 3 System Call Operating System Lab

NCHU System & Network LabNCHU System & Network Lab

What is a System Call? (3/3)What is a System Call? (3/3)

Page 5: NCHU System & Network Lab Lab 3 System Call Operating System Lab

NCHU System & Network LabNCHU System & Network Lab

How to Add a System Call (1/9)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

Page 6: NCHU System & Network Lab Lab 3 System Call Operating System Lab

NCHU System & Network LabNCHU System & Network Lab

How to add a system call(2/9)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

Page 7: NCHU System & Network Lab Lab 3 System Call Operating System Lab

NCHU System & Network LabNCHU System & Network Lab

How to Add a System Call (3/9)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  */

Page 8: NCHU System & Network Lab Lab 3 System Call Operating System Lab

NCHU System & Network LabNCHU System & Network Lab

How to Add a System Call(4/9)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;}

Page 9: NCHU System & Network Lab Lab 3 System Call Operating System Lab

NCHU System & Network LabNCHU System & Network Lab

How to Add a System Call (5/9)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 syst

em 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

Page 10: NCHU System & Network Lab Lab 3 System Call Operating System Lab

NCHU System & Network LabNCHU System & Network Lab

How to Add a System Call (6/9)How to Add a System Call (6/9)

– 6. – build system call 「 stub」 to allow user program call this system cal

l• [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

Page 11: NCHU System & Network Lab Lab 3 System Call Operating System Lab

NCHU System & Network LabNCHU System & Network Lab

How to Add a System Call (7/9)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

Page 12: NCHU System & Network Lab Lab 3 System Call Operating System Lab

NCHU System & Network LabNCHU System & Network Lab

How to Add a System Call (8/9)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;}

Page 13: NCHU System & Network Lab Lab 3 System Call Operating System Lab

NCHU System & Network LabNCHU System & Network Lab

How to Add a System Call (9/9)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

Page 14: NCHU System & Network Lab Lab 3 System Call Operating System Lab

NCHU System & Network LabNCHU System & Network Lab

ReferenceReference

• Operation system concepts sixth edition

• Wikipedia– http://en.wikipedia.org/wiki/System_call

• 鳥哥的 Linux 私房菜– http://linux.vbird.org/

• Google– Search key word “system call”