00017 {
00018
00019 EXCEPTION_RECORD ExceptionRecord;
00020 LONG Counter;
00021 ULONG rv;
00022
00023
00024
00025
00026
00027
DbgPrint(
"Start of exception test\n");
00028
00029
00030
00031
00032
00033 ExceptionRecord.ExceptionCode = (
NTSTATUS)49;
00034 ExceptionRecord.ExceptionRecord = (PEXCEPTION_RECORD)
NULL;
00035 ExceptionRecord.NumberParameters = 1;
00036 ExceptionRecord.ExceptionInformation[0] = 9;
00037
00038
00039
00040
00041
DbgPrint(
"t1...");
00042 Counter = 0;
00043
try {
00044 Counter += 1;
00045 } finally {
00046
if (abnormal_termination() == 0) {
00047 Counter += 1;
00048 }
00049 }
00050
if (Counter != 2) {
00051
DbgPrint(
"BUG Finally clause executed as result of unwind\n");
00052 }
00053
DbgPrint(
"done\n");
00054
00055
00056
00057
00058
00059
00060
DbgPrint(
"t2...");
00061 Counter = 0;
00062
try {
00063
00064 Counter += 1;
00065 } except (Counter) {
00066 Counter += 1;
00067 }
00068
if (Counter != 1) {
00069
DbgPrint(
"BUG Exception clause executed when it shouldn't be\n");
00070 }
00071
DbgPrint(
"done\n");
00072
00073
00074
00075
00076
00077
DbgPrint(
"t3...");
00078 Counter = 0;
00079 ExceptionRecord.ExceptionFlags = 0;
00080
try {
00081 Counter -= 1;
00082
RtlRaiseException(&ExceptionRecord);
00083 } except (Counter) {
00084 Counter -= 1;
00085 }
00086
if (Counter != - 1) {
00087
DbgPrint(
"BUG Exception clause executed when it shouldn't be\n");
00088 }
00089
DbgPrint(
"done\n");
00090
00091
00092
00093
00094
DbgPrint(
"t4...");
00095 Counter = 0;
00096 ExceptionRecord.ExceptionFlags =
EXCEPTION_NONCONTINUABLE;
00097
try {
00098 Counter += 1;
00099
RtlRaiseException(&ExceptionRecord);
00100 } except (Counter) {
00101 Counter += 1;
00102 }
00103
if (Counter != 2) {
00104
DbgPrint(
"BUG Exception clause not executed when it should be\n");
00105 }
00106
DbgPrint(
"done\n");
00107
00108
00109
00110
00111
00112
00113
DbgPrint(
"t5...");
00114 Counter = 0;
00115 ExceptionRecord.ExceptionFlags = 0;
00116
try {
00117
try {
00118 Counter += 1;
00119
RtlRaiseException(&ExceptionRecord);
00120 } finally {
00121
if (abnormal_termination() != 0) {
00122 Counter += 1;
00123 }
00124 }
00125 } except (Counter) {
00126
if (Counter == 2) {
00127 Counter += 1;
00128 }
00129 }
00130
if (Counter != 3) {
00131
DbgPrint(
"BUG Finally clause executed as result of sequential exit\n");
00132 }
00133
DbgPrint(
"done\n");
00134
00135
00136
00137
00138
DbgPrint(
"t6...");
00139 Counter = 0;
00140 ExceptionRecord.ExceptionFlags =
EXCEPTION_NONCONTINUABLE;
00141
try {
00142
VOID foo(IN NTSTATUS Status);
00143
00144 Counter += 1;
00145
foo(STATUS_ACCESS_VIOLATION);
00146 } except (exception_code() == STATUS_ACCESS_VIOLATION) {
00147 Counter += 1;
00148 }
00149
if (Counter != 2) {
00150
DbgPrint(
"BUG Exception clause not executed when it should be\n");
00151 }
00152
DbgPrint(
"done\n");
00153
00154
00155
00156
00157
00158
00159
DbgPrint(
"t7...");
00160 Counter = 0;
00161 ExceptionRecord.ExceptionFlags =
EXCEPTION_NONCONTINUABLE;
00162
try {
00163
VOID bar(IN NTSTATUS Status, IN PULONG Counter);
00164
00165
bar(STATUS_ACCESS_VIOLATION, &Counter);
00166
00167 } except (exception_code() == STATUS_ACCESS_VIOLATION) {
00168
if (Counter != 99) {
00169
DbgPrint(
"BUG finally in called procedure not executed\n");
00170 }
00171 }
00172
DbgPrint(
"done\n");
00173
00174
00175
00176
00177
DbgPrint(
"t8...");
00178 Counter = 0;
00179 ExceptionRecord.ExceptionFlags =
EXCEPTION_NONCONTINUABLE;
00180
try {
00181
00182
foo(STATUS_ACCESS_VIOLATION);
00183
00184 } except (exception_code() == STATUS_ACCESS_VIOLATION) {
00185
00186 Counter++;
00187
00188
try {
00189
00190
foo(STATUS_SUCCESS);
00191
00192 } except (exception_code() == STATUS_SUCCESS) {
00193
if ( Counter != 1 ) {
00194
DbgPrint(
"BUG Previous Handler not Entered\n");
00195 }
00196 Counter++;
00197
00198 }
00199 }
00200
if (Counter != 2) {
00201
DbgPrint(
"BUG Both Handlers not entered\n");
00202 }
00203
DbgPrint(
"done\n");
00204
00205
00206
00207
00208
00209
DbgPrint(
"t9...");
00210 Counter = 0;
00211 ExceptionRecord.ExceptionFlags =
EXCEPTION_NONCONTINUABLE;
00212
try {
00213
try {
00214
foo(STATUS_ACCESS_VIOLATION);
00215 } except (exception_code() == STATUS_ACCESS_VIOLATION) {
00216 Counter++;
00217
goto t9;
00218 }
00219 } finally {
00220 Counter++;
00221 }
00222 t9:
00223
if (Counter != 2) {
00224
DbgPrint(
"BUG Finally and Exception Handlers not entered\n");
00225 }
00226
DbgPrint(
"done\n");
00227
00228
00229
00230
00231
00232
DbgPrint(
"t10...");
00233 Counter = 0;
00234 ExceptionRecord.ExceptionFlags =
EXCEPTION_NONCONTINUABLE;
00235
try {
00236
try {
00237 Counter++;
00238 } finally {
00239 Counter++;
00240
goto t10;
00241 }
00242 } finally {
00243 Counter++;
00244 }
00245 t10:
00246
if (Counter != 3) {
00247
DbgPrint(
"BUG Both Finally Handlers not entered\n");
00248 }
00249
DbgPrint(
"done\n");
00250
00251
00252
00253
00254
DbgPrint(
"t11...");
00255 Counter = 0;
00256 ExceptionRecord.ExceptionFlags =
EXCEPTION_NONCONTINUABLE;
00257
00258
try {
00259 ULONG
eret(IN NTSTATUS Status, IN PULONG Counter);
00260
00261 Counter++;
00262 rv =
eret(STATUS_ACCESS_VIOLATION, &Counter);
00263 } finally {
00264 Counter++;
00265 }
00266
00267
if (Counter != 4) {
00268
DbgPrint(
"BUG Both Finally Handlers and Exception Handler not entered\n");
00269 }
00270
if (rv != 0xDEADBEEF) {
00271
DbgPrint(
"BUG rv is wrong\n");
00272 }
00273
DbgPrint(
"done\n");
00274
00275
00276
00277
00278
DbgPrint(
"t12...");
00279 Counter = 0;
00280 ExceptionRecord.ExceptionFlags =
EXCEPTION_NONCONTINUABLE;
00281
00282
try {
00283
VOID fret(IN PULONG Counter);
00284
00285 Counter++;
00286
fret(&Counter);
00287 } finally {
00288 Counter++;
00289 }
00290
00291
if (Counter != 5) {
00292
DbgPrint(
"BUG All three Finally Handlers not entered\n");
00293 }
00294
DbgPrint(
"done\n");
00295
00296
00297
00298
00299
DbgPrint(
"End of exception test\n");
00300
00301
return;
00302 }