Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

x86: Deactivate P/Invoke frames after a native call. #8464

Merged
merged 2 commits into from
Dec 6, 2016
Merged
Changes from 1 commit
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
14 changes: 13 additions & 1 deletion src/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2963,7 +2963,7 @@ void Lowering::InsertPInvokeCallEpilog(GenTreeCall* call)
BlockRange().InsertBefore(insertionPoint, LIR::SeqTree(comp, tree));

// Pop the frame if necessary. On 32-bit targets this only happens in the method epilog; on 64-bit targets thi

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conflict with what you added:

On 32-bit targets this only happens in the method epilog;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a difference between popping and deactivating a frame: the latter removes the frame from its thread's frame list, while the former leaves the frame on the list but marks it s.t. the stack walker ignores it.

// happens after every PInvoke call in non-stubs.
// happens after every PInvoke call in non-stubs. 32-bit targets instead mark the frame as inactive.
CLANG_FORMAT_COMMENT_ANCHOR;

#ifdef _TARGET_64BIT_
Expand All @@ -2972,6 +2972,18 @@ void Lowering::InsertPInvokeCallEpilog(GenTreeCall* call)
tree = CreateFrameLinkUpdate(PopFrame);
BlockRange().InsertBefore(insertionPoint, LIR::SeqTree(comp, tree));
}
#else
const CORINFO_EE_INFO::InlinedCallFrameInfo& callFrameInfo = comp->eeGetEEInfo()->inlinedCallFrameInfo;

GenTreeLclFld* const storeCallSiteTracker =
Copy link

@briansull briansull Dec 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment similar to this one should be added:
(This is the comment that is used when we setup this value in InsertPInvokeCallProlog)

     // ----------------------------------------------------------------------------------
     // InlinedCallFrame.m_pCallerReturnAddress = &label (the address of the instruction immediately following the call)		     // InlinedCallFrame.m_pCallerReturnAddress = &label (the address of the instruction immediately following the call)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

new (comp, GT_STORE_LCL_FLD) GenTreeLclFld(GT_STORE_LCL_FLD, TYP_I_IMPL, comp->lvaInlinedPInvokeFrameVar,
callFrameInfo.offsetOfReturnAddress);

GenTreeIntCon* const constantZero = new (comp, GT_CNS_INT) GenTreeIntCon(TYP_I_IMPL, 0);

storeCallSiteTracker->gtOp1 = constantZero;

BlockRange().InsertBefore(insertionPoint, constantZero, storeCallSiteTracker);
#endif // _TARGET_64BIT_
}

Expand Down