Skip to content

Commit 30b34e6

Browse files
Convert exception throwing JIT helpers to managed code. (#105671)
* Change JIT helper definition macro to encode BinderMethodID. Remove CorInfoHelpSig and replace with BinderMethodID in macros. Convert start up loading of managed JIT helpers to lazy model. * Remove the early start-up registration of managed JIT helpers. * Narrowly permit type loading in SPCL during eager fixup for R2R images.
1 parent 280f2a0 commit 30b34e6

File tree

23 files changed

+500
-651
lines changed

23 files changed

+500
-651
lines changed

src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@
231231
<Compile Include="$(BclSourcesRoot)\System\Threading\ThreadPool.CoreCLR.cs" />
232232
<Compile Include="$(BclSourcesRoot)\System\Threading\WaitHandle.CoreCLR.cs" />
233233
<Compile Include="$(BclSourcesRoot)\System\Type.CoreCLR.cs" />
234+
<Compile Include="$(BclSourcesRoot)\System\ThrowHelper.cs" />
234235
<Compile Include="$(BclSourcesRoot)\System\TypedReference.CoreCLR.cs" />
235236
<Compile Include="$(BclSourcesRoot)\System\TypeLoadException.CoreCLR.cs" />
236237
<Compile Include="$(BclSourcesRoot)\System\ValueType.cs" />
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Diagnostics.CodeAnalysis;
5+
using System.Runtime.CompilerServices;
6+
using System.Runtime.InteropServices;
7+
8+
namespace System
9+
{
10+
internal static unsafe partial class ThrowHelper
11+
{
12+
[DoesNotReturn]
13+
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ExceptionNative_ThrowAmbiguousResolutionException")]
14+
private static partial void ThrowAmbiguousResolutionException(MethodTable* targetType, MethodTable* interfaceType, void* methodDesc);
15+
16+
[DoesNotReturn]
17+
internal static void ThrowAmbiguousResolutionException(
18+
void* method, // MethodDesc*
19+
void* interfaceType, // MethodTable*
20+
void* targetType) // MethodTable*
21+
{
22+
ThrowAmbiguousResolutionException((MethodTable*)targetType, (MethodTable*)interfaceType, method);
23+
}
24+
25+
[DoesNotReturn]
26+
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ExceptionNative_ThrowEntryPointNotFoundException")]
27+
private static partial void ThrowEntryPointNotFoundException(MethodTable* targetType, MethodTable* interfaceType, void* methodDesc);
28+
29+
[DoesNotReturn]
30+
internal static void ThrowEntryPointNotFoundException(
31+
void* method, // MethodDesc*
32+
void* interfaceType, // MethodTable*
33+
void* targetType) // MethodTable*
34+
{
35+
ThrowEntryPointNotFoundException((MethodTable*)targetType, (MethodTable*)interfaceType, method);
36+
}
37+
}
38+
}

src/coreclr/debug/daccess/daccess.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5656,8 +5656,8 @@ ClrDataAccess::GetJitHelperName(
56565656

56575657
// Check if its a dynamically generated JIT helper
56585658
const static CorInfoHelpFunc s_rgDynamicHCallIds[] = {
5659-
#define DYNAMICJITHELPER(code, fn, sig) code,
5660-
#define JITHELPER(code, fn,sig)
5659+
#define DYNAMICJITHELPER(code, fn, binderId) code,
5660+
#define JITHELPER(code, fn, binderId)
56615661
#include <jithelpers.h>
56625662
};
56635663

src/coreclr/debug/daccess/dacdbiimplstackwalk.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -882,15 +882,15 @@ void DacDbiInterfaceImpl::InitFrameData(StackFrameIterator * pIter,
882882
pJITFuncData->nativeOffset = pCF->GetRelOffset();
883883

884884
// Here we detect (and set the appropriate flag) if the nativeOffset in the current frame points to the return address of IL_Throw()
885-
// (or other exception related JIT helpers like IL_Throw, IL_Rethrow, JIT_RngChkFail, IL_VerificationError, JIT_Overflow etc).
886-
// Since return addres point to the next(!) instruction after [call IL_Throw] this sometimes can lead to incorrect exception stacktraces
885+
// (or other exception related JIT helpers like IL_Throw, IL_Rethrow etc).
886+
// Since return address point to the next(!) instruction after [call IL_Throw] this sometimes can lead to incorrect exception stacktraces
887887
// where a next source line is spotted as an exception origin. This happens when the next instruction after [call IL_Throw] belongs to
888888
// a sequence point and a source line different from a sequence point and a source line of [call IL_Throw].
889889
// Later on this flag is used in order to adjust nativeOffset and make ICorDebugILFrame::GetIP return IL offset within
890890
// the same sequence point as an actual IL throw instruction.
891891

892892
// Here is how we detect it:
893-
// We can assume that nativeOffset points to an the instruction after [call IL_Throw] when these conditioins are met:
893+
// We can assume that nativeOffset points to an the instruction after [call IL_Throw] when these conditions are met:
894894
// 1. pCF->IsInterrupted() - Exception has been thrown by this managed frame (frame attr FRAME_ATTR_EXCEPTION)
895895
// 2. !pCF->HasFaulted() - It wasn't a "hardware" exception (Access violation, dev by 0, etc.)
896896
// 3. !pCF->IsIPadjusted() - It hasn't been previously adjusted to point to [call IL_Throw]

src/coreclr/inc/corinfo.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -604,26 +604,6 @@ enum CorInfoHelpFunc
604604
CORINFO_HELP_COUNT,
605605
};
606606

607-
//This describes the signature for a helper method.
608-
enum CorInfoHelpSig
609-
{
610-
CORINFO_HELP_SIG_UNDEF,
611-
CORINFO_HELP_SIG_NO_ALIGN_STUB,
612-
CORINFO_HELP_SIG_NO_UNWIND_STUB,
613-
CORINFO_HELP_SIG_REG_ONLY,
614-
CORINFO_HELP_SIG_4_STACK,
615-
CORINFO_HELP_SIG_8_STACK,
616-
CORINFO_HELP_SIG_12_STACK,
617-
CORINFO_HELP_SIG_16_STACK,
618-
619-
CORINFO_HELP_SIG_EBPCALL, //special calling convention that uses EDX and
620-
//EBP as arguments
621-
622-
CORINFO_HELP_SIG_CANNOT_USE_ALIGN_STUB,
623-
624-
CORINFO_HELP_SIG_COUNT
625-
};
626-
627607
// The enumeration is returned in 'getSig','getType', getArgType methods
628608
enum CorInfoType
629609
{

0 commit comments

Comments
 (0)