From 4d21384d8f2e8a992abbf96461563e75f7a8b69c Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Fri, 11 Jul 2025 10:20:13 +0300 Subject: [PATCH] [COMPILER_APITEST] Add a test for collided unwind --- modules/rostests/apitests/compiler/pseh.c | 56 +++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/modules/rostests/apitests/compiler/pseh.c b/modules/rostests/apitests/compiler/pseh.c index ec5f3c72bd3..ecdaaa687ab 100644 --- a/modules/rostests/apitests/compiler/pseh.c +++ b/modules/rostests/apitests/compiler/pseh.c @@ -2920,6 +2920,61 @@ static void Test_structs_seh_nested(void) #endif // _M_IX86 +void Test_collided_unwind(void) +{ + volatile int Flags = 0; + volatile int Count = 0; + jmp_buf JumpBuffer; + int ret; +#ifdef _M_IX86 + unsigned int Registration = __readfsdword(0); +#endif + + ret = setjmp(JumpBuffer); + if (ret == 0) + { + _SEH2_TRY + { + _SEH2_TRY + { + _SEH2_TRY + { + Flags |= 1; + *((volatile int*)(LONG_PTR)-1) = 123; + } + _SEH2_FINALLY + { + Count++; + Flags |= 2; + if (Count) // This is to prevent the compiler from optimizing stuff out + longjmp(JumpBuffer, 1); + Flags |= 4; + } + _SEH2_END; + } + _SEH2_FINALLY + { + Count++; + Flags |= 8; + } + _SEH2_END; + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + Flags |= 16; + } + _SEH2_END; + } + + todo_ros ok(Flags == (1 | 2 | 8), "Flags = %x\n", Flags); + todo_ros ok(Count == 2, "Count = %d\n", Count); +#ifdef _M_IX86 + todo_ros ok(__readfsdword(0) == Registration, "SEH registration corrupted!\n"); + *(unsigned int*)NtCurrentTeb() = Registration; +#endif + +} + START_TEST(pseh) { #ifdef _M_IX86 @@ -2928,6 +2983,7 @@ START_TEST(pseh) Test_structs_seh_finally(); Test_structs_seh_nested(); #endif + Test_collided_unwind(); const struct subtest testsuite[] = {