Kinds of traps


Two basic kinds of traps can occur: synchronous and asynchronous. Synchronous traps are caused by, or during the operation of, an instruction. These may be actual trap instructions or hardware errors, such as bad address alignments, bad addresses (bus timeouts), illegal instructions, floating-point coprocessor errors, and so on. These traps are taken immediately; the hardware stops the operation of the current instruction in its tracks and heads for kernel space.

A synchronous trap will occur before it changes any state in the processor. Thus, if the trap is caused by a "repairable" hardware fault, then the instruction can and should be restarted to recover from the problem once the trap handling is completed. Page faults are a good example of this. You need to be able to get the page into memory, map it in to the process address space, and then let the instruction try again, now that the data is really there.

Asynchronous traps can be " requested " at any time but will be recognized and processed only after an instruction has completed. These traps are due to external events such as interrupts; they do not affect the operation of an instruction but just cause a break in the instruction stream. It's as if a subroutine call to the kernel were invisibly inserted into the code.

Both types of traps can occur in user programs and inside the kernel. Both cause a switch to kernel or supervisor mode and a transfer of control to the kernel trap code, where the software will decide what to do about it. Thus, a page fault from a user program is generally acceptable: the kernel will load in the appropriate page and let the instruction continue. A page fault from the kernel, however, is bad news, and the trap code will stop with a panic.



PANIC. UNIX System Crash Dump Analysis Handbook
PANIC! UNIX System Crash Dump Analysis Handbook (Bk/CD-ROM)
ISBN: 0131493868
EAN: 2147483647
Year: 1994
Pages: 289
Authors: Chris Drake

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net