System Calls: Difference between revisions

From OSDev.wiki
Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content added Content deleted
(Links added)
m (links corrected)
Line 1: Line 1:
'''System Calls''' are used to call a kernel service from user land. The goal is to be able to switch from user mode to kernel mode, with the associated privileges. Provided system calls depends on the nature of your kernel (see KernelTypes).
'''System Calls''' are used to call a kernel service from user land. The goal is to be able to switch from user mode to kernel mode, with the associated privileges. Provided system calls depends on the nature of your [[Kernels|kernel]].


'''This is a work in progress, I will complete it with link to the forum and websites.'''
'''This is a work in progress, I will complete it with link to the forum and websites.'''
Line 26: Line 26:
==Forum links==
==Forum links==


* Forum discussion on system call implementation: [[Topic:13186]]
* [[Topic:13186|Forum discussion on system call implementation]]


==External links==
==External links==

Revision as of 09:01, 11 March 2007

System Calls are used to call a kernel service from user land. The goal is to be able to switch from user mode to kernel mode, with the associated privileges. Provided system calls depends on the nature of your kernel.

This is a work in progress, I will complete it with link to the forum and websites.

On the Kernel side

System Calls via Interrupts

The most common way to implement system calls is using a software interrupt. It is probably the most portable way to imlement system call. Linux traditionaly use interrupt 0x80 for this purposes.

System Calls via sysenter/sysexit (Intel)

On Intel CPU, starting from the Pentium II, a new instruction pair sysenter/sysexit has appeared. It allows a faster switch from user mode to kernel mode, by limiting the overhead of changing mode.

A similar instruction pair has been created by AMD: syscall/sysret. However the behaviour of these instructions are different from Intel's.

System Calls via Trap

Some OSes implement system calls by triggering a CPU Trap in a determined fashion such that they can recognize it as a system call. This solution is adopted on some hardware by Solaris, by L4, and probably others.

For example, L4 use a "LOCK NOP" instruction on x86. Since it is not permitted to perfrom a lock on the "NOP" instruction a trap is triggered. The problem with this approach is that there is no guarantee the "LOCK NOP" will have the same behavior on futur x86 CPU. They should probably have used the "UD2" instruction, since it is defined for this purposes.

Strategies Conlusion

The system call strategy depends on the platform. You may want to use different strategy depending on the architecture, and even switch strategy depending on the hardware performance.

On the user land side

While the developper can trigger manually the system call, it is probably a good idea to provide a library to encapsulate such a call. Therefore you wil be able to switch the system call technique without impacting the user applications.

Forum links

External links