1 // Copyright (c) Microsoft. All rights reserved.
2 // Licensed under the MIT license. See LICENSE file in the project root for
3 // full license information.
4 
5 #include <windows.h>
6 #include "seh.h"
7 
8 char test[] = "SEH0027.c";
9 
10 void rtlRaiseStatus(DWORD Status) {
11   RaiseException(Status, 0, /*no flags*/ 0, 0);
12   return;
13 }
14 
15 ULONG except3(PEXCEPTION_POINTERS ExceptionPointers, PLONG Counter) {
16   PEXCEPTION_RECORD ExceptionRecord;
17 
18   ExceptionRecord = ExceptionPointers->ExceptionRecord;
19   if ((ExceptionRecord->ExceptionCode == (STATUS_INTEGER_OVERFLOW)) &&
20       ((ExceptionRecord->ExceptionFlags & 0x10) == 0)) {
21     /* set counter = 23 */
22     *Counter += 17;
23     rtlRaiseStatus(EXCEPTION_EXECUTE_HANDLER);
24   } else if ((ExceptionRecord->ExceptionCode == EXCEPTION_EXECUTE_HANDLER) &&
25              ((ExceptionRecord->ExceptionFlags & 0x10) != 0)) {
26     /* set counter = 42 */
27     *Counter += 19;
28     /* return COTINUE SEARCH */
29     return 0;
30   }
31   /* never gets here due to exception being rasied */
32   *Counter += 23;
33   return 1;
34 }
35 
36 void except1(PLONG Counter) {
37   try {
38     /* set counter = 6 */
39     *Counter += 5;
40     RaiseException(EXCEPTION_INT_OVERFLOW, 0, /*no flags*/ 0, 0);
41   }
42   except(except3(GetExceptionInformation(), Counter)) { *Counter += 7; }
43   endtry
44   /* set counter = 59 */
45   *Counter += 9;
46   return;
47 }
48 
49 ULONG except2(PEXCEPTION_POINTERS ExceptionPointers, PLONG Counter) {
50   PEXCEPTION_RECORD ExceptionRecord;
51 
52   ExceptionRecord = ExceptionPointers->ExceptionRecord;
53   if ((ExceptionRecord->ExceptionCode == EXCEPTION_EXECUTE_HANDLER) &&
54       ((ExceptionRecord->ExceptionFlags & 0x10) == 0)) {
55     /* set counter = 53 */
56     *Counter += 11;
57     return 1;
58   } else {
59     *Counter += 13;
60     return 0;
61   }
62 }
63 
64 int main() {
65   LONG Counter;
66 
67   Counter = 0;
68 
69   try {
70     try {
71       /* set counter = 1 */
72       Counter += 1;
73       except1(&Counter);
74     }
75     except(except2(GetExceptionInformation(), &Counter)) {
76       /* set counter = 55 */
77       Counter += 2;
78     }
79     endtry
80   }
81   except(1) { Counter += 3; }
82   endtry
83 
84   if (Counter != 55) {
85     printf("TEST 27 FAILED. Counter = %d\n\r", Counter);
86     return -1;
87   }
88 
89   return 0;
90 }
91