Skip to content

Commit

Permalink
Add SEH hookup and profiler/debugger hooks to Reverse P/Invoke entry …
Browse files Browse the repository at this point in the history
…helper to match custom x86 thunk.

Fixes dotnet#46177
  • Loading branch information
jkoritzinsky committed Dec 17, 2020
1 parent c6f5880 commit d54420b
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 51 deletions.
11 changes: 6 additions & 5 deletions src/coreclr/inc/jiteeversionguid.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
// NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//

constexpr GUID JITEEVersionIdentifier = { /* {a7bb194e-4e7c-4850-af12-ea9f30ea5a13} */
0xa7bb194e,
0x4e7c,
0x4850,
{0xaf, 0x12, 0xea, 0x9f, 0x30, 0xea, 0x5a, 0x13}
constexpr GUID JITEEVersionIdentifier = { /* {71a99045-a4fe-43b3-abd9-c1742ab020b3} */
0x71a99045,
0xa4fe,
0x43b3,
{0xab, 0xd9, 0xc1, 0x74, 0x2a, 0xb0, 0x20, 0xb3}
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/inc/readytorun.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ struct READYTORUN_EXCEPTION_CLAUSE
enum ReadyToRunRuntimeConstants : DWORD
{
READYTORUN_PInvokeTransitionFrameSizeInPointerUnits = 11,
READYTORUN_ReversePInvokeTransitionFrameSizeInPointerUnits = 2
READYTORUN_ReversePInvokeTransitionFrameSizeInPointerUnits = 5
};

enum ReadyToRunHFAElemType : DWORD
Expand Down
24 changes: 20 additions & 4 deletions src/coreclr/jit/flowgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8610,13 +8610,29 @@ void Compiler::fgAddReversePInvokeEnterExit()
varDsc->lvType = TYP_BLK;
varDsc->lvExactSize = eeGetEEInfo()->sizeOfReversePInvokeFrame;

GenTree* tree;

// Add enter pinvoke exit callout at the start of prolog

tree = gtNewOperNode(GT_ADDR, TYP_I_IMPL, gtNewLclvNode(lvaReversePInvokeFrameVar, TYP_BLK));
GenTree* pInvokeFrameVar = gtNewOperNode(GT_ADDR, TYP_I_IMPL, gtNewLclvNode(lvaReversePInvokeFrameVar, TYP_BLK));

GenTree* stubArgument;

if (info.compPublishStubParam)
{
// If we have a secret param for a Reverse P/Invoke, that means that we are in an IL stub.
// In this case, the method handle we pass down to the Reverse P/Invoke helper should be
// the target method, which is passed in the secret parameter.
stubArgument = gtNewLclvNode(lvaStubArgumentVar, TYP_I_IMPL);
}
else
{
stubArgument = gtNewIconNode(0, TYP_I_IMPL);
}

GenTree* tree;

GenTreeCall::Use* args = gtNewCallArgs(pInvokeFrameVar, gtNewIconEmbMethHndNode(info.compMethodHnd), stubArgument);

tree = gtNewHelperCallNode(CORINFO_HELP_JIT_REVERSE_PINVOKE_ENTER, TYP_VOID, gtNewCallArgs(tree));
tree = gtNewHelperCallNode(CORINFO_HELP_JIT_REVERSE_PINVOKE_ENTER, TYP_VOID, args);

fgEnsureFirstBBisScratch();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public enum ReadyToRunFixupKind
IndirectPInvokeTarget = 0x2E, // Target (indirect) of an inlined pinvoke
PInvokeTarget = 0x2F, // Target of an inlined pinvoke

Check_InstructionSetSupport = 0x30, // Define the set of instruction sets that must be supported/unsupported to use the fixup
Check_InstructionSetSupport = 0x30, // Define the set of instruction sets that must be supported/unsupported to use the fixup

Verify_FieldOffset = 0x31, // Generate a runtime check to ensure that the field offset matches between compile and runtime. Unlike CheckFieldOffset, this will generate a runtime exception on failure instead of silently dropping the method
Verify_TypeLayout = 0x32, // Generate a runtime check to ensure that the type layout (size, alignment, HFA, reference map) matches between compile and runtime. Unlike Check_TypeLayout, this will generate a runtime failure instead of silently dropping the method
Expand Down Expand Up @@ -330,6 +330,6 @@ public enum ReadyToRunHFAElemType
public static class ReadyToRunRuntimeConstants
{
public const int READYTORUN_PInvokeTransitionFrameSizeInPointerUnits = 11;
public const int READYTORUN_ReversePInvokeTransitionFrameSizeInPointerUnits = 2;
public const int READYTORUN_ReversePInvokeTransitionFrameSizeInPointerUnits = 5;
}
}
4 changes: 4 additions & 0 deletions src/coreclr/vm/frames.h
Original file line number Diff line number Diff line change
Expand Up @@ -2787,6 +2787,10 @@ class UMThkCallFrame : public UnmanagedToManagedFrame
struct ReversePInvokeFrame
{
Thread* currentThread;
MethodDesc* pMD;
#ifndef FEATURE_EH_FUNCLETS
FrameHandlerExRecord record;
#endif
};

#if defined(TARGET_X86) && defined(FEATURE_COMINTEROP)
Expand Down
Loading

0 comments on commit d54420b

Please sign in to comment.