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 a system call must be invoked by
int $0x80 assembly language
instruction, which raises the programmed exception that has vector
128 (see Section 4.4.1
and Section 4.2.4, both 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;
eax register is used for this purpose. As we
shall see in Section 9.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 0 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 in the
errno variable is not set or used by
the kernel. Instead, the wrapper routines handles the task of setting
this variable after a return from a system call.
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 ...