nutt exercise v pp 107 n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
System Calls PowerPoint Presentation
Download Presentation
System Calls

Loading in 2 Seconds...

play fullscreen
1 / 12

System Calls - PowerPoint PPT Presentation


  • 248 Views
  • Uploaded on

Nutt Exercise V, pp. 107. System Calls. Goal. Learn how to make a system call Learn about reading/writing user space from the kernel This is done by adding a new function to the kernel The function itself is trivial, it just returns the value of xtime. System Calls.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'System Calls' - mireya


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
slide2
Goal
  • Learn how to make a system call
  • Learn about reading/writing user space from the kernel
  • This is done by adding a new function to the kernel
  • The function itself is trivial, it just returns the value of xtime
system calls
System Calls
  • A syscall is the name of a kernel function that's exported for use by user-space programs
  • Kernel functions that appear on the system call interface can't be called directly like an ordinary function
  • Instead they must be called indirectly via the trap table
  • Thus if you write a new kernel function , then you need to create a new entry in the kernel trap table to reference the new function
slide4
Stub
  • If user-space programs are to call the program like they do any other system call, then you need to provide a system call STUB function (that contains the trap instruction)
  • Strictly speaking, you can avoid creating the system call stub by using the system_call( ) routine (see section 5.1.3)
the system call linkage
The System Call Linkage
  • A user-space program calls a system call stub, which contains a trap instruction
  • As a result, the CPU switches to supervisor mode and begins to execute at a specified location in kernel space
  • In the i386 hardware, the trap instruction actually causes interrupt 0x80 to occur, with the ISR address pointing at the entry point of the system_call( ) assembly-language routine
  • See arch/i386/kernel/entry.S
the entry s code
The entry.S Code

.data

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 */

  • Entry 1 contains the address of the exit( ) system call (the kernel function named sys_exit)
  • Entry 2 contains the address of fork( ),
  • Etc.
steps taken by system call
Steps taken by system_call( )
  • Under usual processing the system_call( ) function...
    • Saves the context of the calling process
    • Checks to make sure that the function number is in range
    • Then calls the kernel function
    • Flow of control differes if kernel tracing is enabled... ignore that for now
no prototypes
No prototypes
  • In ANSI C progrtams, the compiler uses function prototypes to check that a function call agrees with the target function header
  • The function call is compiled only if it provides the correct number and types of args according to the prototype
syscall linkage is dynamic
Syscall linkage is dynamic
  • But syscall linkage is different! It's dynamic... doesn't use the compiler's type checking mechanism.
  • Instead, when kernel function begins to execute, it presumes that the correct number oand type of args have been placed on the stack when the function is called!
  • The kernel checks for some obvious errors like an attempt to dereference a null pointer
  • However, you have no assurangce that bad parameters values will be caught by kernel function!
defining the system call number
Defining the system call number
  • System calls are defined in sys_call_table in arch/i386/kernel/entry.S assembly lang file

.long SYMBOL_NAME(sys_ni_syscall) /* 240 reserved for futex */

.long SYMBOL_NAME(sys_sched_setaffinity)

.long SYMBOL_NAME(sys_sched_getaffinity)

.rept NR_syscalls-(.-sys_call_table)/4

.long SYMBOL_NAME(sys_ni_syscall)

.long SYMBOL_NAME(sys_my_new_call) /*not sure what number*/

.endr

what this editing of entry s does
What this editing of entry.S does
  • It allows a trap with an arg of the new syscall's number to invoke a new kernel function, sys_my_new_call( ).
  • Note that by editing this file, you change your orig copy of the kernel source code!!!
  • So make 2 copies of the orig entry.S in a user-space directory in which you are developing your solution.
  • Retain one copy to ensure that you have a copy of the orig, and use the other as the experimental version!!!
how to call this new syscall
How to call this new syscall
  • You can also call the new system call by using the system call syscall( )
  • syscall( ) takes the system call table entry number and arguments as parameters andt hen traps to the kernel