From d50b8c93fbbb23a52ce076283bd3f21d3615feec Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Wed, 27 Aug 2025 12:20:36 +0300 Subject: [PATCH] [PSEH] Fix a bug with try inside except PSEH has 2 scopes: an outer scope, that starts with _SEH3_TRY and ends with _SEH3_END, and an inner scope that goes around the try block only. PSEH tracks try-levels by using an enum, which increments at every new TRY scrope, and which needs to be accessible in the outer scope for all registration and cleanup to work. But it should only increment when nested within the inner try scope, not from the except scope. This is fixed by adding an additional _SEH3$_InnerTryLevel, which increments only within the try block, but resets to the parent-value outside of it. Should fix CORE-20316. --- sdk/lib/pseh/include/pseh/pseh3.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sdk/lib/pseh/include/pseh/pseh3.h b/sdk/lib/pseh/include/pseh/pseh3.h index ce1ea5d0489..cea3f84e462 100644 --- a/sdk/lib/pseh/include/pseh/pseh3.h +++ b/sdk/lib/pseh/include/pseh/pseh3.h @@ -112,6 +112,7 @@ void _SEH3$_UnregisterTryLevel( enum { _SEH3$_TryLevel = -1, + _SEH3$_InnerTryLevel = -1, }; #ifndef __clang__ @@ -375,7 +376,7 @@ _Pragma("GCC diagnostic pop") \ \ /* Count the try level. Outside of any __try, _SEH3$_TryLevel is -1 */ \ enum { \ - _SEH3$_PreviousTryLevel = _SEH3$_TryLevel, \ + _SEH3$_PreviousTryLevel = _SEH3$_InnerTryLevel, \ _SEH3$_TryLevel = _SEH3$_PreviousTryLevel + 1, \ }; \ \ @@ -388,6 +389,11 @@ _Pragma("GCC diagnostic pop") \ goto _SEH3$_l_BeforeTry; \ { \ __label__ _SEH3$_l_Leave; \ +\ + enum { \ + _SEH3$_InnerTryLevel = _SEH3$_TryLevel, \ + }; \ +\ _SEH3$_l_Leave: (void)0; \ /* Silence warning */ goto _SEH3$_l_AfterTry; \ /* Silence warning */ goto _SEH3$_l_Leave; \