Repository: dotnet/runtime
File: src/coreclr/vm/amd64/cgenamd64.cpp (C++)

Code before:
        SetFirstArgReg(pRD->pCurrentContext, dac_cast<TADDR>(m_Next));
    }
#endif // FEATURE_INTERPRETER

    LOG((LF_GCROOTS, LL_INFO100000, "STACKWALK    InlinedCallFrame::UpdateRegDisplay_Impl(rip:%p, rsp:%p)\n", pRD->ControlPC, pRD->SP));
}

void FaultingExceptionFrame::UpdateRegDisplay_Impl(const PREGDISPLAY pRD, bool updateFloats)
{
    LIMITED_METHOD_DAC_CONTRACT;

    memcpy(pRD->pCurrentContext, &m_ctx, sizeof(CONTEXT));

    // Clear the CONTEXT_XSTATE, since the REGDISPLAY contains just plain CONTEXT structure
    // that cannot contain any extended state.
    pRD->pCurrentContext->ContextFlags &= ~(CONTEXT_XSTATE & CONTEXT_AREA_MASK);

    pRD->ControlPC = m_ctx.Rip;

    pRD->SP = m_ctx.Rsp;

#ifdef TARGET_WINDOWS
    pRD->SSP = m_SSP;
#endif

#ifdef DACCESS_COMPILE
    // &m_ctx.Xxx resolves through the DAC cache and the entry can be evicted
    // before context pointers are consumed. Point at the local copy in
    // pCurrentContext instead (values were already copied above).
    pRD->pCurrentContextPointers->Rax = &pRD->pCurrentContext->Rax;
    pRD->pCurrentContextPointers->Rcx = &pRD->pCurrentContext->Rcx;
    pRD->pCurrentContextPointers->Rdx = &pRD->pCurrentContext->Rdx;
    pRD->pCurrentContextPointers->Rbx = &pRD->pCurrentContext->Rbx;
    pRD->pCurrentContextPointers->Rbp = &pRD->pCurrentContext->Rbp;
    pRD->pCurrentContextPointers->Rsi = &pRD->pCurrentContext->Rsi;
    pRD->pCurrentContextPointers->Rdi = &pRD->pCurrentContext->Rdi;
    pRD->pCurrentContextPointers->R8  = &pRD->pCurrentContext->R8;
    pRD->pCurrentContextPointers->R9  = &pRD->pCurrentContext->R9;
    pRD->pCurrentContextPointers->R10 = &pRD->pCurrentContext->R10;
    pRD->pCurrentContextPointers->R11 = &pRD->pCurrentContext->R11;
    pRD->pCurrentContextPointers->R12 = &pRD->pCurrentContext->R12;
    pRD->pCurrentContextPointers->R13 = &pRD->pCurrentContext->R13;
    pRD->pCurrentContextPointers->R14 = &pRD->pCurrentContext->R14;
    pRD->pCurrentContextPointers->R15 = &pRD->pCurrentContext->R15;
#else
    pRD->pCurrentContextPointers->Rax = &m_ctx.Rax;
    pRD->pCurrentContextPointers->Rcx = &m_ctx.Rcx;
    pRD->pCurrentContextPointers->Rdx = &m_ctx.Rdx;
    pRD->pCurrentContextPointers->Rbx = &m_ctx.Rbx;
    pRD->pCurrentContextPointers->Rbp = &m_ctx.Rbp;
    pRD->pCurrentContextPointers->Rsi = &m_ctx.Rsi;

Review comment (refactor):
A nit - we can simplify the change here as follows so that we don't have to repeat the long sequence.
```c++
#ifdef DACCESS_COMPILE
CONTEXT *pContext = pRD->pCurrentContex;
#else
CONTEXT *pContext = &m_ctx;
#endif
pRD->pCurrentContextPointers->Rax = &pContext->Rax;
.
.
.
```

Code after:
        SetFirstArgReg(pRD->pCurrentContext, dac_cast<TADDR>(m_Next));
    }
#endif // FEATURE_INTERPRETER

    LOG((LF_GCROOTS, LL_INFO100000, "STACKWALK    InlinedCallFrame::UpdateRegDisplay_Impl(rip:%p, rsp:%p)\n", pRD->ControlPC, pRD->SP));
}

void FaultingExceptionFrame::UpdateRegDisplay_Impl(const PREGDISPLAY pRD, bool updateFloats)
{
    LIMITED_METHOD_DAC_CONTRACT;

    memcpy(pRD->pCurrentContext, &m_ctx, sizeof(CONTEXT));

    // Clear the CONTEXT_XSTATE, since the REGDISPLAY contains just plain CONTEXT structure
    // that cannot contain any extended state.
    pRD->pCurrentContext->ContextFlags &= ~(CONTEXT_XSTATE & CONTEXT_AREA_MASK);

    pRD->ControlPC = m_ctx.Rip;

    pRD->SP = m_ctx.Rsp;

#ifdef TARGET_WINDOWS
    pRD->SSP = m_SSP;
#endif

#ifdef DACCESS_COMPILE
    // &m_ctx.Xxx resolves through the DAC cache and the entry can be evicted
    // before context pointers are consumed. Point at the local copy in
    // pCurrentContext instead (values were already copied above).
    CONTEXT *pContext = pRD->pCurrentContext;
#else
    CONTEXT *pContext = &m_ctx;
#endif

    pRD->pCurrentContextPointers->Rax = &pContext->Rax;
    pRD->pCurrentContextPointers->Rcx = &pContext->Rcx;
    pRD->pCurrentContextPointers->Rdx = &pContext->Rdx;
    pRD->pCurrentContextPointers->Rbx = &pContext->Rbx;
    pRD->pCurrentContextPointers->Rbp = &pContext->Rbp;
    pRD->pCurrentContextPointers->Rsi = &pContext->Rsi;
    pRD->pCurrentContextPointers->Rdi = &pContext->Rdi;
    pRD->pCurrentContextPointers->R8  = &pContext->R8;
    pRD->pCurrentContextPointers->R9  = &pContext->R9;
    pRD->pCurrentContextPointers->R10 = &pContext->R10;
    pRD->pCurrentContextPointers->R11 = &pContext->R11;
    pRD->pCurrentContextPointers->R12 = &pContext->R12;
    pRD->pCurrentContextPointers->R13 = &pContext->R13;
    pRD->pCurrentContextPointers->R14 = &pContext->R14;
    pRD->pCurrentContextPointers->R15 = &pContext->R15;

    pRD->IsCallerContextValid = FALSE;