System Call - Typical Implementations

Typical Implementations

Implementing system calls requires a control transfer which involves some sort of architecture-specific feature. A typical way to implement this is to use a software interrupt or trap. Interrupts transfer control to the operating system kernel so software simply needs to set up some register with the system call number needed, and execute the software interrupt.

For many RISC processors this is the only technique provided, but CISC architectures such as x86 support additional techniques. One example is SYSCALL/SYSENTER, SYSRET/SYSEXIT (the two mechanisms were independently created by AMD and Intel, respectively, but in essence do the same thing). These are "fast" control transfer instructions that are designed to quickly transfer control to the OS for a system call without the overhead of an interrupt. Linux 2.5 began using this on the x86, where available; formerly it used the INT instruction, where the system call number was placed in the EAX register before interrupt 0x80 was executed.

An older x86 mechanism is called a call gate and is a way for a program to literally call a kernel function directly using a safe control transfer mechanism the OS sets up in advance. This approach has been unpopular, presumably due to the requirement of a far call which uses x86 memory segmentation and the resulting lack of portability it causes, and existence of the faster instructions mentioned above.

For IA-64 architecture, EPC (Enter Privileged Mode) instruction is used. The first eight system call arguments are passed in registers, and the rest are passed on the stack.

System calls can be roughly grouped into five major categories:

  1. Process Control
    • load
    • execute
    • create process (for example, fork on Unix-like systems or NTCreateProcess in the Windows NT Native API)
    • terminate process
    • get/set process attributes
    • wait for time, wait event, signal event
    • allocate, free memory
  2. File management
    • create file, delete file
    • open, close
    • read, write, reposition
    • get/set file attributes
  3. Device Management
    • request device, release device
    • read, write, reposition
    • get/set device attributes
    • logically attach or detach devices
  4. Information Maintenance
    • get/set time or date
    • get/set system data
    • get/set process, file, or device attributes
  5. Communication
    • create, delete communication connection
    • send, receive messages
    • transfer status information
    • attach or detach remote devices

Read more about this topic:  System Call

Famous quotes containing the word typical:

    A building is akin to dogma; it is insolent, like dogma. Whether or no it is permanent, it claims permanence, like a dogma. People ask why we have no typical architecture of the modern world, like impressionism in painting. Surely it is obviously because we have not enough dogmas; we cannot bear to see anything in the sky that is solid and enduring, anything in the sky that does not change like the clouds of the sky.
    Gilbert Keith Chesterton (1874–1936)