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