Abstract


Benefits


Better Security

  • Allow User Space program to use computer hardware to complete its job with OS’s security implementation to prevent programs from doing malicious stuff

How a system call is triggered


  1. Calling program pushes parameters of the system call to Stack Segment (Step 1-3)
  2. Trigger an Instruction to trigger the corresponding Library Call, the same instruction is used to trigger other library calls (Step 4, where the actual library call is happening)
    1. Library Call puts Syscall Interrupt Number in a place where OS expects it, such as a Register (Step 5)
  3. Execute Trap Interrupt (陷入) (Step 6)
  4. Kernel code examines Syscall Interrupt Number, dispatch the correct Interrupt Handler via Interrupt Vector Table(Step 7)
  5. The desired Interrupt Handler starts running (Step 8)
  6. After Interrupt Handler finishes, control maybe returned to the User Space at the Instruction following the Trap Interrupt (陷入) (Step 9)

Control MAYBE returned to user-space

  • The System Call (系统调用) may block the caller (in this case Library Call), preventing it from continuing
  • For example, keyboard reads system call. When system call tries to read but nothing has been typed yet, the caller has to be blocked
  1. Then, library call returns to the user program (Step 10)
  2. To finish the job, the user program has to clean up the Stack Segment by incrementing the Stack Pointer exactly enough to remove the parameters pushed before the making the System Call (系统调用) (Step 11) (Stack Segment grows downwards, so to remove Stack frame, we increment the Stack Pointer)

Highly CPU dependent


Parameters of system call

Abstraction comes to rescue

Examples


Linux System Calls

Windows System Calls