@@ -5462,6 +5462,8 @@ BOOL HandleHardwareException(PAL_SEHException* ex)
5462
5462
args[ARGNUM_0] = DWORD_TO_ARGHOLDER (exceptionCode);
5463
5463
args[ARGNUM_1] = PTR_TO_ARGHOLDER (&exInfo);
5464
5464
5465
+ pThread->IncPreventAbort ();
5466
+
5465
5467
// Ex.RhThrowHwEx(exceptionCode, &exInfo)
5466
5468
CALL_MANAGED_METHOD_NORET (args)
5467
5469
@@ -5555,6 +5557,8 @@ VOID DECLSPEC_NORETURN DispatchManagedException(OBJECTREF throwable)
5555
5557
args[ARGNUM_0] = OBJECTREF_TO_ARGHOLDER (throwable);
5556
5558
args[ARGNUM_1] = PTR_TO_ARGHOLDER (&exInfo);
5557
5559
5560
+ pThread->IncPreventAbort ();
5561
+
5558
5562
// Ex.RhThrowEx(throwable, &exInfo)
5559
5563
CRITICAL_CALLSITE;
5560
5564
CALL_MANAGED_METHOD_NORET (args)
@@ -7559,11 +7563,13 @@ extern "C" void * QCALLTYPE CallCatchFunclet(QCall::ObjectHandleOnStack exceptio
7559
7563
GCX_COOP_NO_DTOR ();
7560
7564
7561
7565
Thread* pThread = GET_THREAD ();
7566
+ pThread->DecPreventAbort ();
7567
+
7562
7568
Frame* pFrame = pThread->GetFrame ();
7563
7569
MarkInlinedCallFrameAsFuncletCall (pFrame);
7564
7570
HandlerFn* pfnHandler = (HandlerFn*)pHandlerIP;
7565
7571
exInfo->m_sfHighBound = exInfo->m_frameIter .m_crawl .GetRegisterSet ()->SP ;
7566
- DWORD_PTR dwResumePC;
7572
+ DWORD_PTR dwResumePC = 0 ;
7567
7573
7568
7574
if (pHandlerIP != NULL )
7569
7575
{
@@ -7643,6 +7649,29 @@ extern "C" void * QCALLTYPE CallCatchFunclet(QCall::ObjectHandleOnStack exceptio
7643
7649
ExceptionTracker::UpdateNonvolatileRegisters (pvRegDisplay->pCurrentContext , pvRegDisplay, FALSE );
7644
7650
if (pHandlerIP != NULL )
7645
7651
{
7652
+ CopyOSContext (pThread->m_OSContext , pvRegDisplay->pCurrentContext );
7653
+ SetIP (pThread->m_OSContext , (PCODE)dwResumePC);
7654
+ UINT_PTR uAbortAddr = (UINT_PTR)COMPlusCheckForAbort (dwResumePC);
7655
+ if (uAbortAddr)
7656
+ {
7657
+ #ifdef TARGET_AMD64
7658
+ #ifdef TARGET_UNIX
7659
+ pvRegDisplay->pCurrentContext ->Rdi = dwResumePC;
7660
+ pvRegDisplay->pCurrentContext ->Rsi = GetIP (pThread->GetAbortContext ()); // How can this ever be different from dwResumePC?
7661
+ #else
7662
+ pvRegDisplay->pCurrentContext ->Rcx = dwResumePC;
7663
+ #endif
7664
+ #elif defined(TARGET_ARM) || defined(TARGET_ARM64)
7665
+ // On ARM & ARM64, we save off the original PC in Lr. This is the same as done
7666
+ // in HandleManagedFault for H/W generated exceptions.
7667
+ pvRegDisplay->pCurrentContext ->Lr = dwResumePC;
7668
+ #elif defined(TARGET_LOONGARCH64) || defined(TARGET_RISCV64)
7669
+ pvRegDisplay->pCurrentContext ->Ra = dwResumePC;
7670
+ #endif
7671
+
7672
+ SetIP (pvRegDisplay->pCurrentContext , uAbortAddr);
7673
+ }
7674
+
7646
7675
ClrRestoreNonvolatileContext (pvRegDisplay->pCurrentContext );
7647
7676
}
7648
7677
else
@@ -7709,6 +7738,8 @@ extern "C" void QCALLTYPE CallFinallyFunclet(BYTE* pHandlerIP, REGDISPLAY* pvReg
7709
7738
BEGIN_QCALL;
7710
7739
GCX_COOP ();
7711
7740
Thread* pThread = GET_THREAD ();
7741
+ pThread->DecPreventAbort ();
7742
+
7712
7743
Frame* pFrame = pThread->GetFrame ();
7713
7744
MarkInlinedCallFrameAsFuncletCall (pFrame);
7714
7745
HandlerFn* pfnHandler = (HandlerFn*)pHandlerIP;
@@ -7733,6 +7764,9 @@ extern "C" void QCALLTYPE CallFinallyFunclet(BYTE* pHandlerIP, REGDISPLAY* pvReg
7733
7764
#else
7734
7765
DWORD_PTR dwResumePC = pfnHandler (establisherFrame, NULL );
7735
7766
#endif
7767
+
7768
+ pThread->IncPreventAbort ();
7769
+
7736
7770
// Profiler, debugger and ETW events
7737
7771
exInfo->MakeCallbacksRelatedToHandler (false , pThread, pMD, &exInfo->m_CurrentClause , (DWORD_PTR)pHandlerIP, GetSP (pvRegDisplay->pCurrentContext ) );
7738
7772
END_QCALL;
0 commit comments