Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NativeAOT rethrow bug #88113

Merged
merged 4 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -619,6 +619,7 @@ private static void DispatchEx(scoped ref StackFrameIterator frameIter, ref ExIn

OnFirstChanceExceptionViaClassLib(exceptionObj);

uint startIdx = MaxTryRegionIdx;
jkotas marked this conversation as resolved.
Show resolved Hide resolved
for (; isValid; isValid = frameIter.Next(&startIdx, &unwoundReversePInvoke))
{
// For GC stackwalking, we'll happily walk across native code blocks, but for EH dispatch, we
Expand Down
30 changes: 30 additions & 0 deletions src/tests/Regressions/coreclr/GitHub_88128/test88128.cs
Original file line number Diff line number Diff line change
@@ -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;
jkotas marked this conversation as resolved.
Show resolved Hide resolved
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;
}
}
10 changes: 10 additions & 0 deletions src/tests/Regressions/coreclr/GitHub_88128/test88128.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<CLRTestPriority>1</CLRTestPriority>
</PropertyGroup>
<ItemGroup>
<Compile Include="test88128.cs" />
</ItemGroup>
</Project>
Loading