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

Commit 98a41f0

Browse files
parjongjanvorli
authored andcommitted
[x86/Linux] EH Support for Per-Frame P/Invoke Init (#10966)
1 parent bbe202b commit 98a41f0

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

src/vm/exceptionhandling.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,17 +1071,23 @@ ProcessCLRException(IN PEXCEPTION_RECORD pExceptionRecord
10711071

10721072
CLRUnwindStatus status;
10731073

1074+
#ifdef USE_PER_FRAME_PINVOKE_INIT
10741075
// Refer to comment in ProcessOSExceptionNotification about ICF and codegen difference.
1075-
ARM_ONLY(InlinedCallFrame *pICFSetAsLimitFrame = NULL;)
1076-
1076+
InlinedCallFrame *pICFSetAsLimitFrame = NULL;
1077+
#endif // USE_PER_FRAME_PINVOKE_INIT
1078+
10771079
status = pTracker->ProcessOSExceptionNotification(
10781080
pExceptionRecord,
10791081
pContextRecord,
10801082
pDispatcherContext,
10811083
dwExceptionFlags,
10821084
sf,
10831085
pThread,
1084-
STState ARM_ARG((PVOID)pICFSetAsLimitFrame));
1086+
STState
1087+
#ifdef USE_PER_FRAME_PINVOKE_INIT
1088+
, (PVOID)pICFSetAsLimitFrame
1089+
#endif // USE_PER_FRAME_PINVOKE_INIT
1090+
);
10851091

10861092
if (FirstPassComplete == status)
10871093
{
@@ -1184,7 +1190,7 @@ ProcessCLRException(IN PEXCEPTION_RECORD pExceptionRecord
11841190

11851191

11861192
CONSISTENCY_CHECK(pLimitFrame > dac_cast<PTR_VOID>(GetSP(pContextRecord)));
1187-
#if defined(_TARGET_ARM_)
1193+
#ifdef USE_PER_FRAME_PINVOKE_INIT
11881194
if (pICFSetAsLimitFrame != NULL)
11891195
{
11901196
_ASSERTE(pICFSetAsLimitFrame == pLimitFrame);
@@ -1196,7 +1202,7 @@ ProcessCLRException(IN PEXCEPTION_RECORD pExceptionRecord
11961202
// the next pinvoke callsite does not see the frame as active.
11971203
pICFSetAsLimitFrame->Reset();
11981204
}
1199-
#endif // defined(_TARGET_ARM_)
1205+
#endif // USE_PER_FRAME_PINVOKE_INIT
12001206

12011207
pThread->SetFrame(pLimitFrame);
12021208

@@ -1653,7 +1659,11 @@ CLRUnwindStatus ExceptionTracker::ProcessOSExceptionNotification(
16531659
DWORD dwExceptionFlags,
16541660
StackFrame sf,
16551661
Thread* pThread,
1656-
StackTraceState STState ARM_ARG(PVOID pICFSetAsLimitFrame))
1662+
StackTraceState STState
1663+
#ifdef USE_PER_FRAME_PINVOKE_INIT
1664+
, PVOID pICFSetAsLimitFrame
1665+
#endif // USE_PER_FRAME_PINVOKE_INIT
1666+
)
16571667
{
16581668
CONTRACTL
16591669
{
@@ -1719,10 +1729,10 @@ CLRUnwindStatus ExceptionTracker::ProcessOSExceptionNotification(
17191729
this->m_EnclosingClauseInfoForGCReporting.SetEnclosingClauseCallerSP(uCallerSP);
17201730
}
17211731

1722-
#if defined(_TARGET_ARM_)
1732+
#ifdef USE_PER_FRAME_PINVOKE_INIT
17231733
// Refer to detailed comment below.
17241734
PTR_Frame pICFForUnwindTarget = NULL;
1725-
#endif // defined(_TARGET_ARM_)
1735+
#endif // USE_PER_FRAME_PINVOKE_INIT
17261736

17271737
CheckForRudeAbort(pThread, fIsFirstPass);
17281738

@@ -1751,7 +1761,7 @@ CLRUnwindStatus ExceptionTracker::ProcessOSExceptionNotification(
17511761

17521762
while (((UINT_PTR)pFrame) < uCallerSP)
17531763
{
1754-
#if defined(_TARGET_ARM_)
1764+
#ifdef USE_PER_FRAME_PINVOKE_INIT
17551765
// InlinedCallFrames (ICF) are allocated, initialized and linked to the Frame chain
17561766
// by the code generated by the JIT for a method containing a PInvoke.
17571767
//
@@ -1956,7 +1966,7 @@ CLRUnwindStatus ExceptionTracker::ProcessOSExceptionNotification(
19561966

19571967
if (fTargetUnwind && (status == SecondPassComplete))
19581968
{
1959-
#if defined(_TARGET_ARM_)
1969+
#ifdef USE_PER_FRAME_PINVOKE_INIT
19601970
// If we have got a ICF to set as the LimitFrame, do that now.
19611971
// The Frame chain is still intact and would be updated using
19621972
// the LimitFrame (done after the catch handler returns).
@@ -1968,7 +1978,7 @@ CLRUnwindStatus ExceptionTracker::ProcessOSExceptionNotification(
19681978
m_pLimitFrame = pICFForUnwindTarget;
19691979
pICFSetAsLimitFrame = (PVOID)pICFForUnwindTarget;
19701980
}
1971-
#endif // _TARGET_ARM_
1981+
#endif // USE_PER_FRAME_PINVOKE_INIT
19721982

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

src/vm/exceptionhandling.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010

1111
#ifdef WIN64EXCEPTIONS
1212

13+
#if defined(_TARGET_ARM_) || defined(_TARGET_X86_)
14+
#define USE_PER_FRAME_PINVOKE_INIT
15+
#endif // _TARGET_ARM_ || _TARGET_X86_
16+
17+
1318
// This address lies in the NULL pointer partition of the process memory.
1419
// Accessing it will result in AV.
1520
#define INVALID_RESUME_ADDRESS 0x000000000000bad0
@@ -203,7 +208,11 @@ class ExceptionTracker
203208
DWORD dwExceptionFlags,
204209
StackFrame sf,
205210
Thread* pThread,
206-
StackTraceState STState ARM_ARG(PVOID pICFSetAsLimitFrame));
211+
StackTraceState STState
212+
#ifdef USE_PER_FRAME_PINVOKE_INIT
213+
, PVOID pICFSetAsLimitFrame
214+
#endif // USE_PER_FRAME_PINVOKE_INIT
215+
);
207216

208217
CLRUnwindStatus ProcessExplicitFrame(
209218
CrawlFrame* pcfThisFrame,

0 commit comments

Comments
 (0)