The fine detail of exception management by OS/2 is complex. However the principles are easy to grasp. This section gives an overview of OS/2 Exception Management sufficient to provide the reader with a technique for intercepting exceptions in user code under the Kernel Debugger.
Exception Definition
Exceptions may be summarised as follows:
Hardware Traps and Faults - INTEL defined.
Software generated exceptions - OS/2 and User defined.
Page fault exceptions.
Trap 1 and 3 for system trace
387 Co-processor emulation
VDM privileged instruction emulation
Exception Logic
The essential logic for exception handling is as follows:
If recovery is not directly possible or further special processing is required then control passes to one of the following second level exception handlers:
V8086 Emulation for instruction emulation.
VDM Exception Handler to reflect non-fatal exceptions back to the VDM using its IDT.
Process Fatal Fault Handler (_TRAPProcessFatalFault) for non-kernel mode code (InDos=0).
Kernel Fault Handler for kernel code (InDos=1)
Special handlers for Co-processor handling, NMIs etc..
The parameters to XCPTBuildR3DispatcherStack are:
Trap number or 0x0000ffff for S/W generated exceptions Exception
number
Count of exception info parameters
Pointer to the array of exception info parameters
Boolean, if true then exception is non-contnueable.
Pointer to any additional nested report record
Trap number
Pointer to the exception report
record
Pointer to the exception context
record
The values for the various return codes are as follows:
┌───────────────────────┬──────────┬─────────────────────┐ │Name │Bit Mask │Description │ ├───────────────────────┼──────────┼─────────────────────┤ │XCPT_CONTINUE_SEARCH │0x00000000│Exception not handled│ ├───────────────────────┼──────────┼─────────────────────┤ │XCPT_CONTINUE_EXECUTION│0xFFFFFFFF│Exception handled │ ├───────────────────────┼──────────┼─────────────────────┤ │XCPT_CONTINUE_STOP │0x00716668│Exception handled by │ │ │ │debugger (via │ │ │ │DosDebug) │ └───────────────────────┴──────────┴─────────────────────┘
The following additional return codes are used by internal excfeption handlers to manage nested exceptions.
┌───────────────┬──────────┬────────────────────────────────────────┐ │Name │Bit Mask │Description │ ├───────────────┼──────────┼────────────────────────────────────────┤ │NESTED │0xf0f0f0f0│An exception occurred while an exception│ │ │ │was active │ ├───────────────┼──────────┼────────────────────────────────────────┤ │COLLIDED_UNWIND│0x0f0f0f0f│Indicates collided unwinds │ ├───────────────┼──────────┼────────────────────────────────────────┤ │EXIT_UNWIND │0x65796C4B│Indicates the end of an exit unwind │ └───────────────┴──────────┴────────────────────────────────────────┘
Trap number
Pointer to the exception report
record
Pointer to the exception context
record
Exception disposition
For fatal exceptions _xctDefaultAction. calls DelayHardError to format the trap screen information from the context record and wake the Hard Error process. It also writes the POPUPLOG.OS2 entry and calls the Kernel Debugger if the VSU command has been specified.
These details are summarised in the following diagrams: