From 1ccb05f4e15756639b0caa18553f2c578d07a433 Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Sat, 23 Mar 2024 01:59:51 +0100 Subject: [PATCH 1/6] Improve collided exception performance With the new EH enabled, one exception handling performance test has regressed while all other improved dramatically. I have investigated the test case and it turned out that the regression is due to the way we unwind during second pass when we have an exception that occured in a catch or finally funclet call chain and escaped it. What we do is that we unwind stack until we reach the parent stack frame of the catch / finally and then continue searching for handlers. The NativeAOT that the new EH is based on doesn't unwind stack though, it just moves the current stack frame iterator to the position of the previous exception's stack frame iterator by copying its state. I have applied the same mechanism to the new EH in coreclr and it improved the performance of that test 3-4 times on my machine. --- src/coreclr/vm/exceptionhandling.cpp | 9 +--- src/coreclr/vm/stackwalk.cpp | 61 ++++++++++++++++++++++++++++ src/coreclr/vm/stackwalk.h | 5 +++ 3 files changed, 68 insertions(+), 7 deletions(-) diff --git a/src/coreclr/vm/exceptionhandling.cpp b/src/coreclr/vm/exceptionhandling.cpp index 7a92fa7666f10e..c9ae699a517077 100644 --- a/src/coreclr/vm/exceptionhandling.cpp +++ b/src/coreclr/vm/exceptionhandling.cpp @@ -8491,14 +8491,9 @@ extern "C" bool QCALLTYPE SfiNext(StackFrameIterator* pThis, uint* uExCollideCla isCollided = true; pExInfo->m_kind = (ExKind)((uint8_t)pExInfo->m_kind | (uint8_t)ExKind::SupersededFlag); - // Unwind until we hit the frame of the prevExInfo + // Unwind to the frame of the prevExInfo ExInfo* pPrevExInfo = pThis->GetNextExInfo(); - do - { - retVal = MoveToNextNonSkippedFrame(pThis); - } - while ((retVal == SWA_CONTINUE) && !(pThis->GetFrameState() == StackFrameIterator::SFITER_FRAMELESS_METHOD && pThis->m_crawl.GetRegisterSet()->SP == pPrevExInfo->m_regDisplay.SP)); - _ASSERTE(retVal != SWA_FAILED); + pThis->SkipTo(&pPrevExInfo->m_frameIter); pThis->ResetNextExInfoForSP(pThis->m_crawl.GetRegisterSet()->SP); } diff --git a/src/coreclr/vm/stackwalk.cpp b/src/coreclr/vm/stackwalk.cpp index c1fd2841199d9e..2796f08991e4cf 100644 --- a/src/coreclr/vm/stackwalk.cpp +++ b/src/coreclr/vm/stackwalk.cpp @@ -1546,6 +1546,67 @@ BOOL StackFrameIterator::IsValid(void) return TRUE; } // StackFrameIterator::IsValid() +#ifndef DACCESS_COMPILE +//--------------------------------------------------------------------------------------- +// +// Advance to the position that the other iterator is currently at. +// +void StackFrameIterator::SkipTo(StackFrameIterator *pOtherStackFrameIterator) +{ + // We copy the other stack frame iterator over the current one, but we need to + // keep a couple of members untouched. So we save them here and restore them + // after the copy. + ExInfo* pPrevExInfo = GetNextExInfo(); + REGDISPLAY *pRD = m_crawl.GetRegisterSet(); + GSCookie *pCurGSCookie = m_crawl.pCurGSCookie; + GSCookie *pFirstGSCookie = m_crawl.pFirstGSCookie; + Frame *pStartFrame = m_pStartFrame; +#ifdef _DEBUG + Frame *pRealStartFrame = m_pRealStartFrame; +#endif + + *this = *pOtherStackFrameIterator; + + m_pNextExInfo = pPrevExInfo; + m_crawl.pRD = pRD; + m_crawl.pCurGSCookie = pCurGSCookie; + m_crawl.pFirstGSCookie = pFirstGSCookie; + m_pStartFrame = pStartFrame; +#ifdef _DEBUG + m_pRealStartFrame = pRealStartFrame; +#endif + + REGDISPLAY *pOtherRD = pOtherStackFrameIterator->m_crawl.GetRegisterSet(); + *pRD->pCurrentContextPointers = *pOtherRD->pCurrentContextPointers; + SetIP(pRD->pCurrentContext, GetIP(pOtherRD->pCurrentContext)); + SetSP(pRD->pCurrentContext, GetSP(pOtherRD->pCurrentContext)); +#if defined(TARGET_ARM) || defined(TARGET_ARM64) + SetLR(pRD->pCurrentContext, GetLR(pOtherRD->pCurrentContext)); +#elif defined(TARGET_RISCV64) || defined(TARGET_LOONGARCH64) + SetRA(pRD->pCurrentContext, GetRA(pOtherRD->pCurrentContext)); +#endif // TARGET_ARM || TARGET_ARM64 +#define CALLEE_SAVED_REGISTER(regname) pRD->pCurrentContext->regname = *pRD->pCurrentContextPointers->regname; + ENUM_CALLEE_SAVED_REGISTERS(); +#undef CALLEE_SAVED_REGISTER + pRD->IsCallerContextValid = pOtherRD->IsCallerContextValid; + if (pRD->IsCallerContextValid) + { + *pRD->pCallerContextPointers = *pOtherRD->pCallerContextPointers; + SetIP(pRD->pCallerContext, GetIP(pOtherRD->pCallerContext)); + SetSP(pRD->pCallerContext, GetSP(pOtherRD->pCallerContext)); +#if defined(TARGET_ARM) || defined(TARGET_ARM64) + SetLR(pRD->pCallerContext, GetLR(pOtherRD->pCallerContext)); +#elif defined(TARGET_RISCV64) || defined(TARGET_LOONGARCH64) + SetRA(pRD->pCallerContext, GetRA(pOtherRD->pCallerContext)); +#endif // TARGET_ARM || TARGET_ARM64 +#define CALLEE_SAVED_REGISTER(regname) pRD->pCallerContext->regname = *pRD->pCallerContextPointers->regname; + ENUM_CALLEE_SAVED_REGISTERS(); +#undef CALLEE_SAVED_REGISTER + } + SyncRegDisplayToCurrentContext(pRD); +} +#endif // DACCESS_COMPILE + //--------------------------------------------------------------------------------------- // // Advance to the next frame according to the stackwalk flags. If the iterator is stopped diff --git a/src/coreclr/vm/stackwalk.h b/src/coreclr/vm/stackwalk.h index 19fcebc2ec8188..a65f1b916818ed 100644 --- a/src/coreclr/vm/stackwalk.h +++ b/src/coreclr/vm/stackwalk.h @@ -599,6 +599,11 @@ class StackFrameIterator // advance to the next frame according to the stackwalk flags StackWalkAction Next(void); +#ifndef DACCESS_COMPILE + // advance to the position that the other iterator is currently at + void SkipTo(StackFrameIterator *pOtherStackFrameIterator); +#endif // DACCESS_COMPILE + #ifdef FEATURE_EH_FUNCLETS void ResetNextExInfoForSP(TADDR SP); From bc57e0011d3bbaf0e705f4c3ac0c4423ddbd9a96 Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Mon, 25 Mar 2024 21:43:02 +0100 Subject: [PATCH 2/6] Fix build on non-x64 platforms and add FP nonvol regs --- src/coreclr/inc/regdisp.h | 1 + src/coreclr/vm/amd64/cgencpu.h | 15 ++++++++++++++ src/coreclr/vm/arm/cgencpu.h | 21 +++++++++++++++++++ src/coreclr/vm/arm64/cgencpu.h | 22 ++++++++++++++++++++ src/coreclr/vm/i386/cgencpu.h | 3 +++ src/coreclr/vm/loongarch64/cgencpu.h | 24 +++++++++++++++++++++ src/coreclr/vm/riscv64/cgencpu.h | 31 ++++++++++++++++++++++++++++ src/coreclr/vm/stackwalk.cpp | 18 +++++++--------- src/coreclr/vm/stackwalk.h | 2 ++ 9 files changed, 127 insertions(+), 10 deletions(-) diff --git a/src/coreclr/inc/regdisp.h b/src/coreclr/inc/regdisp.h index ec47b9019dbc02..c3e4c560dec480 100644 --- a/src/coreclr/inc/regdisp.h +++ b/src/coreclr/inc/regdisp.h @@ -426,6 +426,7 @@ inline void FillContextPointers(PT_KNONVOLATILE_CONTEXT_POINTERS pCtxPtrs, PT_CO { *(&pCtxPtrs->R4 + i) = (&pCtx->R4 + i); } + *(&pCtxPtrs->Lr) = &pCtx->Lr; #elif defined(TARGET_X86) // TARGET_ARM for (int i = 0; i < 7; i++) { diff --git a/src/coreclr/vm/amd64/cgencpu.h b/src/coreclr/vm/amd64/cgencpu.h index b3f038321e3bfe..9d4eb754ac7d17 100644 --- a/src/coreclr/vm/amd64/cgencpu.h +++ b/src/coreclr/vm/amd64/cgencpu.h @@ -188,6 +188,9 @@ struct REGDISPLAY; #define NUM_CALLEE_SAVED_REGISTERS 6 +// No floating point callee saved registers on Unix AMD64 +#define ENUM_FP_CALLEE_SAVED_REGISTERS() + #else // UNIX_AMD64_ABI #define ENUM_ARGUMENT_REGISTERS() \ @@ -212,6 +215,18 @@ struct REGDISPLAY; #define NUM_CALLEE_SAVED_REGISTERS 8 +#define ENUM_FP_CALLEE_SAVED_REGISTERS() \ + CALLEE_SAVED_REGISTER(Xmm6) \ + CALLEE_SAVED_REGISTER(Xmm7) \ + CALLEE_SAVED_REGISTER(Xmm8) \ + CALLEE_SAVED_REGISTER(Xmm9) \ + CALLEE_SAVED_REGISTER(Xmm10) \ + CALLEE_SAVED_REGISTER(Xmm11) \ + CALLEE_SAVED_REGISTER(Xmm12) \ + CALLEE_SAVED_REGISTER(Xmm13) \ + CALLEE_SAVED_REGISTER(Xmm14) \ + CALLEE_SAVED_REGISTER(Xmm15) + #endif // UNIX_AMD64_ABI typedef DPTR(struct ArgumentRegisters) PTR_ArgumentRegisters; diff --git a/src/coreclr/vm/arm/cgencpu.h b/src/coreclr/vm/arm/cgencpu.h index f60822ccaa87c2..499ce4db3e9a94 100644 --- a/src/coreclr/vm/arm/cgencpu.h +++ b/src/coreclr/vm/arm/cgencpu.h @@ -21,6 +21,27 @@ #define RESOLVE_STUB_THIRD_WORD 0xb460 #define LOOKUP_STUB_FIRST_WORD 0xf8df +#define ENUM_CALLEE_SAVED_REGISTERS() \ + CALLEE_SAVED_REGISTER(R4) \ + CALLEE_SAVED_REGISTER(R5) \ + CALLEE_SAVED_REGISTER(R6) \ + CALLEE_SAVED_REGISTER(R7) \ + CALLEE_SAVED_REGISTER(R8) \ + CALLEE_SAVED_REGISTER(R9) \ + CALLEE_SAVED_REGISTER(R10) \ + CALLEE_SAVED_REGISTER(R11) \ + CALLEE_SAVED_REGISTER(Lr) + +#define ENUM_FP_CALLEE_SAVED_REGISTERS() \ + CALLEE_SAVED_REGISTER(D[8]) \ + CALLEE_SAVED_REGISTER(D[9]) \ + CALLEE_SAVED_REGISTER(D[10]) \ + CALLEE_SAVED_REGISTER(D[11]) \ + CALLEE_SAVED_REGISTER(D[12]) \ + CALLEE_SAVED_REGISTER(D[13]) \ + CALLEE_SAVED_REGISTER(D[14]) \ + CALLEE_SAVED_REGISTER(D[15]) + class MethodDesc; class FramedMethodFrame; class Module; diff --git a/src/coreclr/vm/arm64/cgencpu.h b/src/coreclr/vm/arm64/cgencpu.h index 3ec3d6ea3b1a13..41147148c26f8f 100644 --- a/src/coreclr/vm/arm64/cgencpu.h +++ b/src/coreclr/vm/arm64/cgencpu.h @@ -17,6 +17,28 @@ #define USE_REDIRECT_FOR_GCSTRESS #endif // TARGET_UNIX +#define ENUM_CALLEE_SAVED_REGISTERS() \ + CALLEE_SAVED_REGISTER(Fp) \ + CALLEE_SAVED_REGISTER(Lr) \ + CALLEE_SAVED_REGISTER(X19) \ + CALLEE_SAVED_REGISTER(X20) \ + CALLEE_SAVED_REGISTER(X21) \ + CALLEE_SAVED_REGISTER(X22) \ + CALLEE_SAVED_REGISTER(X23) \ + CALLEE_SAVED_REGISTER(X24) \ + CALLEE_SAVED_REGISTER(X25) \ + CALLEE_SAVED_REGISTER(X26) + +#define ENUM_FP_CALLEE_SAVED_REGISTERS() \ + CALLEE_SAVED_REGISTER(V[8].Low) \ + CALLEE_SAVED_REGISTER(V[9].Low) \ + CALLEE_SAVED_REGISTER(V[10].Low) \ + CALLEE_SAVED_REGISTER(V[11].Low) \ + CALLEE_SAVED_REGISTER(V[12].Low) \ + CALLEE_SAVED_REGISTER(V[13].Low) \ + CALLEE_SAVED_REGISTER(V[14].Low) \ + CALLEE_SAVED_REGISTER(V[15].Low) + EXTERN_C void getFPReturn(int fpSize, INT64 *pRetVal); EXTERN_C void setFPReturn(int fpSize, INT64 retVal); diff --git a/src/coreclr/vm/i386/cgencpu.h b/src/coreclr/vm/i386/cgencpu.h index 655ad8c7a2398b..358a2939f11004 100644 --- a/src/coreclr/vm/i386/cgencpu.h +++ b/src/coreclr/vm/i386/cgencpu.h @@ -103,6 +103,9 @@ inline unsigned StackElemSize(unsigned parmSize, bool isValueType = false /* unu CALLEE_SAVED_REGISTER(Ebx) \ CALLEE_SAVED_REGISTER(Ebp) +// There are no FP callee saved registers on x86 +#define ENUM_FP_CALLEE_SAVED_REGISTERS() + typedef DPTR(struct CalleeSavedRegisters) PTR_CalleeSavedRegisters; struct CalleeSavedRegisters { #define CALLEE_SAVED_REGISTER(regname) INT32 regname; diff --git a/src/coreclr/vm/loongarch64/cgencpu.h b/src/coreclr/vm/loongarch64/cgencpu.h index 0c3a7ca83a8d09..3bd6789906529a 100644 --- a/src/coreclr/vm/loongarch64/cgencpu.h +++ b/src/coreclr/vm/loongarch64/cgencpu.h @@ -15,6 +15,30 @@ #define USE_REDIRECT_FOR_GCSTRESS #endif // TARGET_UNIX +#define ENUM_CALLEE_SAVED_REGISTERS() \ + CALLEE_SAVED_REGISTER(Fp) \ + CALLEE_SAVED_REGISTER(Ra) \ + CALLEE_SAVED_REGISTER(S0) \ + CALLEE_SAVED_REGISTER(S1) \ + CALLEE_SAVED_REGISTER(S2) \ + CALLEE_SAVED_REGISTER(S3) \ + CALLEE_SAVED_REGISTER(S4) \ + CALLEE_SAVED_REGISTER(S5) \ + CALLEE_SAVED_REGISTER(S6) \ + CALLEE_SAVED_REGISTER(S7) \ + CALLEE_SAVED_REGISTER(S8) \ + CALLEE_SAVED_REGISTER(Tp) + +#define ENUM_FP_CALLEE_SAVED_REGISTERS() \ + CALLEE_SAVED_REGISTER(F[24]) \ + CALLEE_SAVED_REGISTER(F[25]) \ + CALLEE_SAVED_REGISTER(F[26]) \ + CALLEE_SAVED_REGISTER(F[27]) \ + CALLEE_SAVED_REGISTER(F[28]) \ + CALLEE_SAVED_REGISTER(F[29]) \ + CALLEE_SAVED_REGISTER(F[30]) \ + CALLEE_SAVED_REGISTER(F[31]) + EXTERN_C void getFPReturn(int fpSize, INT64 *pRetVal); EXTERN_C void setFPReturn(int fpSize, INT64 retVal); diff --git a/src/coreclr/vm/riscv64/cgencpu.h b/src/coreclr/vm/riscv64/cgencpu.h index 19fb205dffb0c8..d8fd06614f49bb 100644 --- a/src/coreclr/vm/riscv64/cgencpu.h +++ b/src/coreclr/vm/riscv64/cgencpu.h @@ -15,6 +15,37 @@ #define USE_REDIRECT_FOR_GCSTRESS #endif // TARGET_UNIX +#define ENUM_CALLEE_SAVED_REGISTERS() \ + CALLEE_SAVED_REGISTER(Fp) \ + CALLEE_SAVED_REGISTER(Ra) \ + CALLEE_SAVED_REGISTER(S1) \ + CALLEE_SAVED_REGISTER(S2) \ + CALLEE_SAVED_REGISTER(S3) \ + CALLEE_SAVED_REGISTER(S4) \ + CALLEE_SAVED_REGISTER(S5) \ + CALLEE_SAVED_REGISTER(S6) \ + CALLEE_SAVED_REGISTER(S7) \ + CALLEE_SAVED_REGISTER(S8) \ + CALLEE_SAVED_REGISTER(S9) \ + CALLEE_SAVED_REGISTER(S10) \ + CALLEE_SAVED_REGISTER(S11) \ + CALLEE_SAVED_REGISTER(Tp) \ + CALLEE_SAVED_REGISTER(Gp) + +#define ENUM_FP_CALLEE_SAVED_REGISTERS() \ + CALLEE_SAVED_REGISTER(F[8]) \ + CALLEE_SAVED_REGISTER(F[9]) \ + CALLEE_SAVED_REGISTER(F[18]) \ + CALLEE_SAVED_REGISTER(F[19]) \ + CALLEE_SAVED_REGISTER(F[20]) \ + CALLEE_SAVED_REGISTER(F[21]) \ + CALLEE_SAVED_REGISTER(F[22]) \ + CALLEE_SAVED_REGISTER(F[23]) \ + CALLEE_SAVED_REGISTER(F[24]) \ + CALLEE_SAVED_REGISTER(F[25]) \ + CALLEE_SAVED_REGISTER(F[26]) \ + CALLEE_SAVED_REGISTER(F[27]) + EXTERN_C void getFPReturn(int fpSize, INT64 *pRetVal); EXTERN_C void setFPReturn(int fpSize, INT64 retVal); diff --git a/src/coreclr/vm/stackwalk.cpp b/src/coreclr/vm/stackwalk.cpp index 2796f08991e4cf..2eb5695ce9f62e 100644 --- a/src/coreclr/vm/stackwalk.cpp +++ b/src/coreclr/vm/stackwalk.cpp @@ -1547,6 +1547,7 @@ BOOL StackFrameIterator::IsValid(void) } // StackFrameIterator::IsValid() #ifndef DACCESS_COMPILE +#ifdef FEATURE_EH_FUNCLETS //--------------------------------------------------------------------------------------- // // Advance to the position that the other iterator is currently at. @@ -1580,13 +1581,11 @@ void StackFrameIterator::SkipTo(StackFrameIterator *pOtherStackFrameIterator) *pRD->pCurrentContextPointers = *pOtherRD->pCurrentContextPointers; SetIP(pRD->pCurrentContext, GetIP(pOtherRD->pCurrentContext)); SetSP(pRD->pCurrentContext, GetSP(pOtherRD->pCurrentContext)); -#if defined(TARGET_ARM) || defined(TARGET_ARM64) - SetLR(pRD->pCurrentContext, GetLR(pOtherRD->pCurrentContext)); -#elif defined(TARGET_RISCV64) || defined(TARGET_LOONGARCH64) - SetRA(pRD->pCurrentContext, GetRA(pOtherRD->pCurrentContext)); -#endif // TARGET_ARM || TARGET_ARM64 #define CALLEE_SAVED_REGISTER(regname) pRD->pCurrentContext->regname = *pRD->pCurrentContextPointers->regname; ENUM_CALLEE_SAVED_REGISTERS(); +#undef CALLEE_SAVED_REGISTER +#define CALLEE_SAVED_REGISTER(regname) pRD->pCurrentContext->regname = pRD->pCurrentContext->regname; + ENUM_FP_CALLEE_SAVED_REGISTERS(); #undef CALLEE_SAVED_REGISTER pRD->IsCallerContextValid = pOtherRD->IsCallerContextValid; if (pRD->IsCallerContextValid) @@ -1594,17 +1593,16 @@ void StackFrameIterator::SkipTo(StackFrameIterator *pOtherStackFrameIterator) *pRD->pCallerContextPointers = *pOtherRD->pCallerContextPointers; SetIP(pRD->pCallerContext, GetIP(pOtherRD->pCallerContext)); SetSP(pRD->pCallerContext, GetSP(pOtherRD->pCallerContext)); -#if defined(TARGET_ARM) || defined(TARGET_ARM64) - SetLR(pRD->pCallerContext, GetLR(pOtherRD->pCallerContext)); -#elif defined(TARGET_RISCV64) || defined(TARGET_LOONGARCH64) - SetRA(pRD->pCallerContext, GetRA(pOtherRD->pCallerContext)); -#endif // TARGET_ARM || TARGET_ARM64 #define CALLEE_SAVED_REGISTER(regname) pRD->pCallerContext->regname = *pRD->pCallerContextPointers->regname; ENUM_CALLEE_SAVED_REGISTERS(); +#undef CALLEE_SAVED_REGISTER +#define CALLEE_SAVED_REGISTER(regname) pRD->pCallerContext->regname = pRD->pCallerContext->regname; + ENUM_FP_CALLEE_SAVED_REGISTERS(); #undef CALLEE_SAVED_REGISTER } SyncRegDisplayToCurrentContext(pRD); } +#endif // FEATURE_EH_FUNCLETS #endif // DACCESS_COMPILE //--------------------------------------------------------------------------------------- diff --git a/src/coreclr/vm/stackwalk.h b/src/coreclr/vm/stackwalk.h index a65f1b916818ed..ac37c6679e83c2 100644 --- a/src/coreclr/vm/stackwalk.h +++ b/src/coreclr/vm/stackwalk.h @@ -600,8 +600,10 @@ class StackFrameIterator StackWalkAction Next(void); #ifndef DACCESS_COMPILE +#ifdef FEATURE_EH_FUNCLETS // advance to the position that the other iterator is currently at void SkipTo(StackFrameIterator *pOtherStackFrameIterator); +#endif // FEATURE_EH_FUNCLETS #endif // DACCESS_COMPILE #ifdef FEATURE_EH_FUNCLETS From add6b2f016c4bf6ae3e0bedeef586460eca0c182 Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Tue, 26 Mar 2024 16:34:02 +0100 Subject: [PATCH 3/6] Ensure Lr / Ra context pointers are non-null --- src/coreclr/pal/src/exception/seh-unwind.cpp | 2 ++ src/coreclr/vm/arm/stubs.cpp | 8 ++++---- src/coreclr/vm/arm64/stubs.cpp | 6 ++---- src/coreclr/vm/loongarch64/stubs.cpp | 8 +++----- src/coreclr/vm/riscv64/stubs.cpp | 8 +++----- src/coreclr/vm/stackwalk.cpp | 4 ++-- 6 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/coreclr/pal/src/exception/seh-unwind.cpp b/src/coreclr/pal/src/exception/seh-unwind.cpp index 5b12af8aa027bc..8ce69ce73f71a5 100644 --- a/src/coreclr/pal/src/exception/seh-unwind.cpp +++ b/src/coreclr/pal/src/exception/seh-unwind.cpp @@ -555,6 +555,7 @@ void GetContextPointers(unw_cursor_t *cursor, unw_context_t *unwContext, KNONVOL GetContextPointer(cursor, unwContext, UNW_ARM_R9, &contextPointers->R9); GetContextPointer(cursor, unwContext, UNW_ARM_R10, &contextPointers->R10); GetContextPointer(cursor, unwContext, UNW_ARM_R11, &contextPointers->R11); + GetContextPointer(cursor, unwContext, UNW_ARM_R14, &contextPointers->Lr); GetContextPointer(cursor, unwContext, UNW_ARM_D8, (SIZE_T **)&contextPointers->D8); GetContextPointer(cursor, unwContext, UNW_ARM_D9, (SIZE_T **)&contextPointers->D9); GetContextPointer(cursor, unwContext, UNW_ARM_D10, (SIZE_T **)&contextPointers->D10); @@ -575,6 +576,7 @@ void GetContextPointers(unw_cursor_t *cursor, unw_context_t *unwContext, KNONVOL GetContextPointer(cursor, unwContext, UNW_AARCH64_X27, (SIZE_T**)&contextPointers->X27); GetContextPointer(cursor, unwContext, UNW_AARCH64_X28, (SIZE_T**)&contextPointers->X28); GetContextPointer(cursor, unwContext, UNW_AARCH64_X29, (SIZE_T**)&contextPointers->Fp); + GetContextPointer(cursor, unwContext, UNW_AARCH64_X30, (SIZE_T**)&contextPointers->Lr); GetContextPointer(cursor, unwContext, UNW_AARCH64_V8, (SIZE_T**)&contextPointers->D8); GetContextPointer(cursor, unwContext, UNW_AARCH64_V9, (SIZE_T**)&contextPointers->D9); GetContextPointer(cursor, unwContext, UNW_AARCH64_V10, (SIZE_T**)&contextPointers->D10); diff --git a/src/coreclr/vm/arm/stubs.cpp b/src/coreclr/vm/arm/stubs.cpp index 1424dcecbd918d..8c85461cde9e63 100644 --- a/src/coreclr/vm/arm/stubs.cpp +++ b/src/coreclr/vm/arm/stubs.cpp @@ -718,7 +718,7 @@ void HelperMethodFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloat pRD->pCurrentContextPointers->R9 = m_MachState._R4_R11[5]; pRD->pCurrentContextPointers->R10 = m_MachState._R4_R11[6]; pRD->pCurrentContextPointers->R11 = m_MachState._R4_R11[7]; - pRD->pCurrentContextPointers->Lr = NULL; + pRD->pCurrentContextPointers->Lr = &pRD->pCurrentContext->Lr; } #ifndef DACCESS_COMPILE @@ -1505,7 +1505,7 @@ void UpdateRegDisplayFromCalleeSavedRegisters(REGDISPLAY * pRD, CalleeSavedRegis pRD->pCurrentContextPointers->R9 = (PDWORD)&pRegs->r9; pRD->pCurrentContextPointers->R10 = (PDWORD)&pRegs->r10; pRD->pCurrentContextPointers->R11 = (PDWORD)&pRegs->r11; - pRD->pCurrentContextPointers->Lr = NULL; + pRD->pCurrentContextPointers->Lr = (PDWORD)&pRegs->r14; } void TransitionFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloats) @@ -1565,7 +1565,7 @@ void FaultingExceptionFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool update pRD->pCurrentContextPointers->R9 = (PDWORD)&m_ctx.R9; pRD->pCurrentContextPointers->R10 = (PDWORD)&m_ctx.R10; pRD->pCurrentContextPointers->R11 = (PDWORD)&m_ctx.R11; - pRD->pCurrentContextPointers->Lr = NULL; + pRD->pCurrentContextPointers->Lr = (PDWORD)&m_ctx.Lr; pRD->IsCallerContextValid = FALSE; pRD->IsCallerSPValid = FALSE; // Don't add usage of this field. This is only temporary. @@ -1706,7 +1706,7 @@ void HijackFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloats) pRD->pCurrentContextPointers->R9 = &m_Args->R9; pRD->pCurrentContextPointers->R10 = &m_Args->R10; pRD->pCurrentContextPointers->R11 = &m_Args->R11; - pRD->pCurrentContextPointers->Lr = NULL; + pRD->pCurrentContextPointers->Lr = &m_Args->Lr; SyncRegDisplayToCurrentContext(pRD); } diff --git a/src/coreclr/vm/arm64/stubs.cpp b/src/coreclr/vm/arm64/stubs.cpp index 03783f016a52d3..fedcfe1979aa26 100644 --- a/src/coreclr/vm/arm64/stubs.cpp +++ b/src/coreclr/vm/arm64/stubs.cpp @@ -545,7 +545,7 @@ void HelperMethodFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloat pRD->pCurrentContextPointers->X27 = m_MachState.ptrX19_X29[8]; pRD->pCurrentContextPointers->X28 = m_MachState.ptrX19_X29[9]; pRD->pCurrentContextPointers->Fp = m_MachState.ptrX19_X29[10]; - pRD->pCurrentContextPointers->Lr = NULL; // Unwind again to get Caller's PC + pRD->pCurrentContextPointers->Lr = &pRD->pCurrentContext->Lr; #endif ClearRegDisplayArgumentAndScratchRegisters(pRD); @@ -629,8 +629,6 @@ void TransitionFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloats) ClearRegDisplayArgumentAndScratchRegisters(pRD); // copy the control registers - pRD->pCurrentContext->Fp = pCalleeSaved->x29; - pRD->pCurrentContext->Lr = pCalleeSaved->x30; pRD->pCurrentContext->Pc = GetReturnAddress(); pRD->pCurrentContext->Sp = this->GetSP(); @@ -825,7 +823,7 @@ void HijackFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloats) pRD->pCurrentContextPointers->X27 = &m_Args->X27; pRD->pCurrentContextPointers->X28 = &m_Args->X28; pRD->pCurrentContextPointers->Fp = &m_Args->X29; - pRD->pCurrentContextPointers->Lr = NULL; + pRD->pCurrentContextPointers->Lr = &m_Args->Lr; SyncRegDisplayToCurrentContext(pRD); diff --git a/src/coreclr/vm/loongarch64/stubs.cpp b/src/coreclr/vm/loongarch64/stubs.cpp index 052d71ebc1e44e..73477d979d0a7c 100644 --- a/src/coreclr/vm/loongarch64/stubs.cpp +++ b/src/coreclr/vm/loongarch64/stubs.cpp @@ -514,7 +514,7 @@ void HelperMethodFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloat pRD->pCurrentContextPointers->S8 = pUnwoundState->ptrCalleeSavedRegisters[8]; pRD->pCurrentContextPointers->Fp = pUnwoundState->ptrCalleeSavedRegisters[9]; pRD->pCurrentContextPointers->Tp = pUnwoundState->ptrCalleeSavedRegisters[10]; - pRD->pCurrentContextPointers->Ra = NULL; + pRD->pCurrentContextPointers->Ra = &pRD->pCurrentContext->Ra; return; } #endif // DACCESS_COMPILE @@ -567,7 +567,7 @@ void HelperMethodFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloat pRD->pCurrentContextPointers->S8 = m_MachState.ptrCalleeSavedRegisters[8]; pRD->pCurrentContextPointers->Fp = m_MachState.ptrCalleeSavedRegisters[9]; pRD->pCurrentContextPointers->Tp = m_MachState.ptrCalleeSavedRegisters[10]; - pRD->pCurrentContextPointers->Ra = NULL; // Unwind again to get Caller's PC + pRD->pCurrentContextPointers->Ra = pRD->pCurrentContext->Ra; #endif ClearRegDisplayArgumentAndScratchRegisters(pRD); } @@ -648,8 +648,6 @@ void TransitionFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloats) ClearRegDisplayArgumentAndScratchRegisters(pRD); // copy the control registers - //pRD->pCurrentContext->Fp = pCalleeSaved->fp;//not needed for duplicated. - //pRD->pCurrentContext->Ra = pCalleeSaved->ra;//not needed for duplicated. pRD->pCurrentContext->Pc = GetReturnAddress(); pRD->pCurrentContext->Sp = this->GetSP(); @@ -857,7 +855,7 @@ void HijackFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloats) pRD->pCurrentContextPointers->S8 = &m_Args->S8; pRD->pCurrentContextPointers->Tp = &m_Args->Tp; pRD->pCurrentContextPointers->Fp = &m_Args->Fp; - pRD->pCurrentContextPointers->Ra = NULL; + pRD->pCurrentContextPointers->Ra = &m_Args->Ra; SyncRegDisplayToCurrentContext(pRD); LOG((LF_GCROOTS, LL_INFO100000, "STACKWALK HijackFrame::UpdateRegDisplay(pc:%p, sp:%p)\n", pRD->ControlPC, pRD->SP)); diff --git a/src/coreclr/vm/riscv64/stubs.cpp b/src/coreclr/vm/riscv64/stubs.cpp index 4ce55a3849e12b..90101d8df475f1 100644 --- a/src/coreclr/vm/riscv64/stubs.cpp +++ b/src/coreclr/vm/riscv64/stubs.cpp @@ -414,7 +414,7 @@ void HelperMethodFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloat pRD->pCurrentContextPointers->S11 = pUnwoundState->ptrCalleeSavedRegisters[11]; pRD->pCurrentContextPointers->Gp = pUnwoundState->ptrCalleeSavedRegisters[12]; pRD->pCurrentContextPointers->Tp = pUnwoundState->ptrCalleeSavedRegisters[13]; - pRD->pCurrentContextPointers->Ra = NULL; + pRD->pCurrentContextPointers->Ra = &pRD->pCurrentContext->Ra; return; } #endif // DACCESS_COMPILE @@ -476,7 +476,7 @@ void HelperMethodFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloat pRD->pCurrentContextPointers->S11 = m_MachState.ptrCalleeSavedRegisters[11]; pRD->pCurrentContextPointers->Gp = m_MachState.ptrCalleeSavedRegisters[12]; pRD->pCurrentContextPointers->Tp = m_MachState.ptrCalleeSavedRegisters[13]; - pRD->pCurrentContextPointers->Ra = NULL; // Unwind again to get Caller's PC + pRD->pCurrentContextPointers->Ra = &pRD->pCurrentContext->Ra; #endif ClearRegDisplayArgumentAndScratchRegisters(pRD); } @@ -562,8 +562,6 @@ void TransitionFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloats) ClearRegDisplayArgumentAndScratchRegisters(pRD); // copy the control registers - //pRD->pCurrentContext->Fp = pCalleeSaved->fp;//not needed for duplicated. - //pRD->pCurrentContext->Ra = pCalleeSaved->ra;//not needed for duplicated. pRD->pCurrentContext->Pc = GetReturnAddress(); pRD->pCurrentContext->Sp = this->GetSP(); @@ -783,7 +781,7 @@ void HijackFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloats) pRD->pCurrentContextPointers->Gp = &m_Args->Gp; pRD->pCurrentContextPointers->Tp = &m_Args->Tp; pRD->pCurrentContextPointers->Fp = &m_Args->Fp; - pRD->pCurrentContextPointers->Ra = NULL; + pRD->pCurrentContextPointers->Ra = &m_Args->Ra; SyncRegDisplayToCurrentContext(pRD); LOG((LF_GCROOTS, LL_INFO100000, "STACKWALK HijackFrame::UpdateRegDisplay(pc:%p, sp:%p)\n", pRD->ControlPC, pRD->SP)); diff --git a/src/coreclr/vm/stackwalk.cpp b/src/coreclr/vm/stackwalk.cpp index 2eb5695ce9f62e..1bb11b8b876f4f 100644 --- a/src/coreclr/vm/stackwalk.cpp +++ b/src/coreclr/vm/stackwalk.cpp @@ -1584,7 +1584,7 @@ void StackFrameIterator::SkipTo(StackFrameIterator *pOtherStackFrameIterator) #define CALLEE_SAVED_REGISTER(regname) pRD->pCurrentContext->regname = *pRD->pCurrentContextPointers->regname; ENUM_CALLEE_SAVED_REGISTERS(); #undef CALLEE_SAVED_REGISTER -#define CALLEE_SAVED_REGISTER(regname) pRD->pCurrentContext->regname = pRD->pCurrentContext->regname; +#define CALLEE_SAVED_REGISTER(regname) pRD->pCurrentContext->regname = pOtherRD->pCurrentContext->regname; ENUM_FP_CALLEE_SAVED_REGISTERS(); #undef CALLEE_SAVED_REGISTER pRD->IsCallerContextValid = pOtherRD->IsCallerContextValid; @@ -1596,7 +1596,7 @@ void StackFrameIterator::SkipTo(StackFrameIterator *pOtherStackFrameIterator) #define CALLEE_SAVED_REGISTER(regname) pRD->pCallerContext->regname = *pRD->pCallerContextPointers->regname; ENUM_CALLEE_SAVED_REGISTERS(); #undef CALLEE_SAVED_REGISTER -#define CALLEE_SAVED_REGISTER(regname) pRD->pCallerContext->regname = pRD->pCallerContext->regname; +#define CALLEE_SAVED_REGISTER(regname) pRD->pCallerContext->regname = pOtherRD->pCallerContext->regname; ENUM_FP_CALLEE_SAVED_REGISTERS(); #undef CALLEE_SAVED_REGISTER } From 17dab6549b72d115bdc2b75e400b136077c597b9 Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Tue, 26 Mar 2024 21:18:25 +0100 Subject: [PATCH 4/6] Fix Apple where libunwind doesn't provide context pointers --- src/coreclr/vm/stackwalk.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/coreclr/vm/stackwalk.cpp b/src/coreclr/vm/stackwalk.cpp index 1bb11b8b876f4f..bbddd391d4a401 100644 --- a/src/coreclr/vm/stackwalk.cpp +++ b/src/coreclr/vm/stackwalk.cpp @@ -1581,21 +1581,26 @@ void StackFrameIterator::SkipTo(StackFrameIterator *pOtherStackFrameIterator) *pRD->pCurrentContextPointers = *pOtherRD->pCurrentContextPointers; SetIP(pRD->pCurrentContext, GetIP(pOtherRD->pCurrentContext)); SetSP(pRD->pCurrentContext, GetSP(pOtherRD->pCurrentContext)); -#define CALLEE_SAVED_REGISTER(regname) pRD->pCurrentContext->regname = *pRD->pCurrentContextPointers->regname; + +#define CALLEE_SAVED_REGISTER(regname) pRD->pCurrentContext->regname = (pRD->pCurrentContextPointers->regname == NULL) ? pOtherRD->pCurrentContext->regname : *pRD->pCurrentContextPointers->regname; ENUM_CALLEE_SAVED_REGISTERS(); #undef CALLEE_SAVED_REGISTER + #define CALLEE_SAVED_REGISTER(regname) pRD->pCurrentContext->regname = pOtherRD->pCurrentContext->regname; ENUM_FP_CALLEE_SAVED_REGISTERS(); #undef CALLEE_SAVED_REGISTER + pRD->IsCallerContextValid = pOtherRD->IsCallerContextValid; if (pRD->IsCallerContextValid) { *pRD->pCallerContextPointers = *pOtherRD->pCallerContextPointers; SetIP(pRD->pCallerContext, GetIP(pOtherRD->pCallerContext)); SetSP(pRD->pCallerContext, GetSP(pOtherRD->pCallerContext)); -#define CALLEE_SAVED_REGISTER(regname) pRD->pCallerContext->regname = *pRD->pCallerContextPointers->regname; + +#define CALLEE_SAVED_REGISTER(regname) pRD->pCallerContext->regname = (pRD->pCallerContextPointers->regname == NULL) ? pOtherRD->pCallerContext->regname : *pRD->pCallerContextPointers->regname; ENUM_CALLEE_SAVED_REGISTERS(); #undef CALLEE_SAVED_REGISTER + #define CALLEE_SAVED_REGISTER(regname) pRD->pCallerContext->regname = pOtherRD->pCallerContext->regname; ENUM_FP_CALLEE_SAVED_REGISTERS(); #undef CALLEE_SAVED_REGISTER From bed0c2b084cd14a71fdeef82f767d8098f54ee21 Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Wed, 27 Mar 2024 01:12:36 +0100 Subject: [PATCH 5/6] Revert the LR/RA context pointers related changes --- src/coreclr/inc/regdisp.h | 1 - src/coreclr/pal/src/exception/seh-unwind.cpp | 2 -- src/coreclr/vm/arm/stubs.cpp | 8 ++++---- src/coreclr/vm/arm64/stubs.cpp | 6 ++++-- src/coreclr/vm/loongarch64/stubs.cpp | 8 +++++--- src/coreclr/vm/riscv64/stubs.cpp | 8 +++++--- 6 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/coreclr/inc/regdisp.h b/src/coreclr/inc/regdisp.h index c3e4c560dec480..ec47b9019dbc02 100644 --- a/src/coreclr/inc/regdisp.h +++ b/src/coreclr/inc/regdisp.h @@ -426,7 +426,6 @@ inline void FillContextPointers(PT_KNONVOLATILE_CONTEXT_POINTERS pCtxPtrs, PT_CO { *(&pCtxPtrs->R4 + i) = (&pCtx->R4 + i); } - *(&pCtxPtrs->Lr) = &pCtx->Lr; #elif defined(TARGET_X86) // TARGET_ARM for (int i = 0; i < 7; i++) { diff --git a/src/coreclr/pal/src/exception/seh-unwind.cpp b/src/coreclr/pal/src/exception/seh-unwind.cpp index 8ce69ce73f71a5..5b12af8aa027bc 100644 --- a/src/coreclr/pal/src/exception/seh-unwind.cpp +++ b/src/coreclr/pal/src/exception/seh-unwind.cpp @@ -555,7 +555,6 @@ void GetContextPointers(unw_cursor_t *cursor, unw_context_t *unwContext, KNONVOL GetContextPointer(cursor, unwContext, UNW_ARM_R9, &contextPointers->R9); GetContextPointer(cursor, unwContext, UNW_ARM_R10, &contextPointers->R10); GetContextPointer(cursor, unwContext, UNW_ARM_R11, &contextPointers->R11); - GetContextPointer(cursor, unwContext, UNW_ARM_R14, &contextPointers->Lr); GetContextPointer(cursor, unwContext, UNW_ARM_D8, (SIZE_T **)&contextPointers->D8); GetContextPointer(cursor, unwContext, UNW_ARM_D9, (SIZE_T **)&contextPointers->D9); GetContextPointer(cursor, unwContext, UNW_ARM_D10, (SIZE_T **)&contextPointers->D10); @@ -576,7 +575,6 @@ void GetContextPointers(unw_cursor_t *cursor, unw_context_t *unwContext, KNONVOL GetContextPointer(cursor, unwContext, UNW_AARCH64_X27, (SIZE_T**)&contextPointers->X27); GetContextPointer(cursor, unwContext, UNW_AARCH64_X28, (SIZE_T**)&contextPointers->X28); GetContextPointer(cursor, unwContext, UNW_AARCH64_X29, (SIZE_T**)&contextPointers->Fp); - GetContextPointer(cursor, unwContext, UNW_AARCH64_X30, (SIZE_T**)&contextPointers->Lr); GetContextPointer(cursor, unwContext, UNW_AARCH64_V8, (SIZE_T**)&contextPointers->D8); GetContextPointer(cursor, unwContext, UNW_AARCH64_V9, (SIZE_T**)&contextPointers->D9); GetContextPointer(cursor, unwContext, UNW_AARCH64_V10, (SIZE_T**)&contextPointers->D10); diff --git a/src/coreclr/vm/arm/stubs.cpp b/src/coreclr/vm/arm/stubs.cpp index 8c85461cde9e63..1424dcecbd918d 100644 --- a/src/coreclr/vm/arm/stubs.cpp +++ b/src/coreclr/vm/arm/stubs.cpp @@ -718,7 +718,7 @@ void HelperMethodFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloat pRD->pCurrentContextPointers->R9 = m_MachState._R4_R11[5]; pRD->pCurrentContextPointers->R10 = m_MachState._R4_R11[6]; pRD->pCurrentContextPointers->R11 = m_MachState._R4_R11[7]; - pRD->pCurrentContextPointers->Lr = &pRD->pCurrentContext->Lr; + pRD->pCurrentContextPointers->Lr = NULL; } #ifndef DACCESS_COMPILE @@ -1505,7 +1505,7 @@ void UpdateRegDisplayFromCalleeSavedRegisters(REGDISPLAY * pRD, CalleeSavedRegis pRD->pCurrentContextPointers->R9 = (PDWORD)&pRegs->r9; pRD->pCurrentContextPointers->R10 = (PDWORD)&pRegs->r10; pRD->pCurrentContextPointers->R11 = (PDWORD)&pRegs->r11; - pRD->pCurrentContextPointers->Lr = (PDWORD)&pRegs->r14; + pRD->pCurrentContextPointers->Lr = NULL; } void TransitionFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloats) @@ -1565,7 +1565,7 @@ void FaultingExceptionFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool update pRD->pCurrentContextPointers->R9 = (PDWORD)&m_ctx.R9; pRD->pCurrentContextPointers->R10 = (PDWORD)&m_ctx.R10; pRD->pCurrentContextPointers->R11 = (PDWORD)&m_ctx.R11; - pRD->pCurrentContextPointers->Lr = (PDWORD)&m_ctx.Lr; + pRD->pCurrentContextPointers->Lr = NULL; pRD->IsCallerContextValid = FALSE; pRD->IsCallerSPValid = FALSE; // Don't add usage of this field. This is only temporary. @@ -1706,7 +1706,7 @@ void HijackFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloats) pRD->pCurrentContextPointers->R9 = &m_Args->R9; pRD->pCurrentContextPointers->R10 = &m_Args->R10; pRD->pCurrentContextPointers->R11 = &m_Args->R11; - pRD->pCurrentContextPointers->Lr = &m_Args->Lr; + pRD->pCurrentContextPointers->Lr = NULL; SyncRegDisplayToCurrentContext(pRD); } diff --git a/src/coreclr/vm/arm64/stubs.cpp b/src/coreclr/vm/arm64/stubs.cpp index fedcfe1979aa26..03783f016a52d3 100644 --- a/src/coreclr/vm/arm64/stubs.cpp +++ b/src/coreclr/vm/arm64/stubs.cpp @@ -545,7 +545,7 @@ void HelperMethodFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloat pRD->pCurrentContextPointers->X27 = m_MachState.ptrX19_X29[8]; pRD->pCurrentContextPointers->X28 = m_MachState.ptrX19_X29[9]; pRD->pCurrentContextPointers->Fp = m_MachState.ptrX19_X29[10]; - pRD->pCurrentContextPointers->Lr = &pRD->pCurrentContext->Lr; + pRD->pCurrentContextPointers->Lr = NULL; // Unwind again to get Caller's PC #endif ClearRegDisplayArgumentAndScratchRegisters(pRD); @@ -629,6 +629,8 @@ void TransitionFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloats) ClearRegDisplayArgumentAndScratchRegisters(pRD); // copy the control registers + pRD->pCurrentContext->Fp = pCalleeSaved->x29; + pRD->pCurrentContext->Lr = pCalleeSaved->x30; pRD->pCurrentContext->Pc = GetReturnAddress(); pRD->pCurrentContext->Sp = this->GetSP(); @@ -823,7 +825,7 @@ void HijackFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloats) pRD->pCurrentContextPointers->X27 = &m_Args->X27; pRD->pCurrentContextPointers->X28 = &m_Args->X28; pRD->pCurrentContextPointers->Fp = &m_Args->X29; - pRD->pCurrentContextPointers->Lr = &m_Args->Lr; + pRD->pCurrentContextPointers->Lr = NULL; SyncRegDisplayToCurrentContext(pRD); diff --git a/src/coreclr/vm/loongarch64/stubs.cpp b/src/coreclr/vm/loongarch64/stubs.cpp index 73477d979d0a7c..052d71ebc1e44e 100644 --- a/src/coreclr/vm/loongarch64/stubs.cpp +++ b/src/coreclr/vm/loongarch64/stubs.cpp @@ -514,7 +514,7 @@ void HelperMethodFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloat pRD->pCurrentContextPointers->S8 = pUnwoundState->ptrCalleeSavedRegisters[8]; pRD->pCurrentContextPointers->Fp = pUnwoundState->ptrCalleeSavedRegisters[9]; pRD->pCurrentContextPointers->Tp = pUnwoundState->ptrCalleeSavedRegisters[10]; - pRD->pCurrentContextPointers->Ra = &pRD->pCurrentContext->Ra; + pRD->pCurrentContextPointers->Ra = NULL; return; } #endif // DACCESS_COMPILE @@ -567,7 +567,7 @@ void HelperMethodFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloat pRD->pCurrentContextPointers->S8 = m_MachState.ptrCalleeSavedRegisters[8]; pRD->pCurrentContextPointers->Fp = m_MachState.ptrCalleeSavedRegisters[9]; pRD->pCurrentContextPointers->Tp = m_MachState.ptrCalleeSavedRegisters[10]; - pRD->pCurrentContextPointers->Ra = pRD->pCurrentContext->Ra; + pRD->pCurrentContextPointers->Ra = NULL; // Unwind again to get Caller's PC #endif ClearRegDisplayArgumentAndScratchRegisters(pRD); } @@ -648,6 +648,8 @@ void TransitionFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloats) ClearRegDisplayArgumentAndScratchRegisters(pRD); // copy the control registers + //pRD->pCurrentContext->Fp = pCalleeSaved->fp;//not needed for duplicated. + //pRD->pCurrentContext->Ra = pCalleeSaved->ra;//not needed for duplicated. pRD->pCurrentContext->Pc = GetReturnAddress(); pRD->pCurrentContext->Sp = this->GetSP(); @@ -855,7 +857,7 @@ void HijackFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloats) pRD->pCurrentContextPointers->S8 = &m_Args->S8; pRD->pCurrentContextPointers->Tp = &m_Args->Tp; pRD->pCurrentContextPointers->Fp = &m_Args->Fp; - pRD->pCurrentContextPointers->Ra = &m_Args->Ra; + pRD->pCurrentContextPointers->Ra = NULL; SyncRegDisplayToCurrentContext(pRD); LOG((LF_GCROOTS, LL_INFO100000, "STACKWALK HijackFrame::UpdateRegDisplay(pc:%p, sp:%p)\n", pRD->ControlPC, pRD->SP)); diff --git a/src/coreclr/vm/riscv64/stubs.cpp b/src/coreclr/vm/riscv64/stubs.cpp index 90101d8df475f1..4ce55a3849e12b 100644 --- a/src/coreclr/vm/riscv64/stubs.cpp +++ b/src/coreclr/vm/riscv64/stubs.cpp @@ -414,7 +414,7 @@ void HelperMethodFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloat pRD->pCurrentContextPointers->S11 = pUnwoundState->ptrCalleeSavedRegisters[11]; pRD->pCurrentContextPointers->Gp = pUnwoundState->ptrCalleeSavedRegisters[12]; pRD->pCurrentContextPointers->Tp = pUnwoundState->ptrCalleeSavedRegisters[13]; - pRD->pCurrentContextPointers->Ra = &pRD->pCurrentContext->Ra; + pRD->pCurrentContextPointers->Ra = NULL; return; } #endif // DACCESS_COMPILE @@ -476,7 +476,7 @@ void HelperMethodFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloat pRD->pCurrentContextPointers->S11 = m_MachState.ptrCalleeSavedRegisters[11]; pRD->pCurrentContextPointers->Gp = m_MachState.ptrCalleeSavedRegisters[12]; pRD->pCurrentContextPointers->Tp = m_MachState.ptrCalleeSavedRegisters[13]; - pRD->pCurrentContextPointers->Ra = &pRD->pCurrentContext->Ra; + pRD->pCurrentContextPointers->Ra = NULL; // Unwind again to get Caller's PC #endif ClearRegDisplayArgumentAndScratchRegisters(pRD); } @@ -562,6 +562,8 @@ void TransitionFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloats) ClearRegDisplayArgumentAndScratchRegisters(pRD); // copy the control registers + //pRD->pCurrentContext->Fp = pCalleeSaved->fp;//not needed for duplicated. + //pRD->pCurrentContext->Ra = pCalleeSaved->ra;//not needed for duplicated. pRD->pCurrentContext->Pc = GetReturnAddress(); pRD->pCurrentContext->Sp = this->GetSP(); @@ -781,7 +783,7 @@ void HijackFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloats) pRD->pCurrentContextPointers->Gp = &m_Args->Gp; pRD->pCurrentContextPointers->Tp = &m_Args->Tp; pRD->pCurrentContextPointers->Fp = &m_Args->Fp; - pRD->pCurrentContextPointers->Ra = &m_Args->Ra; + pRD->pCurrentContextPointers->Ra = NULL; SyncRegDisplayToCurrentContext(pRD); LOG((LF_GCROOTS, LL_INFO100000, "STACKWALK HijackFrame::UpdateRegDisplay(pc:%p, sp:%p)\n", pRD->ControlPC, pRD->SP)); From 86389ea6ea0906fbbb4577ce14e858e19a475cbf Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Wed, 27 Mar 2024 22:55:43 +0100 Subject: [PATCH 6/6] Remove saving / restoring the GS cookie stuff --- src/coreclr/vm/stackwalk.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/coreclr/vm/stackwalk.cpp b/src/coreclr/vm/stackwalk.cpp index bbddd391d4a401..56e76cdf4949d1 100644 --- a/src/coreclr/vm/stackwalk.cpp +++ b/src/coreclr/vm/stackwalk.cpp @@ -1559,8 +1559,6 @@ void StackFrameIterator::SkipTo(StackFrameIterator *pOtherStackFrameIterator) // after the copy. ExInfo* pPrevExInfo = GetNextExInfo(); REGDISPLAY *pRD = m_crawl.GetRegisterSet(); - GSCookie *pCurGSCookie = m_crawl.pCurGSCookie; - GSCookie *pFirstGSCookie = m_crawl.pFirstGSCookie; Frame *pStartFrame = m_pStartFrame; #ifdef _DEBUG Frame *pRealStartFrame = m_pRealStartFrame; @@ -1570,8 +1568,6 @@ void StackFrameIterator::SkipTo(StackFrameIterator *pOtherStackFrameIterator) m_pNextExInfo = pPrevExInfo; m_crawl.pRD = pRD; - m_crawl.pCurGSCookie = pCurGSCookie; - m_crawl.pFirstGSCookie = pFirstGSCookie; m_pStartFrame = pStartFrame; #ifdef _DEBUG m_pRealStartFrame = pRealStartFrame;