Exception Handling
Most exceptions issued by the CPU are
interpreted by Linux as error conditions. When one of them occurs,
the kernel sends a signal to the process that caused the exception to
notify it of an anomalous condition. If, for instance, a process
performs a division by zero, the CPU raises a
“Divide error” exception and the
corresponding exception handler sends a SIGFPE
signal to the current process, which then takes the necessary steps
to recover or (if no signal handler is set for that signal) abort.
There are a couple of cases, however, where Linux exploits CPU
exceptions to manage hardware resources more efficiently. A first
case is already described in section Section 3.3.4.
The “Device not available”
exception is used together with the TS flag of the
cr0 register to force the kernel to load the
floating point registers of the CPU with new values. A second case
refers to the Page Fault exception, which is used to defer allocating
new page frames to the process until the last possible moment. The
corresponding handler is complex because the exception may, or may
not, denote an error condition (see Section 8.4).
Exception handlers have a standard structure consisting of three parts:
Save the contents of most registers in the Kernel Mode stack (this part is coded in assembly language).
Handle the exception by means of a high-level C function.
Exit from the handler by means of the
ret_from_exception( )function.
To take advantage of exceptions, the IDT must be properly ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access