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