Skip to content

Commit 5d90f93

Browse files
authored
Revert "[debugger] Fix crash during Async Break when APC and CET are enabled (#111408)" (#116025)
This reverts commit f6ecb6e.
1 parent f0b32c1 commit 5d90f93

File tree

6 files changed

+7
-88
lines changed

6 files changed

+7
-88
lines changed

src/coreclr/debug/ee/controller.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4469,19 +4469,7 @@ bool DebuggerController::DispatchNativeException(EXCEPTION_RECORD *pException,
44694469
ThisFunctionMayHaveTriggerAGC();
44704470
}
44714471
#endif
4472-
#ifdef FEATURE_SPECIAL_USER_MODE_APC
4473-
if (pCurThread->m_State & Thread::TS_SSToExitApcCall)
4474-
{
4475-
if (!CheckActivationSafePoint(GetIP(pContext)))
4476-
{
4477-
return FALSE;
4478-
}
4479-
pCurThread->SetThreadState(Thread::TS_SSToExitApcCallDone);
4480-
pCurThread->ResetThreadState(Thread::TS_SSToExitApcCall);
4481-
DebuggerController::UnapplyTraceFlag(pCurThread);
4482-
pCurThread->MarkForSuspensionAndWait(Thread::TS_DebugSuspendPending);
4483-
}
4484-
#endif
4472+
44854473

44864474

44874475
// Must restore the filter context. After the filter context is gone, we're

src/coreclr/debug/ee/debugger.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15001,14 +15001,6 @@ HRESULT Debugger::FuncEvalSetup(DebuggerIPCE_FuncEvalInfo *pEvalInfo,
1500115001
return CORDBG_E_ILLEGAL_IN_STACK_OVERFLOW;
1500215002
}
1500315003

15004-
#ifdef FEATURE_SPECIAL_USER_MODE_APC
15005-
if (pThread->m_hasPendingActivation)
15006-
{
15007-
_ASSERTE(!"Should never get here with a pending activation. (Debugger::FuncEvalSetup)");
15008-
return CORDBG_E_ILLEGAL_IN_NATIVE_CODE;
15009-
}
15010-
#endif
15011-
1501215004
bool fInException = pEvalInfo->evalDuringException;
1501315005

1501415006
// The thread has to be at a GC safe place for now, just in case the func eval causes a collection. Processing an
@@ -16780,15 +16772,6 @@ void Debugger::ExternalMethodFixupNextStep(PCODE address)
1678016772
{
1678116773
DebuggerController::DispatchExternalMethodFixup(address);
1678216774
}
16783-
#ifdef FEATURE_SPECIAL_USER_MODE_APC
16784-
void Debugger::SingleStepToExitApcCall(Thread* pThread, CONTEXT *interruptedContext)
16785-
{
16786-
pThread->SetThreadState(Thread::TS_SSToExitApcCall);
16787-
g_pEEInterface->SetThreadFilterContext(pThread, interruptedContext);
16788-
DebuggerController::EnableSingleStep(pThread);
16789-
g_pEEInterface->SetThreadFilterContext(pThread, NULL);
16790-
}
16791-
#endif //FEATURE_SPECIAL_USER_MODE_APC
1679216775
#endif //DACCESS_COMPILE
1679316776

1679416777
unsigned FuncEvalFrame::GetFrameAttribs_Impl(void)

src/coreclr/debug/ee/debugger.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3061,9 +3061,6 @@ class Debugger : public DebugInterface
30613061
// Used by Debugger::FirstChanceNativeException to update the context from out of process
30623062
void SendSetThreadContextNeeded(CONTEXT *context, DebuggerSteppingInfo *pDebuggerSteppingInfo = NULL);
30633063
BOOL IsOutOfProcessSetContextEnabled();
3064-
#ifdef FEATURE_SPECIAL_USER_MODE_APC
3065-
void SingleStepToExitApcCall(Thread* pThread, CONTEXT *interruptedContext);
3066-
#endif // FEATURE_SPECIAL_USER_MODE_APC
30673064
};
30683065

30693066

src/coreclr/vm/dbginterface.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,6 @@ class DebugInterface
412412
virtual HRESULT IsMethodDeoptimized(Module *pModule, mdMethodDef methodDef, BOOL *pResult) = 0;
413413
virtual void MulticastTraceNextStep(DELEGATEREF pbDel, INT32 count) = 0;
414414
virtual void ExternalMethodFixupNextStep(PCODE address) = 0;
415-
#ifdef FEATURE_SPECIAL_USER_MODE_APC
416-
virtual void SingleStepToExitApcCall(Thread* pThread, CONTEXT *interruptedContext) = 0;
417-
#endif // FEATURE_SPECIAL_USER_MODE_APC
418415
#endif //DACCESS_COMPILE
419416
};
420417

src/coreclr/vm/threads.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,6 @@ class Thread
482482
friend void STDCALL OnHijackWorker(HijackArgs * pArgs);
483483
#ifdef FEATURE_THREAD_ACTIVATION
484484
friend void HandleSuspensionForInterruptedThread(CONTEXT *interruptedContext);
485-
friend void HandleSuspensionForInterruptedThread(CONTEXT *interruptedContext, bool suspendForDebugger);
486485
friend BOOL CheckActivationSafePoint(SIZE_T ip);
487486
#endif // FEATURE_THREAD_ACTIVATION
488487

@@ -550,7 +549,7 @@ class Thread
550549
TS_Hijacked = 0x00000080, // Return address has been hijacked
551550
#endif // FEATURE_HIJACK
552551

