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 12 void dojump(jmp_buf JumpBuffer, PLONG Counter) { 13 try { 14 try { 15 /* set Counter = 1 */ 16 *Counter += 1; 17 RaiseException(EXCEPTION_INT_OVERFLOW, 0, /*no flags*/ 0, 0); 18 } 19 finally { 20 /* set counter = 2 */ 21 *Counter += 1; 22 } 23 endtry 24 } 25 finally { 26 /* set counter = 3 */ 27 *Counter += 1; 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 try { 44 *(volatile LONG*)&Counter += 1; 45 dojump(JumpBuffer, &Counter); 46 } 47 finally { *(volatile LONG*)&Counter += 1; } 48 endtry 49 } 50 finally { 51 *(volatile LONG*)&Counter += 1; 52 longjmp(JumpBuffer, 1); 53 } 54 endtry 55 } 56 finally { *(volatile LONG*)&Counter += 1; } 57 endtry 58 } 59 except(1) 60 /* EXECUTE HANDLER after unwinding */ 61 { 62 *(volatile LONG*)&Counter += 1; 63 } 64 endtry 65 } else { 66 /* set Counter = 4 */ // 67 *(volatile LONG*)&Counter += 1; 68 } 69 70 if (Counter != 8) { 71 printf("TEST 26 FAILED. Counter = %d\n\r", Counter); 72 return -1; 73 } 74 75 return 0; 76 } 77