diff --git a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs index 31f21abf28361f..8b369ad0d3e71e 100644 --- a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs +++ b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs @@ -547,7 +547,7 @@ public static void RhThrowHwEx(uint exceptionCode, ref ExInfo exInfo) } exInfo.Init(exceptionToThrow!, instructionFault); - DispatchEx(ref exInfo._frameIter, ref exInfo, MaxTryRegionIdx); + DispatchEx(ref exInfo._frameIter, ref exInfo); FallbackFailFast(RhFailFastReason.InternalError, null); } @@ -569,7 +569,7 @@ public static void RhThrowEx(object exceptionObj, ref ExInfo exInfo) } exInfo.Init(exceptionObj); - DispatchEx(ref exInfo._frameIter, ref exInfo, MaxTryRegionIdx); + DispatchEx(ref exInfo._frameIter, ref exInfo); FallbackFailFast(RhFailFastReason.InternalError, null); } @@ -586,11 +586,11 @@ public static void RhRethrow(ref ExInfo activeExInfo, ref ExInfo exInfo) object rethrownException = activeExInfo.ThrownException; exInfo.Init(rethrownException, ref activeExInfo); - DispatchEx(ref exInfo._frameIter, ref exInfo, activeExInfo._idxCurClause); + DispatchEx(ref exInfo._frameIter, ref exInfo); FallbackFailFast(RhFailFastReason.InternalError, null); } - private static void DispatchEx(scoped ref StackFrameIterator frameIter, ref ExInfo exInfo, uint startIdx) + private static void DispatchEx(scoped ref StackFrameIterator frameIter, ref ExInfo exInfo) { Debug.Assert(exInfo._passNumber == 1, "expected asm throw routine to set the pass"); object exceptionObj = exInfo.ThrownException; @@ -604,7 +604,7 @@ private static void DispatchEx(scoped ref StackFrameIterator frameIter, ref ExIn byte* pCatchHandler = null; uint catchingTryRegionIdx = MaxTryRegionIdx; - bool isFirstRethrowFrame = (startIdx != MaxTryRegionIdx); + bool isFirstRethrowFrame = (exInfo._kind & ExKind.RethrowFlag) != 0; bool isFirstFrame = true; byte* prevControlPC = null; @@ -619,6 +619,7 @@ private static void DispatchEx(scoped ref StackFrameIterator frameIter, ref ExIn OnFirstChanceExceptionViaClassLib(exceptionObj); + uint startIdx = MaxTryRegionIdx; for (; isValid; isValid = frameIter.Next(&startIdx, &unwoundReversePInvoke)) { // For GC stackwalking, we'll happily walk across native code blocks, but for EH dispatch, we diff --git a/src/tests/Regressions/coreclr/GitHub_88128/test88128.cs b/src/tests/Regressions/coreclr/GitHub_88128/test88128.cs new file mode 100644 index 00000000000000..c6975b198e66a3 --- /dev/null +++ b/src/tests/Regressions/coreclr/GitHub_88128/test88128.cs @@ -0,0 +1,30 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Reflection; + +public class test88113 +{ + public static int Main() + { + try + { + throw new Exception("boo"); + } + catch (Exception ex2) + { + Console.WriteLine($"1: {ex2}"); + try + { + throw; + } + catch (Exception ex3) + { + Console.WriteLine($"2: {ex3}"); + } + } + + return 100; + } +} diff --git a/src/tests/Regressions/coreclr/GitHub_88128/test88128.csproj b/src/tests/Regressions/coreclr/GitHub_88128/test88128.csproj new file mode 100644 index 00000000000000..49e01e50f35df0 --- /dev/null +++ b/src/tests/Regressions/coreclr/GitHub_88128/test88128.csproj @@ -0,0 +1,10 @@ + + + Exe + true + 1 + + + + +