553-
TS_SSToExitApcCall = 0x00000100, // Enable SS and resume the thread to exit an APC Call and keep the thread in suspend state
552+
// unused = 0x00000100,
554553
TS_Background = 0x00000200, // Thread is a background thread
555554
TS_Unstarted = 0x00000400, // Thread has never been started
556555
TS_Dead = 0x00000800, // Thread is dead
@@ -567,7 +566,7 @@ class Thread
567566
TS_ReportDead = 0x00010000, // in WaitForOtherThreads()
568567
TS_FullyInitialized = 0x00020000, // Thread is fully initialized and we are ready to broadcast its existence to external clients
569568

570-
TS_SSToExitApcCallDone = 0x00040000, // The thread exited an APC Call and it is already resumed and paused on SS
569+
// unused = 0x00040000,
571570

572571
TS_SyncSuspended = 0x00080000, // Suspended via WaitSuspendEvent
573572
TS_DebugWillSync = 0x00100000, // Debugger will wait for this thread to sync
@@ -2571,9 +2570,7 @@ class Thread
25712570
//-------------------------------------------------------------
25722571
// Waiting & Synchronization
25732572
//-------------------------------------------------------------
2574-
friend class DebuggerController;
2575-
protected:
2576-
void MarkForSuspensionAndWait(ULONG bit);
2573+
25772574
// For suspends. The thread waits on this event. A client sets the event to cause
25782575
// the thread to resume.
25792576
void WaitSuspendEvents();

src/coreclr/vm/threadsuspend.cpp

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4210,18 +4210,6 @@ bool Thread::SysSweepThreadsForDebug(bool forceSync)
42104210
if ((thread->m_State & TS_DebugWillSync) == 0)
42114211
continue;
42124212

4213-
#ifdef FEATURE_SPECIAL_USER_MODE_APC
4214-
if (thread->m_State & Thread::TS_SSToExitApcCallDone)
4215-
{
4216-
thread->ResetThreadState(Thread::TS_SSToExitApcCallDone);
4217-
goto Label_MarkThreadAsSynced;
4218-
}
4219-
if (thread->m_State & Thread::TS_SSToExitApcCall)
4220-
{
4221-
continue;
4222-
}
4223-
#endif
4224-
42254213
if (!UseContextBasedThreadRedirection())
42264214
{
42274215
// On platforms that do not support safe thread suspension we either
@@ -5346,19 +5334,6 @@ BOOL Thread::HandledJITCase()
53465334
#endif // FEATURE_HIJACK
53475335

53485336
// Some simple helpers to keep track of the threads we are waiting for
5349-
void Thread::MarkForSuspensionAndWait(ULONG bit)
5350-
{
5351-
CONTRACTL {
5352-
NOTHROW;
5353-
GC_NOTRIGGER;
5354-
}
5355-
CONTRACTL_END;
5356-
m_DebugSuspendEvent.Reset();
5357-
InterlockedOr((LONG*)&m_State, bit);
5358-
ThreadStore::IncrementTrapReturningThreads();
5359-
m_DebugSuspendEvent.Wait(INFINITE,FALSE);
5360-
}
5361-
53625337
void Thread::MarkForSuspension(ULONG bit)
53635338
{
53645339
CONTRACTL {
@@ -5781,8 +5756,7 @@ BOOL CheckActivationSafePoint(SIZE_T ip)
57815756
// address to take the thread to the appropriate stub (based on the return
57825757
// type of the method) which will then handle preparing the thread for GC.
57835758
//
5784-
5785-
void HandleSuspensionForInterruptedThread(CONTEXT *interruptedContext, bool suspendForDebugger)
5759+
void HandleSuspensionForInterruptedThread(CONTEXT *interruptedContext)
57865760
{
57875761
struct AutoClearPendingThreadActivation
57885762
{
@@ -5818,18 +5792,6 @@ void HandleSuspensionForInterruptedThread(CONTEXT *interruptedContext, bool susp
58185792
if (!codeInfo.IsValid())
58195793
return;
58205794

5821-
#ifdef FEATURE_SPECIAL_USER_MODE_APC
5822-
// It's not allowed to change the IP while paused in an APC Callback for security reasons if CET is turned on
5823-
// So we enable the single step in the thread that is running the APC Callback
5824-
// and then it will be paused using single step exception after exiting the APC callback
5825-
// this will allow the debugger to setIp to execute FuncEvalHijack.
5826-
if (suspendForDebugger)
5827-
{
5828-
g_pDebugInterface->SingleStepToExitApcCall(pThread, interruptedContext);
5829-
return;
5830-
}
5831-
#endif
5832-
58335795
DWORD addrOffset = codeInfo.GetRelOffset();
58345796

58355797
ICodeManager *pEECM = codeInfo.GetCodeManager();
@@ -5905,11 +5867,6 @@ void HandleSuspensionForInterruptedThread(CONTEXT *interruptedContext, bool susp
59055867
}
59065868
}
59075869

5908-
void HandleSuspensionForInterruptedThread(CONTEXT *interruptedContext)
5909-
{
5910-
HandleSuspensionForInterruptedThread(interruptedContext, false);
5911-
}
5912-
59135870
#ifdef FEATURE_SPECIAL_USER_MODE_APC
59145871
void Thread::ApcActivationCallback(ULONG_PTR Parameter)
59155872
{
@@ -5936,10 +5893,10 @@ void Thread::ApcActivationCallback(ULONG_PTR Parameter)
59365893

59375894
switch (reason)
59385895
{
5939-
case ActivationReason::SuspendForDebugger:
59405896
case ActivationReason::SuspendForGC:
5897+
case ActivationReason::SuspendForDebugger:
59415898
case ActivationReason::ThreadAbort:
5942-
HandleSuspensionForInterruptedThread(pContext, reason == ActivationReason::SuspendForDebugger);
5899+
HandleSuspensionForInterruptedThread(pContext);
59435900
break;
59445901

59455902
default:

0 commit comments

Comments
 (0)