All Topics  
System call

 

   Email Print
   Bookmark   Link






 

System call



 
 
In computing
Computing

Computing is usually defined as the activity of using and developing computer technology, computer hardware and computer software. It is the computer-specific part of information technology....
, a system call is the mechanism used by an application program to request service from the operating system based on the monolithic kernel
Monolithic kernel

A monolithic kernel is a Kernel architecture where the entire operating system is run in kernel space as supervisor mode. In difference with other architectures , the monolithic kernel defines alone a high-level virtual interface over computer hardware, with a set of primitives or system calls to implement all operating system services such...
 or to system servers on operating systems based on the microkernel-structure.

stem call is a request made by any arbitrary program to the operating system for performing tasks -- picked from a predefined set -- which the said program does not have required permissions to execute in its own flow of execution.






Discussion
Ask a question about 'System call'
Start a new discussion about 'System call'
Answer questions from other users
Full Discussion Forum



Encyclopedia


In computing
Computing

Computing is usually defined as the activity of using and developing computer technology, computer hardware and computer software. It is the computer-specific part of information technology....
, a system call is the mechanism used by an application program to request service from the operating system based on the monolithic kernel
Monolithic kernel

A monolithic kernel is a Kernel architecture where the entire operating system is run in kernel space as supervisor mode. In difference with other architectures , the monolithic kernel defines alone a high-level virtual interface over computer hardware, with a set of primitives or system calls to implement all operating system services such...
 or to system servers on operating systems based on the microkernel-structure.

Background

A system call is a request made by any arbitrary program to the operating system for performing tasks -- picked from a predefined set -- which the said program does not have required permissions to execute in its own flow of execution. System calls provide the interface between a process and the operating system itself. These calls are generally available as assembly language instructions and they are usually listed in the various manuals used by the assembly-language programmers. Most operations interacting with the system require permissions not available to a user level process, i.e. any I/O performed with any arbitrary device present on the system or any form of communication with other processes requires the use of system calls.

The fact that improper use of the system can easily cause a system crash necessitates some level of control. The design of the microprocessor architecture on practically all modern systems (except some embedded systems) offers a series of privilege level
Privilege level

The concept of privilege level refers to protecting resources on a CPU. Different execution threads can have different privilege levels that grant access to resources such as memory regions, I/O ports, and special instructions....
s
-- the (low) privilege level in which normal applications execute limits the address space
Address space

In computing, an address space defines a range of discrete addresses, each of which may correspond to a physical or virtual memory register, a Node , peripheral device, disk sector or other logical or physical entity....
 of the program so that it cannot access or modify other running applications nor the operating system itself. It also prevents the application from using any devices (e.g. the frame buffer or network
Computer network

A computer network is a group of interconnected computers. Networks may be classified according to a wide variety of characteristics. This article provides a general overview of some types and categories and also presents the basic components of a network....
 devices). But obviously any normal application needs these abilities; thus it can call the operating system. The operating system executes at the highest level of privilege and allows the applications to request services via system calls, which are often implemented through interrupt
Interrupt

In computing, an interrupt is an asynchronous communication signal from hardware indicating the need for attention or a synchronous event in software indicating the need for a change in execution....
s. If allowed, the system enters a higher privilege level, executes a specific set of instructions which the interrupting program has no direct control over, then returns control to the former flow of execution. This concept also serves as a way to implement security
Computer security

Computer security is a branch of technology known as information security as applied to computers. The objective of computer security can include protection of information from theft or corruption, or the preservation of availability, as defined in the security policy....
.

With the development of separate operating modes with varying levels of privilege, a mechanism was needed for transferring control safely from lesser privileged modes to higher privileged modes. Less privileged code could not simply transfer control to more privileged code at any arbitrary point and with any arbitrary processor state. To allow it to do so would allow it to break security. For instance, the less privileged code could cause the higher privileged code to execute in the wrong order, or provide it with a bad stack
Call stack

In computer science, a call stack is a dynamic Stack data structure that stores information about the active subroutines of a computer program....
.

The library as an intermediary


Generally, systems provide a library that sits between normal programs and the operating system, usually an implementation of the C library
C standard library

The C standard library consists of a set of sections of the ISO C standard which describe a collection of header files and library routines used to implement common operations, such as input/output and character string handling, in the C ....
 (libc), such as glibc. This library handles the low-level details of passing information to the operating system and switching to supervisor mode, as well as any data processing and preparation which does not need to be done in privileged mode. Ideally, this reduces the coupling
Coupling (computer science)

In computer science, coupling or dependency is the degree to which each program module relies on each one of the other modules.Coupling is usually contrasted with cohesion ....
 between the OS and the application, and increases portability
Portability

Portability is the general characteristic of being readily transportable from one location to another, and may specifically refer to:*Portability , the portability of social security benefits...
.

On exokernel
Exokernel

