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