Skip to content

Commit 4d21384

Browse files
committed
[COMPILER_APITEST] Add a test for collided unwind
1 parent 6334168 commit 4d21384

File tree

1 file changed

+56
-0
lines changed
  • modules/rostests/apitests/compiler

1 file changed

+56
-0
lines changed

modules/rostests/apitests/compiler/pseh.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2920,6 +2920,61 @@ static void Test_structs_seh_nested(void)
29202920

29212921
#endif // _M_IX86
29222922

2923+
void Test_collided_unwind(void)
2924+
{
2925+
volatile int Flags = 0;
2926+
volatile int Count = 0;
2927+
jmp_buf JumpBuffer;
2928+
int ret;
2929+
#ifdef _M_IX86
2930+
unsigned int Registration = __readfsdword(0);
2931+
#endif
2932+
2933+
ret = setjmp(JumpBuffer);
2934+
if (ret == 0)
2935+
{
2936+
_SEH2_TRY
2937+
{
2938+
_SEH2_TRY
2939+
{
2940+
_SEH2_TRY
2941+
{
2942+
Flags |= 1;
2943+
*((volatile int*)(LONG_PTR)-1) = 123;
2944+
}
2945+
_SEH2_FINALLY
2946+
{
2947+
Count++;
2948+
Flags |= 2;
2949+
if (Count) // This is to prevent the compiler from optimizing stuff out
2950+
longjmp(JumpBuffer, 1);
2951+
Flags |= 4;
2952+
}
2953+
_SEH2_END;
2954+
}
2955+
_SEH2_FINALLY
2956+
{
2957+
Count++;
2958+
Flags |= 8;
2959+
}
2960+
_SEH2_END;
2961+
}
2962+
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
2963+
{
2964+
Flags |= 16;
2965+
}
2966+
_SEH2_END;
2967+
}
2968+
2969+
todo_ros ok(Flags == (1 | 2 | 8), "Flags = %x\n", Flags);
2970+
todo_ros ok(Count == 2, "Count = %d\n", Count);
2971+
#ifdef _M_IX86
2972+
todo_ros ok(__readfsdword(0) == Registration, "SEH registration corrupted!\n");
2973+
*(unsigned int*)NtCurrentTeb() = Registration;
2974+
#endif
2975+
2976+
}
2977+
29232978
START_TEST(pseh)
29242979
{
29252980
#ifdef _M_IX86
@@ -2928,6 +2983,7 @@ START_TEST(pseh)
29282983
Test_structs_seh_finally();
29292984
Test_structs_seh_nested();
29302985
#endif
2986+
Test_collided_unwind();
29312987

29322988
const struct subtest testsuite[] =
29332989
{

0 commit comments

Comments
 (0)