System Calls - How Apps and the OS Communicate

06 Jun 2019

System Calls

The trap instruction is used to switch from user to supervisor mode, therby entering the OS.

  • trap sets the mode bit to 0.
  • On x86, use INT assembly instruction (more recently SYSCALL/SYSENTER).
  • The mode bit is set back to 1 on return. Any instruction that invokes trap is called a system call and there are many different classes of system calls.

Trap Table

  • A trap is a software interrupt.
  • Trap handling: the process of indexing into the trap table to jump to the trap handler routine. This may also be called dispatching.
  • The trap table is also called a jump table or a branch table.
  • The trap handler (or system call handler) performs the specific processing desired by the system call/trap.

System Call Parameter Passing

There are 3 general methods used to pass parameters to the OS:

  1. Register: Simplest; pass the parameters in registers. In some cases, there may be more parameters than registers.
  2. Pointer: Parameters stored in a block or table in memory and the address of the block/table is passed as a parameter in a register. This approach is taken by Linux and Solaris.
  3. Stack: Paramters are placed, or pushed, onto the stack by the program and popped off the stack by the operating system. The block and stack methods do not limit the number or length of parameters being passed.

Protection of Applications

The OS can’t just access any memory (e.g. App1 telling the OS to access App2’s data). It needs to explicitly ask itself for permission and when in the kernel, extra caution is needed when accessing data.