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 <setjmp.h>
7 
8 #include "seh.h"
9 
10 char test[] = "SEH0026.c";
11 int perfect;
12 
13 void dojump(jmp_buf JumpBuffer, PLONG Counter) {
14   try {
15     try {
16       /* set Counter = 1 */
17       *Counter += 1;
18       RaiseException(EXCEPTION_INT_OVERFLOW, 0, /*no flags*/ 0, 0);
19     }
20     finally {
21       /* set counter = 2 */
22       *Counter += 1;
23     }
24     endtry
25   }
26   finally {
27     /* set counter = 3 */
28     *Counter += 1;
29     longjmp(JumpBuffer, 1);
30   }
31   endtry
32 }
33 
34 int main() {
35   jmp_buf JumpBuffer;
36   LONG Counter;
37 
38   Counter = 0;
39 
40   if (_setjmp(JumpBuffer) == 0) {
41     try {
42       try {
43         try {
44           try {
45             *(volatile LONG*)&Counter += 1;
46             dojump(JumpBuffer, &Counter);
47           }
48           finally { *(volatile LONG*)&Counter += 1; }
49           endtry
50         }
51         finally {
52           *(volatile LONG*)&Counter += 1;
53           longjmp(JumpBuffer, 1);
54         }
55         endtry
56       }
57       finally { *(volatile LONG*)&Counter += 1; }
58       endtry
59     }
60     except(1)
61     /* EXECUTE HANDLER after unwinding */
62     {
63       *(volatile LONG*)&Counter += 1;
64     }
65     endtry
66   } else {
67     /* set Counter  = 4 */ //
68     *(volatile LONG*)&Counter += 1;
69   }
70 
71   if (Counter != 8) {
72     printf("TEST 26 FAILED. Counter = %d\n\r", Counter);
73     return -1;
74   }
75 
76   return 0;
77 }
78