The syscall and the syscall table are the fundamental mechanism for getting system services. The kernel of the operating system exposes an API. These are the operations that can be called on the kernel. Because a program is not linked to the kernel, the call to a system service is done through pre-assigned addresses and operation codes. Also, a call to a kernel function changes the mode of the CPU, and the thread moves from user mode to kernel mode at the instant of the call.
System calls on the Intel architecture involve a special trap instruction. A trap instruction works similar to a call instruction, in that it pushes a return address on the stack and branches to a new instruction address. However, a syscall trap also:
Starting in linux kernel 3.3, the syscall operation code is vectored through a table at
(Prior to that, it was at linux/arch/x86/kernel/syscall_table_32.S, and was written in assembler.) Each entry names a function. As an example the sys_setgid function is in TheSYSCALL_DEFINE1
symbol is a macro that sets up the signature properly,
including changing the setgid argument into sys_setgid as the name of the function.
In the Intel x86 architecture, the code immediately run in response to the trap is determined by a complicated thing called the GDT, the Global Descriptor Table. A pointer to this table is installed in the CPU during linux boot, and it has entries for various sorts of traps. Each entry is called a call gate which directs the change of privilege and gives the address of the function that will respond to he trap. All of the CPU context can change through a call gate. In particular, the stack is changed from the user stack to the kernel stack, and new data segments are installed that allow for full permission over the entire 4G virtual memory space.
The syscall depends on a trap. A trap is one of several call-like instructions that perform special operations as part of the call. What they all have in common is that an event causes a call-like instruction branch, with the return address saved on the stack, with additional changes in processor mode.
The names and taxonomy of this special sorts of calls will vary from processor to processor. Intel breaks them down in interrupts and exceptions:
Exceptions are classified as faults, traps or aborts.