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:
- 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
- File management
- create file, delete file
- open, close
- read, write, reposition
- get/set file attributes
- Device Management
- request device, release device
- read, write, reposition
- get/set device attributes
- logically attach or detach devices
- Information Maintenance
- get/set time or date
- get/set system data
- get/set process, file, or device attributes
- 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:
“Consciousness is cerebral celebritynothing more and nothing less. Those contents are conscious that persevere, that monopolize resources long enough to achieve certain typical and symptomatic effectson memory, on the control of behavior and so forth.”
—Daniel Clement Dennett (b. 1942)