Skip to content

Commit

Permalink
Ensure Lr / Ra context pointers are non-null
Browse files Browse the repository at this point in the history
  • Loading branch information
janvorli committed Mar 26, 2024
1 parent bc57e00 commit add6b2f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 20 deletions.
2 changes: 2 additions & 0 deletions src/coreclr/pal/src/exception/seh-unwind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/coreclr/vm/arm/stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 2 additions & 4 deletions src/coreclr/vm/arm64/stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);

Expand Down
8 changes: 3 additions & 5 deletions src/coreclr/vm/loongarch64/stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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));
Expand Down
8 changes: 3 additions & 5 deletions src/coreclr/vm/riscv64/stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/vm/stackwalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
}
Expand Down

0 comments on commit add6b2f

Please sign in to comment.