Exokernel is an operating system kernel developed by the MIT Parallel and Distributed Operating Systems group, and also a class of similar operating systems....
 based systems, the library is especially important as an intermediary. On exokernels, OS shield user applications from the very low level kernel API, and provide abstractions
Abstraction (computer science)

In computer science, abstraction is a mechanism and practice to reduce and factor out details so that one can focus on a few concepts at a time....
 and resource
Resource (computer science)

A resource, or system resource, is any physical or virtual component of limited availability within a computer system. Every device connected to a computer system is a resource....
 management.

Examples and tools


On Unix
Unix

Unix is a computer operating system originally developed in 1969 by a group of American Telephone & Telegraph employees at Bell Labs, including Ken Thompson , Dennis Ritchie, Douglas McIlroy, and Joe Ossanna....
, Unix-like and other POSIX
POSIX

POSIX or "Portable Operating System Interface" is the collective name of a family of related standardizations specified by the Institute of Electrical and Electronics Engineers to define the application programming interface , along with shell and utilities interfaces for software compatible with variants of the Unix operating system, altho...
 systems, popular system calls are open
Open (system call)

In most modern operating systems, a program that needs access to a Computer file stored in a filesystem uses the open system call. This system call allocates resources associated to the file , and returns a Smart pointer#Handles that the process will use to refer to that file from then on....
, read, write, close, wait, exec
Exec (operating system)

The exec functions of Unix-like operating systems are a collection of functions that causes the running process to be completely replaced by the program passed as argument to the function....
, fork
Fork (operating system)

In computing, when a Computer_process forks, it creates a copy of itself, which is called a "Child_process." The original process is then called the "Parent_process"....
, exit
Exit (operating system)

A computer process terminates its execution by making an exit system call. More generally, an exit in a multithreading environment means that a thread of execution has stopped running....
, and kill
Kill (Unix)

In computing, kill is an operating system command that is used to request the termination of a process that is currently running on the system....
. Many of today's operating systems have hundreds of system calls. For example, Linux
Linux

Linux is a generic term referring to Unix-like computer operating systems based on the Linux kernel. Their development is one of the most prominent examples of free and open source software collaboration; typically all the underlying source code can be used, freely modified, and redistributed by anyone under the terms of the GNU GPL license...
 has 319 different system calls. FreeBSD
FreeBSD

FreeBSD is a Unix-like free software operating system descended from AT&T Unix via the Berkeley Software Distribution branch through the 386BSD and Berkeley Software Distribution#4.4BSD and descendants operating systems....
 has about the same amount (almost 330).

Tools such as strace and truss allow a process to execute from start and report all system calls the process invokes, or can attach to an already running process and intercept any system call made by said process if the operation does not violate the permissions of the user. This special ability of the program is usually also implemented with a system call, e.g. the GNU's strace is implemented with i.a. ptrace.

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
Interrupt

In computing, an interrupt is an asynchronous communication signal from hardware indicating the need for attention or a synchronous event in software indicating the need for a change in execution....
 or trap
Trap (computing)

In computing and operating systems, a trap is a type of synchronization interrupt typically caused by an exception handling condition in a user process ....
. Interrupts transfer control to the OS so software simply needs to set up some register with the system call number they want and execute the software interrupt.

For many RISC processors this is the only feasible implementation, but CISC
Complex instruction set computer

A complex instruction set computer is a computer instruction set architecture in which each instruction can execute several low-level operations, such as a load from Memory , an arithmetic operator, and a memory , all in a single instruction....
 architectures such as x86 support additional techniques. One example is SYSCALL/SYSRET which is very similar to SYSENTER/SYSEXIT (the two mechanisms were created by Intel and AMD independently, but do basically 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
Linux

Linux is a generic term referring to Unix-like computer operating systems based on the Linux kernel. Their development is one of the most prominent examples of free and open source software collaboration; typically all the underlying source code can be used, freely modified, and redistributed by anyone under the terms of the GNU GPL license...
 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
Processor register

In computer architecture, a processor register is a small amount of Computer storage available on the CPU whose contents can be accessed more quickly than storage available elsewhere....
 before interrupt
INT (x86 instruction)

INT is an assembly language instruction for x86 central processing unit for generating a software interrupt. It takes the interrupt number formatted as a byte value....
 0x80 was executed.

An older x86 mechanism is called a call gate
Call gate

A call gate is a mechanism in Intel's x86 architecture for changing the privilege level of the CPU when it executes a predefined function call using a CALL FAR instruction....
 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.

External links

  • - system calls for Linux kernel
    Linux kernel

    The Linux kernel is an operating system kernel used by a family of Unix-like operating systems. The term Linux distribution is used to refer to the various operating systems that run on top of the Linux Kernel....
     2.2, with IA32 calling convention
    Calling convention

    In computer science, a calling convention is a scheme for how function s receive parameters from their caller and how they return a result; calling conventions can differ in:...
    s
  • - IBM developerWorks
  • - Amit Choudhary