Syscalls

Syscalls provide an interface to the services made available by an operating system. These system calls are generally available as C/C++ functions. They are a method for a program to request services from the kernel. It is the only method to access the kernel system.

Implementation

Each system call has a number associated with it and the system call interface maintains a table indexed according to these numbers. Parameters can be passed to a system call either via -

  • Registers
  • Parameters stored in a block of memory, and the address of the block is sent (like Linux and Solaris do)
  • Parameters pushed onto the stack and then popped off

The last two methods do not limit the number of parameters that we can supply.

Types

There are six major categories. They will be discussed below.

  1. Process control: Start, stop, abort, wait for processes
  2. File management: Opening, closing, reading write are some examples
  3. Device management: Requesting, releasing, getting and setting attributes of devices
  4. Information maintenance (dev attributes, system data, date time)
  5. Communications: Creating comm connections, attaching and detaching remote devices
  6. Protection: Permissions, authorization

Protection modes

User mode

It is a restricted mode with limited access to the system's resources. Code running in user mode can only make use of the system calls API. In windows, when a process is created, it is allocated a private virtual address space, which by definition cannot be accessed by other processes. This is done to ensure that if one program crashes, it is isolated and does not effect the OS or other processes.

Kernel mode

It is a privileged mode with complete access the machine's hardware. The code has complete access to the hardware. All of the kernel mode programs share a single virtual private space. This means that all the kernel drivers (which will obviously be running in kernel mode) share the same address space, and one single write to the wrong address will crash the drivers which will in turn crash the operating system.

Working of protection modes

If a privileged instruction is tried to be executed in user mode, it is treated as illegal and trapped to the OS. A mode bit set to 1 indicates user mode and 0 indicates kernel mode. A trap happens when switching from user mode to kernel mode, where the mode bit is "trapped" to 0. Before returning the control to the user program, the mode is switched back to user mode always.