Understanding System Call Execution

When a user program invokes a system call, a system call instruction is executed, which causes the processor to begin executing the system call handler in the kernel protection domain.

This system call handler performs the following actions:
  1. Sets the ut_error field in the uthread structure to 0
  2. Switches to a kernel stack associated with the calling thread
  3. Calls the function that implements the requested system call.

The system loader maintains a table of the functions that are used for each system call.

The system call runs within the calling thread, but with more privilege because system calls run in the kernel protection domain. After the function implementing the system call has performed the requested action, control returns to the system call handler. If the ut_error field in the uthread structure has a non-zero value, the value is copied to the application's thread-specific errno variable. If a signal is pending, signal processing take place, which can result in an application's signal handler being invoked. If no signals are pending, the system call handler restores the state of the calling thread, which is resumed in the user protection domain. For more information on protection domains, see Understanding Protection Domains.