Skip to content

Commit 59ca590

Browse files
author
Fadi Hanna
authored
Fix incorrect assumption around the presence of ICF frames in EH codebase for 64-bit targets (#34526)
1 parent 6d395de commit 59ca590

File tree

2 files changed

+9
-33
lines changed

2 files changed

+9
-33
lines changed

src/coreclr/src/vm/exceptionhandling.cpp

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,10 +1104,8 @@ ProcessCLRException(IN PEXCEPTION_RECORD pExceptionRecord
11041104

11051105
CLRUnwindStatus status;
11061106

1107-
#ifdef USE_PER_FRAME_PINVOKE_INIT
11081107
// Refer to comment in ProcessOSExceptionNotification about ICF and codegen difference.
11091108
InlinedCallFrame *pICFSetAsLimitFrame = NULL;
1110-
#endif // USE_PER_FRAME_PINVOKE_INIT
11111109

11121110
status = pTracker->ProcessOSExceptionNotification(
11131111
pExceptionRecord,
@@ -1116,11 +1114,8 @@ ProcessCLRException(IN PEXCEPTION_RECORD pExceptionRecord
11161114
dwExceptionFlags,
11171115
sf,
11181116
pThread,
1119-
STState
1120-
#ifdef USE_PER_FRAME_PINVOKE_INIT
1121-
, (PVOID)pICFSetAsLimitFrame
1122-
#endif // USE_PER_FRAME_PINVOKE_INIT
1123-
);
1117+
STState,
1118+
(PVOID)pICFSetAsLimitFrame);
11241119

11251120
if (FirstPassComplete == status)
11261121
{
@@ -1223,7 +1218,6 @@ ProcessCLRException(IN PEXCEPTION_RECORD pExceptionRecord
12231218

12241219

12251220
CONSISTENCY_CHECK(pLimitFrame > dac_cast<PTR_VOID>(GetSP(pContextRecord)));
1226-
#ifdef USE_PER_FRAME_PINVOKE_INIT
12271221
if (pICFSetAsLimitFrame != NULL)
12281222
{
12291223
_ASSERTE(pICFSetAsLimitFrame == pLimitFrame);
@@ -1235,7 +1229,6 @@ ProcessCLRException(IN PEXCEPTION_RECORD pExceptionRecord
12351229
// the next pinvoke callsite does not see the frame as active.
12361230
pICFSetAsLimitFrame->Reset();
12371231
}
1238-
#endif // USE_PER_FRAME_PINVOKE_INIT
12391232

12401233
pThread->SetFrame(pLimitFrame);
12411234

@@ -1715,11 +1708,8 @@ CLRUnwindStatus ExceptionTracker::ProcessOSExceptionNotification(
17151708
DWORD dwExceptionFlags,
17161709
StackFrame sf,
17171710
Thread* pThread,
1718-
StackTraceState STState
1719-
#ifdef USE_PER_FRAME_PINVOKE_INIT
1720-
, PVOID pICFSetAsLimitFrame
1721-
#endif // USE_PER_FRAME_PINVOKE_INIT
1722-
)
1711+
StackTraceState STState,
1712+
PVOID pICFSetAsLimitFrame)
17231713
{
17241714
CONTRACTL
17251715
{
@@ -1785,10 +1775,8 @@ CLRUnwindStatus ExceptionTracker::ProcessOSExceptionNotification(
17851775
this->m_EnclosingClauseInfoForGCReporting.SetEnclosingClauseCallerSP(uCallerSP);
17861776
}
17871777

1788-
#ifdef USE_PER_FRAME_PINVOKE_INIT
17891778
// Refer to detailed comment below.
17901779
PTR_Frame pICFForUnwindTarget = NULL;
1791-
#endif // USE_PER_FRAME_PINVOKE_INIT
17921780

17931781
CheckForRudeAbort(pThread, fIsFirstPass);
17941782

@@ -1817,15 +1805,12 @@ CLRUnwindStatus ExceptionTracker::ProcessOSExceptionNotification(
18171805

18181806
while (((UINT_PTR)pFrame) < uCallerSP)
18191807
{
1820-
#ifdef USE_PER_FRAME_PINVOKE_INIT
18211808
// InlinedCallFrames (ICF) are allocated, initialized and linked to the Frame chain
18221809
// by the code generated by the JIT for a method containing a PInvoke.
18231810
//
1824-
// On X64, JIT generates code to dynamically link and unlink the ICF around
1825-
// each PInvoke call. On ARM, on the other hand, JIT's codegen, in context of ICF,
1826-
// is more inline with X86 and thus, it links in the ICF at the start of the method
1827-
// and unlinks it towards the method end. Thus, ICF is present on the Frame chain
1828-
// at any given point so long as the method containing the PInvoke is on the stack.
1811+
// JIT generates code that links in the ICF at the start of the method and unlinks it towards
1812+
// the method end. Thus, ICF is present on the Frame chain at any given point so long as the
1813+
// method containing the PInvoke is on the stack.
18291814
//
18301815
// Now, if the method containing ICF catches an exception, we will reset the Frame chain
18311816
// with the LimitFrame, that is computed below, after the catch handler returns. Since this
@@ -1895,7 +1880,6 @@ CLRUnwindStatus ExceptionTracker::ProcessOSExceptionNotification(
18951880
}
18961881
}
18971882
}
1898-
#endif // USE_PER_FRAME_PINVOKE_INIT
18991883

19001884
cfThisFrame.CheckGSCookies();
19011885

@@ -2040,7 +2024,6 @@ CLRUnwindStatus ExceptionTracker::ProcessOSExceptionNotification(
20402024

20412025
if (fTargetUnwind && (status == SecondPassComplete))
20422026
{
2043-
#ifdef USE_PER_FRAME_PINVOKE_INIT
20442027
// If we have got a ICF to set as the LimitFrame, do that now.
20452028
// The Frame chain is still intact and would be updated using
20462029
// the LimitFrame (done after the catch handler returns).
@@ -2052,7 +2035,6 @@ CLRUnwindStatus ExceptionTracker::ProcessOSExceptionNotification(
20522035
m_pLimitFrame = pICFForUnwindTarget;
20532036
pICFSetAsLimitFrame = (PVOID)pICFForUnwindTarget;
20542037
}
2055-
#endif // USE_PER_FRAME_PINVOKE_INIT
20562038

20572039
// Since second pass is complete and we have reached
20582040
// the frame containing the catch funclet, reset the enclosing

src/coreclr/src/vm/exceptionhandling.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
#include "eexcp.h"
1414
#include "exstatecommon.h"
1515

16-
#if defined(TARGET_ARM) || defined(TARGET_X86)
17-
#define USE_PER_FRAME_PINVOKE_INIT
18-
#endif // TARGET_ARM || TARGET_X86
19-
2016
// This address lies in the NULL pointer partition of the process memory.
2117
// Accessing it will result in AV.
2218
#define INVALID_RESUME_ADDRESS 0x000000000000bad0
@@ -195,10 +191,8 @@ class ExceptionTracker
195191
DWORD dwExceptionFlags,
196192
StackFrame sf,
197193
Thread* pThread,
198-
StackTraceState STState
199-
#ifdef USE_PER_FRAME_PINVOKE_INIT
200-
, PVOID pICFSetAsLimitFrame
201-
#endif // USE_PER_FRAME_PINVOKE_INIT
194+
StackTraceState STState,
195+
PVOID pICFSetAsLimitFrame
202196
);
203197

204198
CLRUnwindStatus ProcessExplicitFrame(

0 commit comments

Comments
 (0)