Presentation is loading. Please wait.

Presentation is loading. Please wait.

System Calls: A Kernel Project Hunter Bell CS-550-3 Fall 2003 1.

Similar presentations


Presentation on theme: "System Calls: A Kernel Project Hunter Bell CS-550-3 Fall 2003 1."— Presentation transcript:

1 System Calls: A Kernel Project Hunter Bell CS-550-3 Fall 2003 1

2 Introduction System Call Linkage Generating a New Kernel Function Defining the System Call Number Rebuilding the Kernel Generation and Running of User-space Program Problem encountered with programming exercise 2

3 System Call Linkage Macro (called in user program) Stub (trap instruction) Sys_call_table User space Kernel Function Kernel/Supervisor Space 3

4 What is a Macro? In this case, a predefined function in the Operating System that can be called from user space Generates a system call stub with zero to five parameters For example, generating a system call stub with two parameters: _syscall2(type,name,type1,arg1,type2,arg2); This generates a stub that makes a system call to the kernel function with matching type and name with the argument signature provided 4

5 Generating a New Kernel Function Update System Call Number / Linkage Determine location of body for function Write code for new Function Rebuild Kernel to include new Function 5

6 Defining the System Call Number (entry.S) ENTRY(sys_call_table).long SYMBOL_NAME(sys_ni_syscall)/* 0 - old "setup()" system call*/.long SYMBOL_NAME(sys_exit).long SYMBOL_NAME(sys_fork).long SYMBOL_NAME(sys_read).long SYMBOL_NAME(sys_write).long SYMBOL_NAME(sys_open)/* 5 */ ….long SYMBOL_NAME(sys_ni_syscall)/* streams2 */.long SYMBOL_NAME(sys_vfork) /* 190 */.long SYMBOL_NAME(sys_pedagogictime) /*191 - Hunter Bell*/.rept NR_syscalls-191.long SYMBOL_NAME(sys_ni_syscall) F’n name # of f’ns 6

7 Defining the System Call Linkage (unistd.h) #define __NR_exit 1 #define __NR_fork 2 … #define __NR_vfork 190 #define __NR_pedagogictime 191 New entry in table - for generating a stub 7

8 Source Code for Kernel Function asmlinkage int sys_pedagogictime(int flag,struct timeval *thetime) { /*declarations*/ int write_failed; struct timeval *temp; /*verify we can write to user space*/ write_failed = verify_area(VERIFY_WRITE,thetime,sizeof(thetime)); if(!write_failed) { printk("skelcall: Cannot write into user space"); return 0; }/*end if*/ cli(); /*disable interrupts*/ 8

9 Source Code for Kernel Function cli(); /*disable interrupts*/ /* write into user space the values in xtime */ __copy_to_user(&thetime->tv_sec,&xtime.tv_sec,sizeof(xtime.tv_sec)); __copy_to_user(&thetime->tv_usec,&xtime.tv_usec,sizeof(xtime.tv_usec)); sti(); /*enable interrupts*/ /* verify we can read from user space*/ write_failed = verify_area(VERIFY_READ,thetime,sizeof(thetime)); if(!write_failed) { printk("skelcall: Cannot read from user space"); return 0; } /*copy back from user space into temporary variable for printing*/ temp = NULL; __copy_from_user(&temp->tv_sec,&thetime->tv_sec,sizeof(thetime->tv_sec)); __copy_from_user(&temp->tv_usec,&thetime->tv_usec,sizeof(thetime->tv_usec)); 9

10 Source Code for Kernel Function /*Print time if flag is true*/ if(flag) printk("%s",ctime(temp->tv_sec)); return (!(write_failed)); }//end pedagogictime 10

11 Rebuilding the Kernel 5 steps: make clean make oldconfig make depend make make bzImage 11

12 Rebuilding the Kernel (commands) CommandFunctionality make cleanRemoves old object files and other temporary files in kernel environment make oldconfig Generic form: make Defines logical environment for new kernel – in this case, the same as the older configuration make dependSpecifies compile-order of kernel files makeCompiles all kernel source code into an executable file make bzImage Generic form : make Creates a bootable image of the kernel 12

13 Generation and Running of User- space Program /* **************************************** * Hunter Bell - CS550 * exercise-5 (term project) * this program executes in user space and * makes a system call to kernel space ***************************************** */ #include int main(int argc, char * argv[]) { struct timeval *thetime = (struct timeval *) malloc(sizeof(struct timeval *)); int flag = 1; /* generate a stub for System call for int pedagogictime through a Macro*/ _syscall2(int,pedagogictime,int,flag,struct timeval *,thetime); return 0; }//end main 13

14 Summary – System Call Linkage Macro (called in user program) Stub (trap instruction) Sys_call_table User space Kernel Function 14

15 Problem encountered with creating kernel function memcpy_fromfs() and memcpy_tofs() did not compile, and a grep produced nothing 15

16 Summary System Call Linkage Generating a New Kernel Function Defining the System Call Number Rebuilding the Kernel Generation and Running of User-space Program 16


Download ppt "System Calls: A Kernel Project Hunter Bell CS-550-3 Fall 2003 1."

Similar presentations


Ads by Google