Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

raisests.c

Go to the documentation of this file.
00001 /*++ 00002 00003 Copyright (c) 1990 Microsoft Corporation 00004 00005 Module Name: 00006 00007 raisests.c 00008 00009 Abstract: 00010 00011 This module implements routines to raise a general exception from kernel 00012 mode or a noncontinuable exception from kernel mode. 00013 00014 Author: 00015 00016 William K. Cheung (wcheung) 08-Mar-1996 00017 00018 based on David N. Cutler (davec) 18-Oct-1990 00019 00020 Environment: 00021 00022 Any mode. 00023 00024 Revision History: 00025 00026 --*/ 00027 00028 #include "exp.h" 00029 00030 // 00031 // Define private function prototypes. 00032 // 00033 00034 VOID 00035 ExpRaiseException ( 00036 IN PEXCEPTION_RECORD ExceptionRecord 00037 ); 00038 00039 VOID 00040 ExpRaiseStatus ( 00041 IN NTSTATUS ExceptionCode 00042 ); 00043 00044 VOID 00045 ExRaiseException ( 00046 IN PEXCEPTION_RECORD ExceptionRecord 00047 ) 00048 00049 /*++ 00050 00051 Routine Description: 00052 00053 This function raises a software exception by building a context record 00054 and calling the exception dispatcher directly. 00055 00056 N.B. This routine is a shell routine that simply calls another routine 00057 to do the real work. The reason this is done is to avoid a problem 00058 in try/finally scopes where the last statement in the scope is a 00059 call to raise an exception. 00060 00061 Arguments: 00062 00063 ExceptionRecord - Supplies a pointer to an exception record. 00064 00065 Return Value: 00066 00067 None. 00068 00069 --*/ 00070 00071 { 00072 00073 ExpRaiseException(ExceptionRecord); 00074 return; 00075 } 00076 00077 VOID 00078 ExpRaiseException ( 00079 IN PEXCEPTION_RECORD ExceptionRecord 00080 ) 00081 00082 /*++ 00083 00084 Routine Description: 00085 00086 This function raises a software exception by building a context record 00087 and calling the exception dispatcher directly. 00088 00089 N.B. Assuming that the call is made in the 3rd slot of a bundle; 00090 therefore, ControlPc is ORed with 0x8. 00091 00092 Arguments: 00093 00094 ExceptionRecord - Supplies a pointer to an exception record. 00095 00096 Return Value: 00097 00098 None. 00099 00100 --*/ 00101 00102 { 00103 00104 ULONGLONG ControlPc; 00105 CONTEXT ContextRecord; 00106 FRAME_POINTERS EstablisherFrame; 00107 PRUNTIME_FUNCTION FunctionEntry; 00108 BOOLEAN InFunction; 00109 ULONGLONG NextPc; 00110 NTSTATUS Status; 00111 ULONGLONG ImageBase; 00112 ULONGLONG TargetGp; 00113 00114 // 00115 // Capture the current context, virtually unwind to the caller of this 00116 // routine, set the fault instruction address to that of the caller, and 00117 // call the exception dispatcher. 00118 // 00119 00120 RtlCaptureContext(&ContextRecord); 00121 ControlPc = RtlIa64InsertIPSlotNumber((ContextRecord.BrRp-16), 2); 00122 FunctionEntry = RtlLookupFunctionEntry(ControlPc, &ImageBase, &TargetGp); 00123 NextPc = RtlVirtualUnwind(ImageBase, 00124 ControlPc, 00125 FunctionEntry, 00126 &ContextRecord, 00127 &InFunction, 00128 &EstablisherFrame, 00129 NULL); 00130 00131 ContextRecord.StIIP = NextPc + 8; 00132 ContextRecord.StIPSR &= ~((ULONGLONG) 3 << PSR_RI); 00133 ExceptionRecord->ExceptionAddress = (PVOID)ContextRecord.StIIP; 00134 00135 // 00136 // If the exception is successfully dispatched, then continue execution. 00137 // Otherwise, give the kernel debugger a chance to handle the exception. 00138 // 00139 00140 if (RtlDispatchException(ExceptionRecord, &ContextRecord)) { 00141 Status = ZwContinue(&ContextRecord, FALSE); 00142 00143 } else { 00144 Status = ZwRaiseException(ExceptionRecord, &ContextRecord, FALSE); 00145 } 00146 00147 // 00148 // Either the attempt to continue execution or the attempt to give 00149 // the kernel debugger a chance to handle the exception failed. Raise 00150 // a noncontinuable exception. 00151 // 00152 00153 ExRaiseStatus(Status); 00154 } 00155 00156 VOID 00157 ExRaiseStatus ( 00158 IN NTSTATUS ExceptionCode 00159 ) 00160 00161 /*++ 00162 00163 Routine Description: 00164 00165 This function raises an exception with the specified status value by 00166 building an exception record, building a context record, and calling the 00167 exception dispatcher directly. The exception is marked as noncontinuable 00168 with no parameters. There is no return from this function. 00169 00170 N.B. This routine is a shell routine that simply calls another routine 00171 to do the real work. The reason this is done is to avoid a problem 00172 in try/finally scopes where the last statement in the scope is a 00173 call to raise an exception. 00174 00175 Arguments: 00176 00177 ExceptionCode - Supplies the status value to be used as the exception 00178 code for the exception that is to be raised. 00179 00180 Return Value: 00181 00182 None. 00183 00184 --*/ 00185 00186 { 00187 00188 ExpRaiseStatus(ExceptionCode); 00189 return; 00190 } 00191 00192 VOID 00193 ExpRaiseStatus ( 00194 IN NTSTATUS ExceptionCode 00195 ) 00196 00197 /*++ 00198 00199 Routine Description: 00200 00201 This function raises an exception with the specified status value by 00202 building an exception record, building a context record, and calling the 00203 exception dispatcher directly. The exception is marked as noncontinuable 00204 with no parameters. There is no return from this function. 00205 00206 N.B. Assuming that the call is made in the 3rd slot of a bundle; 00207 therefore, ControlPc is ORed with 0x8. 00208 00209 Arguments: 00210 00211 ExceptionCode - Supplies the status value to be used as the exception 00212 code for the exception that is to be raised. 00213 00214 Return Value: 00215 00216 None. 00217 00218 --*/ 00219 00220 { 00221 00222 ULONGLONG ControlPc; 00223 CONTEXT ContextRecord; 00224 FRAME_POINTERS EstablisherFrame; 00225 EXCEPTION_RECORD ExceptionRecord; 00226 PRUNTIME_FUNCTION FunctionEntry; 00227 BOOLEAN InFunction; 00228 ULONGLONG NextPc; 00229 NTSTATUS Status; 00230 ULONGLONG ImageBase; 00231 ULONGLONG TargetGp; 00232 00233 // 00234 // Construct an exception record. 00235 // 00236 00237 ExceptionRecord.ExceptionCode = ExceptionCode; 00238 ExceptionRecord.ExceptionRecord = (PEXCEPTION_RECORD)NULL; 00239 ExceptionRecord.NumberParameters = 0; 00240 ExceptionRecord.ExceptionFlags = EXCEPTION_NONCONTINUABLE; 00241 00242 // 00243 // Capture the current context, virtually unwind to the caller of this 00244 // routine, set the fault instruction address to that of the caller, and 00245 // call the exception dispatcher. 00246 // 00247 00248 RtlCaptureContext(&ContextRecord); 00249 ControlPc = RtlIa64InsertIPSlotNumber((ContextRecord.BrRp-16), 2); 00250 FunctionEntry = RtlLookupFunctionEntry(ControlPc, &ImageBase, &TargetGp); 00251 NextPc = RtlVirtualUnwind(ImageBase, 00252 ControlPc, 00253 FunctionEntry, 00254 &ContextRecord, 00255 &InFunction, 00256 &EstablisherFrame, 00257 NULL); 00258 00259 ContextRecord.StIIP = NextPc + 8; 00260 ContextRecord.StIPSR &= ~((ULONGLONG) 3 << PSR_RI); 00261 ExceptionRecord.ExceptionAddress = (PVOID)ContextRecord.StIIP; 00262 RtlDispatchException(&ExceptionRecord, &ContextRecord); 00263 00264 // 00265 // An unwind was not initiated during the dispatching of a noncontinuable 00266 // exception. Give the kernel debugger a chance to handle the exception. 00267 // 00268 00269 Status = ZwRaiseException(&ExceptionRecord, &ContextRecord, FALSE); 00270 00271 // 00272 // The attempt to give the kernel debugger a chance to handle the exception 00273 // failed. Raise another noncontinuable exception. 00274 // 00275 00276 ExRaiseStatus(Status); 00277 }

Generated on Sat May 15 19:41:35 2004 for test by doxygen 1.3.7