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 int perfect; 11 12 void dojump(jmp_buf JumpBuffer, PLONG Counter) { 13 try { 14 try { 15 /* set counter = 2 */ 16 (*Counter) += 1; 17 RaiseException(EXCEPTION_INT_OVERFLOW, 0, /*no flags*/ 0, 0); 18 } 19 finally { 20 /* set counter = 3 */ 21 (*Counter) += 1; 22 } 23 endtry 24 } 25 finally { 26 /* set counter = 4 */ 27 (*Counter) += 1; 28 /* end unwinding with longjump */ 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 /* set counter = 1 */ 45 //(volatile LONG) Counter += 1; 46 *(volatile LONG*)&Counter += 1; 47 dojump(JumpBuffer, &Counter); 48 } 49 finally { 50 /* set counter = 5 */ 51 //(volatile LONG) Counter += 1; 52 *(volatile LONG*)&Counter += 1; 53 } 54 endtry 55 } 56 finally { 57 /* set counter = 6 */ 58 //(volatile LONG) Counter += 1; 59 *(volatile LONG*)&Counter += 1; 60 } 61 endtry 62 } 63 except(1) 64 /* 65 * handle exception raised in function 66 * after unwinding 67 */ 68 { 69 //(volatile LONG) Counter += 1; 70 *(volatile LONG*)&Counter += 1; 71 } 72 endtry 73 } else { 74 /* set counter = 7 */ 75 //(volatile LONG) Counter += 1; 76 *(volatile LONG*)&Counter += 1; 77 } 78 79 if (Counter != 7) { 80 printf("TEST 25 FAILED. Counter = %d\n\r", Counter); 81 return -1; 82 } 83 84 return 0; 85 } 86