diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
index d1ea61f025f9..81d474349d49 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
@@ -588,8 +588,6 @@ The .NET Foundation licenses this file to you under the MIT license.
-
-
@@ -601,13 +599,15 @@ The .NET Foundation licenses this file to you under the MIT license.
-
-
-
-
+
+
-
+
+
+
+
+
diff --git a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.wasm.cs b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.wasm.cs
index 18168f11c6cd..534e663f7cd6 100644
--- a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.wasm.cs
+++ b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.wasm.cs
@@ -96,7 +96,7 @@ private static void DispatchException(object exception, RhEHFrameType flags)
}
else
{
- if (ShouldTypedClauseCatchThisException(exception, clause.ClauseType, false /* tryUnwrapException, not used for NATIVEAOT */))
+ if (ShouldTypedClauseCatchThisException(exception, clause.ClauseType))
{
goto FoundHandler;
}
@@ -869,4 +869,98 @@ public static int Parse(byte* pUnwindInfo, uint* pShadowFrameSize = null, void**
return (int)(pCurrent - pUnwindInfo);
}
}
+
+ // TODO-LLVM-Upstream: create ExceptionHandling.Common.cs and put the things below there.
+ internal static unsafe partial class EH
+ {
+ private enum RhEHFrameType
+ {
+ RH_EH_FIRST_FRAME = 1,
+ RH_EH_FIRST_RETHROW_FRAME = 2,
+ }
+
+ private enum RhEHClauseKind
+ {
+ RH_EH_CLAUSE_TYPED = 0,
+ RH_EH_CLAUSE_FAULT = 1,
+ RH_EH_CLAUSE_FILTER = 2,
+ RH_EH_CLAUSE_UNUSED = 3,
+ }
+
+ internal struct MethodRegionInfo
+ {
+ }
+
+ internal struct ExInfo
+ {
+ }
+
+ internal struct PAL_LIMITED_CONTEXT
+ {
+ }
+
+ [StackTraceHidden]
+ [RuntimeExport("RhExceptionHandling_FailedAllocation")]
+ public static void FailedAllocation(MethodTable* pEEType, bool fIsOverflow)
+ {
+ ExceptionIDs exID = fIsOverflow ? ExceptionIDs.Overflow : ExceptionIDs.OutOfMemory;
+
+ // Throw the out of memory exception defined by the classlib, using the input MethodTable*
+ // to find the correct classlib.
+
+ throw pEEType->GetClasslibException(exID);
+ }
+
+ private static bool ShouldTypedClauseCatchThisException(object exception, MethodTable* pClauseType)
+ {
+ return TypeCast.IsInstanceOfException(pClauseType, exception);
+ }
+
+ private static void OnFirstChanceExceptionViaClassLib(object exception)
+ {
+ IntPtr pOnFirstChanceFunction =
+ (IntPtr)InternalCalls.RhpGetClasslibFunctionFromEEType(exception.GetMethodTable(), ClassLibFunctionId.OnFirstChance);
+
+ if (pOnFirstChanceFunction == IntPtr.Zero)
+ {
+ return;
+ }
+
+ try
+ {
+ ((delegate*