Skip to content

Commit 35c8a4e

Browse files
committed
Ensure Lr / Ra context pointers are non-null
1 parent bc57e00 commit 35c8a4e

File tree

6 files changed

+16
-20
lines changed

6 files changed

+16
-20
lines changed

src/coreclr/pal/src/exception/seh-unwind.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ void GetContextPointers(unw_cursor_t *cursor, unw_context_t *unwContext, KNONVOL
555555
GetContextPointer(cursor, unwContext, UNW_ARM_R9, &contextPointers->R9);
556556
GetContextPointer(cursor, unwContext, UNW_ARM_R10, &contextPointers->R10);
557557
GetContextPointer(cursor, unwContext, UNW_ARM_R11, &contextPointers->R11);
558+
GetContextPointer(cursor, unwContext, UNW_ARM_R14, &contextPointers->Lr);
558559
GetContextPointer(cursor, unwContext, UNW_ARM_D8, (SIZE_T **)&contextPointers->D8);
559560
GetContextPointer(cursor, unwContext, UNW_ARM_D9, (SIZE_T **)&contextPointers->D9);
560561
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
575576
GetContextPointer(cursor, unwContext, UNW_AARCH64_X27, (SIZE_T**)&contextPointers->X27);
576577
GetContextPointer(cursor, unwContext, UNW_AARCH64_X28, (SIZE_T**)&contextPointers->X28);
577578
GetContextPointer(cursor, unwContext, UNW_AARCH64_X29, (SIZE_T**)&contextPointers->Fp);
579+
GetContextPointer(cursor, unwContext, UNW_AARCH64_X30, (SIZE_T**)&contextPointers->Lr);
578580
GetContextPointer(cursor, unwContext, UNW_AARCH64_V8, (SIZE_T**)&contextPointers->D8);
579581
GetContextPointer(cursor, unwContext, UNW_AARCH64_V9, (SIZE_T**)&contextPointers->D9);
580582
GetContextPointer(cursor, unwContext, UNW_AARCH64_V10, (SIZE_T**)&contextPointers->D10);

src/coreclr/vm/arm/stubs.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ void HelperMethodFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloat
718718
pRD->pCurrentContextPointers->R9 = m_MachState._R4_R11[5];
719719
pRD->pCurrentContextPointers->R10 = m_MachState._R4_R11[6];
720720
pRD->pCurrentContextPointers->R11 = m_MachState._R4_R11[7];
721-
pRD->pCurrentContextPointers->Lr = NULL;
721+
pRD->pCurrentContextPointers->Lr = &pRD->pCurrentContext->Lr;
722722
}
723723

724724
#ifndef DACCESS_COMPILE
@@ -1505,7 +1505,7 @@ void UpdateRegDisplayFromCalleeSavedRegisters(REGDISPLAY * pRD, CalleeSavedRegis
15051505
pRD->pCurrentContextPointers->R9 = (PDWORD)&pRegs->r9;
15061506
pRD->pCurrentContextPointers->R10 = (PDWORD)&pRegs->r10;
15071507
pRD->pCurrentContextPointers->R11 = (PDWORD)&pRegs->r11;
1508-
pRD->pCurrentContextPointers->Lr = NULL;
1508+
pRD->pCurrentContextPointers->Lr = (PDWORD)&pRegs->r14;
15091509
}
15101510

15111511
void TransitionFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloats)
@@ -1565,7 +1565,7 @@ void FaultingExceptionFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool update
15651565
pRD->pCurrentContextPointers->R9 = (PDWORD)&m_ctx.R9;
15661566
pRD->pCurrentContextPointers->R10 = (PDWORD)&m_ctx.R10;
15671567
pRD->pCurrentContextPointers->R11 = (PDWORD)&m_ctx.R11;
1568-
pRD->pCurrentContextPointers->Lr = NULL;
1568+
pRD->pCurrentContextPointers->Lr = (PDWORD)&m_ctx.Lr;
15691569

15701570
pRD->IsCallerContextValid = FALSE;
15711571
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)
17061706
pRD->pCurrentContextPointers->R9 = &m_Args->R9;
17071707
pRD->pCurrentContextPointers->R10 = &m_Args->R10;
17081708
pRD->pCurrentContextPointers->R11 = &m_Args->R11;
1709-
pRD->pCurrentContextPointers->Lr = NULL;
1709+
pRD->pCurrentContextPointers->Lr = &m_Args->Lr;
17101710

17111711
SyncRegDisplayToCurrentContext(pRD);
17121712
}

