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

utxcpt4.c

Go to the documentation of this file.
00001 // utxcpt4.c - user mode seh test #3. 00002 00003 #include <ntos.h> 00004 // 00005 // Define function prototypes. 00006 // 00007 00008 VOID 00009 bar ( 00010 IN NTSTATUS Status, 00011 IN PULONG Counter 00012 ); 00013 00014 VOID 00015 eret ( 00016 IN NTSTATUS Status, 00017 IN PULONG Counter 00018 ); 00019 00020 VOID 00021 foo ( 00022 IN NTSTATUS Status 00023 ); 00024 00025 VOID 00026 fret ( 00027 IN PULONG Counter 00028 ); 00029 00030 BOOLEAN 00031 Tkm ( 00032 VOID 00033 ); 00034 00035 // 00036 // Define static storage. 00037 // 00038 00039 PTESTFCN TestFunction = Tkm; 00040 00041 main() 00042 { 00043 Tkm(); 00044 } 00045 00046 BOOLEAN 00047 Tkm ( 00048 ) 00049 00050 { 00051 00052 EXCEPTION_RECORD ExceptionRecord; 00053 LONG Counter; 00054 00055 // 00056 // Announce start of exception test. 00057 // 00058 00059 DbgPrint("Start of exception test\n"); 00060 00061 // 00062 // Initialize exception record. 00063 // 00064 00065 ExceptionRecord.ExceptionCode = STATUS_INTEGER_OVERFLOW; 00066 ExceptionRecord.ExceptionFlags = 0; 00067 ExceptionRecord.ExceptionRecord = NULL; 00068 ExceptionRecord.NumberParameters = 0; 00069 00070 // 00071 // Simply try statement with a finally clause that is entered sequentially. 00072 // 00073 00074 DbgPrint(" test1..."); 00075 Counter = 0; 00076 try { 00077 Counter += 1; 00078 00079 } finally { 00080 if (abnormal_termination() == FALSE) { 00081 Counter += 1; 00082 } 00083 } 00084 00085 if (Counter != 2) { 00086 DbgPrint("failed\n"); 00087 00088 } else { 00089 DbgPrint("succeeded\n"); 00090 } 00091 00092 // 00093 // Simple try statement with an exception clause that is never executed 00094 // because there is no exception raised in the try clause. 00095 // 00096 00097 DbgPrint(" test2..."); 00098 Counter = 0; 00099 try { 00100 Counter += 1; 00101 00102 } except (Counter) { 00103 Counter += 1; 00104 } 00105 00106 if (Counter != 1) { 00107 DbgPrint("failed\n"); 00108 00109 } else { 00110 DbgPrint("succeeded\n"); 00111 } 00112 00113 // 00114 // Simple try statement with an exception handler that is never executed 00115 // because the exception expression continues execution. 00116 // 00117 00118 DbgPrint(" test3..."); 00119 Counter = 0; 00120 try { 00121 Counter -= 1; 00122 RtlRaiseException(&ExceptionRecord); 00123 00124 } except (Counter) { 00125 Counter -= 1; 00126 } 00127 00128 if (Counter != - 1) { 00129 DbgPrint("failed\n"); 00130 00131 } else { 00132 DbgPrint("succeeded\n"); 00133 } 00134 00135 // 00136 // Simple try statement with an exception clause that is always executed. 00137 // 00138 00139 DbgPrint(" test4..."); 00140 Counter = 0; 00141 try { 00142 Counter += 1; 00143 RtlRaiseStatus(STATUS_INTEGER_OVERFLOW); 00144 00145 } except (Counter) { 00146 Counter += 1; 00147 } 00148 00149 if (Counter != 2) { 00150 DbgPrint("failed\n"); 00151 00152 } else { 00153 DbgPrint("succeeded\n"); 00154 } 00155 00156 // 00157 // Simply try statement with a finally clause that is entered as the 00158 // result of an exception. 00159 // 00160 00161 DbgPrint(" test5..."); 00162 Counter = 0; 00163 try { 00164 try { 00165 Counter += 1; 00166 RtlRaiseException(&ExceptionRecord); 00167 00168 } finally { 00169 if (abnormal_termination() != FALSE) { 00170 Counter += 1; 00171 } 00172 } 00173 00174 } except (Counter) { 00175 if (Counter == 2) { 00176 Counter += 1; 00177 } 00178 } 00179 00180 if (Counter != 3) { 00181 DbgPrint("failed\n"); 00182 00183 } else { 00184 DbgPrint("succeeded\n"); 00185 } 00186 00187 // 00188 // Simple try that calls a function which raises an exception. 00189 // 00190 00191 DbgPrint(" test6..."); 00192 Counter = 0; 00193 try { 00194 Counter += 1; 00195 foo(STATUS_ACCESS_VIOLATION); 00196 00197 } except ((GetExceptionCode() == STATUS_ACCESS_VIOLATION) ? 00198 EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) { 00199 Counter += 1; 00200 } 00201 00202 if (Counter != 2) { 00203 DbgPrint("failed\n"); 00204 00205 } else { 00206 DbgPrint("succeeded\n"); 00207 } 00208 00209 // 00210 // Simple try that calls a function which calls a function that 00211 // raises an exception. The first function has a finally clause 00212 // that must be executed for this test to work. 00213 // 00214 00215 DbgPrint(" test7..."); 00216 Counter = 0; 00217 try { 00218 bar(STATUS_ACCESS_VIOLATION, (PULONG)&Counter); 00219 00220 } except ((GetExceptionCode() == STATUS_ACCESS_VIOLATION) ? 00221 EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) { 00222 Counter -= 1; 00223 } 00224 00225 if (Counter != 98) { 00226 DbgPrint("failed\n"); 00227 00228 } else { 00229 DbgPrint("succeeded\n"); 00230 } 00231 00232 // 00233 // A try within an except 00234 // 00235 00236 DbgPrint(" test8..."); 00237 Counter = 0; 00238 try { 00239 foo(STATUS_ACCESS_VIOLATION); 00240 00241 } except ((GetExceptionCode() == STATUS_ACCESS_VIOLATION) ? 00242 EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) { 00243 Counter += 1; 00244 try { 00245 foo(STATUS_SUCCESS); 00246 00247 } except ((GetExceptionCode() == STATUS_SUCCESS) ? 00248 EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) { 00249 if (Counter != 1) { 00250 DbgPrint("failed..."); 00251 00252 } else { 00253 DbgPrint("succeeded..."); 00254 } 00255 00256 Counter += 1; 00257 } 00258 } 00259 00260 if (Counter != 2) { 00261 DbgPrint("failed\n"); 00262 00263 } else { 00264 DbgPrint("succeeded\n"); 00265 } 00266 00267 // 00268 // A goto from an exception clause that needs to pass 00269 // through a finally 00270 // 00271 00272 DbgPrint(" test9..."); 00273 Counter = 0; 00274 try { 00275 try { 00276 foo(STATUS_ACCESS_VIOLATION); 00277 00278 } except ((GetExceptionCode() == STATUS_ACCESS_VIOLATION) ? 00279 EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) { 00280 Counter += 1; 00281 goto t9; 00282 } 00283 00284 } finally { 00285 Counter += 1; 00286 } 00287 00288 t9:; 00289 if (Counter != 2) { 00290 DbgPrint("failed\n"); 00291 00292 } else { 00293 DbgPrint("succeeded\n"); 00294 } 00295 00296 // 00297 // A goto from an finally clause that needs to pass 00298 // through a finally 00299 // 00300 00301 DbgPrint(" test10..."); 00302 Counter = 0; 00303 try { 00304 try { 00305 Counter += 1; 00306 00307 } finally { 00308 Counter += 1; 00309 goto t10; 00310 } 00311 00312 } finally { 00313 Counter += 1; 00314 } 00315 00316 t10:; 00317 if (Counter != 3) { 00318 DbgPrint("failed\n"); 00319 00320 } else { 00321 DbgPrint("succeeded\n"); 00322 } 00323 00324 // 00325 // A goto from an exception clause that needs to pass 00326 // through a finally into the outer finally clause. 00327 // 00328 00329 DbgPrint(" test11..."); 00330 Counter = 0; 00331 try { 00332 try { 00333 try { 00334 Counter += 1; 00335 foo(STATUS_INTEGER_OVERFLOW); 00336 00337 } except (EXCEPTION_EXECUTE_HANDLER) { 00338 Counter += 1; 00339 goto t11; 00340 } 00341 00342 } finally { 00343 Counter += 1; 00344 } 00345 t11:; 00346 } finally { 00347 Counter += 1; 00348 } 00349 00350 if (Counter != 4) { 00351 DbgPrint("failed\n"); 00352 00353 } else { 00354 DbgPrint("succeeded\n"); 00355 } 00356 00357 // 00358 // A goto from an finally clause that needs to pass 00359 // through a finally into the outer finally clause. 00360 // 00361 00362 DbgPrint(" test12..."); 00363 Counter = 0; 00364 try { 00365 try { 00366 Counter += 1; 00367 00368 } finally { 00369 Counter += 1; 00370 goto t12; 00371 } 00372 t12:; 00373 } finally { 00374 Counter += 1; 00375 } 00376 00377 if (Counter != 3) { 00378 DbgPrint("failed\n"); 00379 00380 } else { 00381 DbgPrint("succeeded\n"); 00382 } 00383 00384 // 00385 // A return from an except clause 00386 // 00387 00388 DbgPrint(" test13..."); 00389 Counter = 0; 00390 try { 00391 Counter += 1; 00392 eret(STATUS_ACCESS_VIOLATION, (PULONG)&Counter); 00393 00394 } finally { 00395 Counter += 1; 00396 } 00397 00398 if (Counter != 4) { 00399 DbgPrint("failed\n"); 00400 } else { 00401 DbgPrint("succeeded\n"); 00402 } 00403 00404 // 00405 // A return from a finally clause 00406 // 00407 00408 DbgPrint(" test14..."); 00409 Counter = 0; 00410 try { 00411 Counter += 1; 00412 fret((PULONG)&Counter); 00413 00414 } finally { 00415 Counter += 1; 00416 } 00417 00418 if (Counter != 5) { 00419 DbgPrint("failed\n"); 00420 } else { 00421 DbgPrint("succeeded\n"); 00422 } 00423 00424 // 00425 // Announce end of exception test. 00426 // 00427 00428 DbgPrint("End of exception test\n"); 00429 return TRUE; 00430 } 00431 00432 VOID 00433 fret( 00434 IN PULONG Counter 00435 ) 00436 00437 { 00438 00439 try { 00440 try { 00441 *Counter += 1; 00442 00443 } finally { 00444 *Counter += 1; 00445 return; 00446 } 00447 } finally { 00448 *Counter += 1; 00449 } 00450 00451 return; 00452 } 00453 00454 VOID 00455 eret( 00456 IN NTSTATUS Status, 00457 IN PULONG Counter 00458 ) 00459 00460 { 00461 00462 try { 00463 try { 00464 foo(Status); 00465 00466 } except ((GetExceptionCode() == Status) ? 00467 EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) { 00468 *Counter += 1; 00469 return; 00470 } 00471 00472 } finally { 00473 *Counter += 1; 00474 } 00475 00476 return; 00477 } 00478 00479 VOID 00480 bar ( 00481 IN NTSTATUS Status, 00482 IN PULONG Counter 00483 ) 00484 { 00485 00486 try { 00487 foo(Status); 00488 00489 } finally { 00490 if (abnormal_termination() != FALSE) { 00491 *Counter = 99; 00492 00493 } else { 00494 *Counter = 100; 00495 } 00496 } 00497 00498 return; 00499 } 00500 00501 VOID 00502 foo( 00503 IN NTSTATUS Status 00504 ) 00505 00506 { 00507 00508 // 00509 // Raise exception. 00510 // 00511 00512 RtlRaiseStatus(Status); 00513 return; 00514 }

Generated on Sat May 15 19:42:17 2004 for test by doxygen 1.3.7