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