src/coreclr/vm/arm64/stubs.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ void HelperMethodFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloat
545545
pRD->pCurrentContextPointers->X27 = m_MachState.ptrX19_X29[8];
546546
pRD->pCurrentContextPointers->X28 = m_MachState.ptrX19_X29[9];
547547
pRD->pCurrentContextPointers->Fp = m_MachState.ptrX19_X29[10];
548-
pRD->pCurrentContextPointers->Lr = NULL; // Unwind again to get Caller's PC
548+
pRD->pCurrentContextPointers->Lr = &pRD->pCurrentContext->Lr
549549
#endif
550550

551551
ClearRegDisplayArgumentAndScratchRegisters(pRD);
@@ -629,8 +629,6 @@ void TransitionFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloats)
629629
ClearRegDisplayArgumentAndScratchRegisters(pRD);
630630

631631
// copy the control registers
632-
pRD->pCurrentContext->Fp = pCalleeSaved->x29;
633-
pRD->pCurrentContext->Lr = pCalleeSaved->x30;
634632
pRD->pCurrentContext->Pc = GetReturnAddress();
635633
pRD->pCurrentContext->Sp = this->GetSP();
636634

@@ -825,7 +823,7 @@ void HijackFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloats)
825823
pRD->pCurrentContextPointers->X27 = &m_Args->X27;
826824
pRD->pCurrentContextPointers->X28 = &m_Args->X28;
827825
pRD->pCurrentContextPointers->Fp = &m_Args->X29;
828-
pRD->pCurrentContextPointers->Lr = NULL;
826+
pRD->pCurrentContextPointers->Lr = &m_Args->Lr;
829827

830828
SyncRegDisplayToCurrentContext(pRD);
831829

src/coreclr/vm/loongarch64/stubs.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ void HelperMethodFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloat
514514
pRD->pCurrentContextPointers->S8 = pUnwoundState->ptrCalleeSavedRegisters[8];
515515
pRD->pCurrentContextPointers->Fp = pUnwoundState->ptrCalleeSavedRegisters[9];
516516
pRD->pCurrentContextPointers->Tp = pUnwoundState->ptrCalleeSavedRegisters[10];
517-
pRD->pCurrentContextPointers->Ra = NULL;
517+
pRD->pCurrentContextPointers->Ra = &pRD->pCurrentContext->Ra;
518518
return;
519519
}
520520
#endif // DACCESS_COMPILE
@@ -567,7 +567,7 @@ void HelperMethodFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloat
567567
pRD->pCurrentContextPointers->S8 = m_MachState.ptrCalleeSavedRegisters[8];
568568
pRD->pCurrentContextPointers->Fp = m_MachState.ptrCalleeSavedRegisters[9];
569569
pRD->pCurrentContextPointers->Tp = m_MachState.ptrCalleeSavedRegisters[10];
570-
pRD->pCurrentContextPointers->Ra = NULL; // Unwind again to get Caller's PC
570+
pRD->pCurrentContextPointers->Ra = pRD->pCurrentContext->Ra;
571571
#endif
572572
ClearRegDisplayArgumentAndScratchRegisters(pRD);
573573
}
@@ -648,8 +648,6 @@ void TransitionFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloats)
648648
ClearRegDisplayArgumentAndScratchRegisters(pRD);
649649

650650
// copy the control registers
651-
//pRD->pCurrentContext->Fp = pCalleeSaved->fp;//not needed for duplicated.
652-
//pRD->pCurrentContext->Ra = pCalleeSaved->ra;//not needed for duplicated.
653651
pRD->pCurrentContext->Pc = GetReturnAddress();
654652
pRD->pCurrentContext->Sp = this->GetSP();
655653

@@ -857,7 +855,7 @@ void HijackFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloats)
857855
pRD->pCurrentContextPointers->S8 = &m_Args->S8;
858856
pRD->pCurrentContextPointers->Tp = &m_Args->Tp;
859857
pRD->pCurrentContextPointers->Fp = &m_Args->Fp;
860-
pRD->pCurrentContextPointers->Ra = NULL;
858+
pRD->pCurrentContextPointers->Ra = &m_Args->Ra;
861859
SyncRegDisplayToCurrentContext(pRD);
862860

863861
LOG((LF_GCROOTS, LL_INFO100000, "STACKWALK HijackFrame::UpdateRegDisplay(pc:%p, sp:%p)\n", pRD->ControlPC, pRD->SP));

