Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Speaker: I-Wei Chen Operating Systems, Spring 2002 Project #1: Adding a System Call.

Similar presentations


Presentation on theme: "1 Speaker: I-Wei Chen Operating Systems, Spring 2002 Project #1: Adding a System Call."— Presentation transcript:

1 1 Speaker: I-Wei Chen Operating Systems, Spring 2002 Project #1: Adding a System Call

2 2 Agenda Purpose Background General steps to add a system call Testing programs Assignment Deadline Report content

3 3 Purpose Deeper into the Operating System The mechanism of system calls Real-world implementations in Linux and FreeBSD

4 4 Background Interface between the OS and user programs Corresponding to each system call is a library procedure that user programs can call - puts parameters in a specified place - switch CPU mode to kernel mode - so, printf() can’t be used in Linux kernel In Linux, sys_read() read() - ssize_t read (int fd, void *buf, size_t count);

5 5 General steps to add a system call What needs to be done ? - assign an id to the system call - make the kernel aware of the system call - allow user programs to use the system call

6 6 How to do ? In Linux: 1.Assign an id to your system call - /usr/src/linux/include/asm-i386/unistd.h - ex. #define __NR_myhello 364 2.Write source code of your system call - /usr/src/linux/kernel/sys.c - function name must be sys_myhello 3.Put your include files in - /usr/include/sys/ or /usr/include/linux/

7 7 4.Add an entry into system call table - /usr/src/linux/arch/i386/kernel/entry.S - ex..long SYMBOL_NAME(sys_myhello) 5.Rebuild the kernel image and install it 6.Write a test program to test the system call

8 8 In FreeBSD: 1.Assign an id to your system call - /sys/kern/syscalls.master - ex. 364 STD BSD { int sys_myhello (char *buf) } 2.Run “sh makesyscalls.sh syscalls.master” - /usr/src/sys/kern/ - this will create three files: syscall.h, sys-hide.h, and sysproto.h - copy these three files to /usr/include/sys/

9 9 3.Edit your source file, says sys_myhello.c - /usr/src/sys/kern/ - 2 parameters to every system call: pointer to struct proc, and pointer to the user defined system call argument structure - struct sys_myhello_args { char *buf; };

10 10 Ex. #include int syshello(p, uap) struct proc* p; struct syshello_args* uap; { sprintf(uap->buf,"Hello"); /* fill the buffer with Hello */ p->p_retval[0] = 0; /* set the return value of the return 0 system call */ }

11 11 4.Edit /sys/conf/files to add your file sys_myhello.c into it 5.Make a new kernel image and isntall it 6.Write a test program to test the system call

12 12 Testing programs In Linux: #include static inline _syscall0( int, sys_myhello) /* note ‘ _ ’ and no ‘ ; ’ */ int main(int argc,char **argv) { printf("return : %d\n", sys_myhello()); return 0; }

13 13 In FreeBSD: #include intmain(int argc, char **argv) { if (argc != 2) { printf("%s yourname\n", argv[0]); exit(-1); } syscall (364, argv[1] ); }

14 14 Assignment Platform : Linux or FreeBSD Everyone must add an “Hello World” system call Any extra functionality will get some bonus Report: 60 % Implementation: 40 %

15 15 Deadline Demo : 5/9-10 (Thursday and Friday 9AM-6PM) in 701 EECS Research Building Report : turn in when you demo

16 16 Report content How system calls work on Linux or FreeBSD - What’s the instruction (Pentium CPU) that jumps to a previous defined location in the kernel ? - Then, what the procedure at the location do ? - Besides, why we need the “blue” codes in the testing programs How to add a system call Describe your extra functions


Download ppt "1 Speaker: I-Wei Chen Operating Systems, Spring 2002 Project #1: Adding a System Call."

Similar presentations


Ads by Google