Skip to content

Commit

Permalink
Convert exception throwing JIT helpers to managed code. (#105671)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
AaronRobinsonMSFT committed Aug 2, 2024
1 parent 280f2a0 commit 30b34e6
Show file tree
Hide file tree
Showing 23 changed files with 500 additions and 651 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@
<Compile Include="$(BclSourcesRoot)\System\Threading\ThreadPool.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\WaitHandle.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Type.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\ThrowHelper.cs" />
<Compile Include="$(BclSourcesRoot)\System\TypedReference.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\TypeLoadException.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\ValueType.cs" />
Expand Down
38 changes: 38 additions & 0 deletions src/coreclr/System.Private.CoreLib/src/System/ThrowHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace System
{
internal static unsafe partial class ThrowHelper
{
[DoesNotReturn]
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ExceptionNative_ThrowAmbiguousResolutionException")]
private static partial void ThrowAmbiguousResolutionException(MethodTable* targetType, MethodTable* interfaceType, void* methodDesc);

[DoesNotReturn]
internal static void ThrowAmbiguousResolutionException(
void* method, // MethodDesc*
void* interfaceType, // MethodTable*
void* targetType) // MethodTable*
{
ThrowAmbiguousResolutionException((MethodTable*)targetType, (MethodTable*)interfaceType, method);
}

[DoesNotReturn]
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ExceptionNative_ThrowEntryPointNotFoundException")]
private static partial void ThrowEntryPointNotFoundException(MethodTable* targetType, MethodTable* interfaceType, void* methodDesc);

[DoesNotReturn]
internal static void ThrowEntryPointNotFoundException(
void* method, // MethodDesc*
void* interfaceType, // MethodTable*
void* targetType) // MethodTable*
{
ThrowEntryPointNotFoundException((MethodTable*)targetType, (MethodTable*)interfaceType, method);
}
}
}
4 changes: 2 additions & 2 deletions src/coreclr/debug/daccess/daccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5656,8 +5656,8 @@ ClrDataAccess::GetJitHelperName(

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

Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/debug/daccess/dacdbiimplstackwalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -882,15 +882,15 @@ void DacDbiInterfaceImpl::InitFrameData(StackFrameIterator * pIter,
pJITFuncData->nativeOffset = pCF->GetRelOffset();

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

// Here is how we detect it:
// We can assume that nativeOffset points to an the instruction after [call IL_Throw] when these conditioins are met:
// We can assume that nativeOffset points to an the instruction after [call IL_Throw] when these conditions are met:
// 1. pCF->IsInterrupted() - Exception has been thrown by this managed frame (frame attr FRAME_ATTR_EXCEPTION)
// 2. !pCF->HasFaulted() - It wasn't a "hardware" exception (Access violation, dev by 0, etc.)
// 3. !pCF->IsIPadjusted() - It hasn't been previously adjusted to point to [call IL_Throw]
Expand Down
20 changes: 0 additions & 20 deletions src/coreclr/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -604,26 +604,6 @@ enum CorInfoHelpFunc
CORINFO_HELP_COUNT,
};

//This describes the signature for a helper method.
enum CorInfoHelpSig
{
CORINFO_HELP_SIG_UNDEF,
CORINFO_HELP_SIG_NO_ALIGN_STUB,
CORINFO_HELP_SIG_NO_UNWIND_STUB,
CORINFO_HELP_SIG_REG_ONLY,
CORINFO_HELP_SIG_4_STACK,
CORINFO_HELP_SIG_8_STACK,
CORINFO_HELP_SIG_12_STACK,
CORINFO_HELP_SIG_16_STACK,

CORINFO_HELP_SIG_EBPCALL, //special calling convention that uses EDX and
//EBP as arguments

CORINFO_HELP_SIG_CANNOT_USE_ALIGN_STUB,

CORINFO_HELP_SIG_COUNT
};

// The enumeration is returned in 'getSig','getType', getArgType methods
enum CorInfoType
{
Expand Down
Loading

0 comments on commit 30b34e6

Please sign in to comment.