When a User Mode process invokes a system call, the CPU switches to Kernel Mode and starts the execution of a kernel function. In Linux the system calls must be invoked by executing the int $0x80 Assembly instruction, which raises the programmed exception having vector 128 (see Section 4.4.1 and Section 4.2.5 in Chapter 4).
Since the kernel implements many different system calls, the process must pass a parameter called the system call number to identify the required system call; the eax register is used for that purpose. As we shall see in Section 8.2.3 later in this chapter, additional parameters are usually passed when invoking a system call.
All system calls return an integer value. The conventions for these return values are different from those for wrapper routines. In the kernel, positive or null values denote a successful termination of the system call, while negative values denote an error condition. In the latter case, the value is the negation of the error code that must be returned to the application program. The errno variable is not set or used by the kernel.
The system call handler, which has a structure similar to that of the other exception handlers, performs the following operations:
Saves the contents of most registers in the Kernel Mode stack (this operation is common to all system calls and is coded in assembly language).
Handles the system call by invoking a corresponding C function called the system call service ...