src/coreclr/vm/riscv64/stubs.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ void HelperMethodFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloat
414414
pRD->pCurrentContextPointers->S11 = pUnwoundState->ptrCalleeSavedRegisters[11];
415415
pRD->pCurrentContextPointers->Gp = pUnwoundState->ptrCalleeSavedRegisters[12];
416416
pRD->pCurrentContextPointers->Tp = pUnwoundState->ptrCalleeSavedRegisters[13];
417-
pRD->pCurrentContextPointers->Ra = NULL;
417+
pRD->pCurrentContextPointers->Ra = &pRD->pCurrentContext->Ra;
418418
return;
419419
}
420420
#endif // DACCESS_COMPILE
@@ -476,7 +476,7 @@ void HelperMethodFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloat
476476
pRD->pCurrentContextPointers->S11 = m_MachState.ptrCalleeSavedRegisters[11];
477477
pRD->pCurrentContextPointers->Gp = m_MachState.ptrCalleeSavedRegisters[12];
478478
pRD->pCurrentContextPointers->Tp = m_MachState.ptrCalleeSavedRegisters[13];
479-
pRD->pCurrentContextPointers->Ra = NULL; // Unwind again to get Caller's PC
479+
pRD->pCurrentContextPointers->Ra = &pRD->pCurrentContext->Ra;
480480
#endif
481481
ClearRegDisplayArgumentAndScratchRegisters(pRD);
482482
}
@@ -562,8 +562,6 @@ void TransitionFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloats)
562562
ClearRegDisplayArgumentAndScratchRegisters(pRD);
563563

564564
// copy the control registers
565-
//pRD->pCurrentContext->Fp = pCalleeSaved->fp;//not needed for duplicated.
566-
//pRD->pCurrentContext->Ra = pCalleeSaved->ra;//not needed for duplicated.
567565
pRD->pCurrentContext->Pc = GetReturnAddress();
568566
pRD->pCurrentContext->Sp = this->GetSP();
569567

@@ -783,7 +781,7 @@ void HijackFrame::UpdateRegDisplay(const PREGDISPLAY pRD, bool updateFloats)
783781
pRD->pCurrentContextPointers->Gp = &m_Args->Gp;
784782
pRD->pCurrentContextPointers->Tp = &m_Args->Tp;
785783
pRD->pCurrentContextPointers->Fp = &m_Args->Fp;
786-
pRD->pCurrentContextPointers->Ra = NULL;
784+
pRD->pCurrentContextPointers->Ra = &m_Args->Ra;
787785
SyncRegDisplayToCurrentContext(pRD);
788786

789787
LOG((LF_GCROOTS, LL_INFO100000, "STACKWALK HijackFrame::UpdateRegDisplay(pc:%p, sp:%p)\n", pRD->ControlPC, pRD->SP));

src/coreclr/vm/stackwalk.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1584,7 +1584,7 @@ void StackFrameIterator::SkipTo(StackFrameIterator *pOtherStackFrameIterator)
15841584
#define CALLEE_SAVED_REGISTER(regname) pRD->pCurrentContext->regname = *pRD->pCurrentContextPointers->regname;
15851585
ENUM_CALLEE_SAVED_REGISTERS();
15861586
#undef CALLEE_SAVED_REGISTER
1587-
#define CALLEE_SAVED_REGISTER(regname) pRD->pCurrentContext->regname = pRD->pCurrentContext->regname;
1587+
#define CALLEE_SAVED_REGISTER(regname) pRD->pCurrentContext->regname = pOtherRD->pCurrentContext->regname;
15881588
ENUM_FP_CALLEE_SAVED_REGISTERS();
15891589
#undef CALLEE_SAVED_REGISTER
15901590
pRD->IsCallerContextValid = pOtherRD->IsCallerContextValid;
@@ -1596,7 +1596,7 @@ void StackFrameIterator::SkipTo(StackFrameIterator *pOtherStackFrameIterator)
15961596
#define CALLEE_SAVED_REGISTER(regname) pRD->pCallerContext->regname = *pRD->pCallerContextPointers->regname;
15971597
ENUM_CALLEE_SAVED_REGISTERS();
15981598
#undef CALLEE_SAVED_REGISTER
1599-
#define CALLEE_SAVED_REGISTER(regname) pRD->pCallerContext->regname = pRD->pCallerContext->regname;
1599+
#define CALLEE_SAVED_REGISTER(regname) pRD->pCallerContext->regname = pOtherRD->pCallerContext->regname;
16001600
ENUM_FP_CALLEE_SAVED_REGISTERS();
16011601
#undef CALLEE_SAVED_REGISTER
16021602
}

0 commit comments

Comments
 (0)