Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

[x86/Linux] Do NOT use pXXX fields #9121

Merged
merged 16 commits into from
Feb 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/debug/daccess/dacdbiimplstackwalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1156,13 +1156,13 @@ void DacDbiInterfaceImpl::UpdateContextFromRegDisp(REGDISPLAY * pRegDisp,
// Do a partial copy first.
pContext->ContextFlags = (CONTEXT_INTEGER | CONTEXT_CONTROL);

pContext->Edi = *pRegDisp->pEdi;
pContext->Esi = *pRegDisp->pEsi;
pContext->Ebx = *pRegDisp->pEbx;
pContext->Ebp = *pRegDisp->pEbp;
pContext->Eax = *pRegDisp->pEax;
pContext->Ecx = *pRegDisp->pEcx;
pContext->Edx = *pRegDisp->pEdx;
pContext->Edi = *pRegDisp->GetEdiLocation();
pContext->Esi = *pRegDisp->GetEsiLocation();
pContext->Ebx = *pRegDisp->GetEbxLocation();
pContext->Ebp = *pRegDisp->GetEbpLocation();
pContext->Eax = *pRegDisp->GetEaxLocation();
pContext->Ecx = *pRegDisp->GetEcxLocation();
pContext->Edx = *pRegDisp->GetEdxLocation();
pContext->Esp = pRegDisp->SP;
pContext->Eip = pRegDisp->ControlPC;

Expand Down
14 changes: 7 additions & 7 deletions src/debug/ee/debugger.inl
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,13 @@ inline void FuncEvalFrame::UpdateRegDisplay(const PREGDISPLAY pRD)
// Update all registers in the reg display from the CONTEXT we stored when the thread was hijacked for this func
// eval. We have to update all registers, not just the callee saved registers, because we can hijack a thread at any
// point for a func eval, not just at a call site.
pRD->pEdi = &(pDE->m_context.Edi);
pRD->pEsi = &(pDE->m_context.Esi);
pRD->pEbx = &(pDE->m_context.Ebx);
pRD->pEdx = &(pDE->m_context.Edx);
pRD->pEcx = &(pDE->m_context.Ecx);
pRD->pEax = &(pDE->m_context.Eax);
pRD->pEbp = &(pDE->m_context.Ebp);
pRD->SetEdiLocation(&(pDE->m_context.Edi));
pRD->SetEsiLocation(&(pDE->m_context.Esi));
pRD->SetEbxLocation(&(pDE->m_context.Ebx));
pRD->SetEdxLocation(&(pDE->m_context.Edx));
pRD->SetEcxLocation(&(pDE->m_context.Ecx));
pRD->SetEaxLocation(&(pDE->m_context.Eax));
pRD->SetEbpLocation(&(pDE->m_context.Ebp));
pRD->SP = (DWORD)GetSP(&pDE->m_context);
pRD->PCTAddr = GetReturnAddressPtr();
pRD->ControlPC = *PTR_PCODE(pRD->PCTAddr);
Expand Down
14 changes: 7 additions & 7 deletions src/debug/ee/i386/x86walker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,28 +292,28 @@ DWORD NativeWalker::GetRegisterValue(int registerNumber)
switch (registerNumber)
{
case 0:
return *m_registers->pEax;
return *m_registers->GetEaxLocation();
break;
case 1:
return *m_registers->pEcx;
return *m_registers->GetEcxLocation();
break;
case 2:
return *m_registers->pEdx;
return *m_registers->GetEdxLocation();
break;
case 3:
return *m_registers->pEbx;
return *m_registers->GetEbxLocation();
break;
case 4:
return m_registers->SP;
break;
case 5:
return *m_registers->pEbp;
return *m_registers->GetEbpLocation();
break;
case 6:
return *m_registers->pEsi;
return *m_registers->GetEsiLocation();
break;
case 7:
return *m_registers->pEdi;
return *m_registers->GetEdiLocation();
break;
default:
_ASSERTE(!"Invalid register number!");
Expand Down
12 changes: 6 additions & 6 deletions src/debug/shared/i386/primitives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ void SetDebuggerREGDISPLAYFromREGDISPLAY(DebuggerREGDISPLAY* pDRD, REGDISPLAY* p
// Frame pointer
LPVOID FPAddress = GetRegdisplayFPAddress(pRD);
pDRD->FP = (FPAddress == NULL ? 0 : *((SIZE_T *)FPAddress));
pDRD->Edi = (pRD->pEdi == NULL ? 0 : *(pRD->pEdi));
pDRD->Esi = (pRD->pEsi == NULL ? 0 : *(pRD->pEsi));
pDRD->Ebx = (pRD->pEbx == NULL ? 0 : *(pRD->pEbx));
pDRD->Edx = (pRD->pEdx == NULL ? 0 : *(pRD->pEdx));
pDRD->Ecx = (pRD->pEcx == NULL ? 0 : *(pRD->pEcx));
pDRD->Eax = (pRD->pEax == NULL ? 0 : *(pRD->pEax));
pDRD->Edi = (pRD->GetEdiLocation() == NULL ? 0 : *pRD->GetEdiLocation());
pDRD->Esi = (pRD->GetEsiLocation() == NULL ? 0 : *pRD->GetEsiLocation());
pDRD->Ebx = (pRD->GetEbxLocation() == NULL ? 0 : *pRD->GetEbxLocation());
pDRD->Edx = (pRD->GetEdxLocation() == NULL ? 0 : *pRD->GetEdxLocation());
pDRD->Ecx = (pRD->GetEcxLocation() == NULL ? 0 : *pRD->GetEcxLocation());
pDRD->Eax = (pRD->GetEsiLocation() == NULL ? 0 : *pRD->GetEaxLocation());

#if defined(USE_REMOTE_REGISTER_ADDRESS)
pDRD->pFP = PushedRegAddr(pRD, FPAddress);
Expand Down
40 changes: 33 additions & 7 deletions src/inc/regdisp.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ struct REGDISPLAY : public REGDISPLAY_BASE {
PCONTEXT pContextForUnwind; // scratch context for unwinding
// used to preserve context saved in the frame that
// could be otherwise wiped by the unwinding
#endif // !WIN64EXCEPTIONS

DWORD * pEdi;
DWORD * pEsi;
Expand All @@ -72,6 +71,33 @@ struct REGDISPLAY : public REGDISPLAY_BASE {
DWORD * pEax;

DWORD * pEbp;
#endif // !WIN64EXCEPTIONS

#ifndef WIN64EXCEPTIONS

#define REG_METHODS(reg) \
inline PDWORD Get##reg##Location(void) { return p##reg; } \
inline void Set##reg##Location(PDWORD p##reg) { this->p##reg = p##reg; }

#else // !WIN64EXCEPTIONS

#define REG_METHODS(reg) \
inline PDWORD Get##reg##Location(void) { return pCurrentContextPointers->reg; } \
inline void Set##reg##Location(PDWORD p##reg) { pCurrentContextPointers->reg = p##reg; }

#endif // WIN64EXCEPTIONS

REG_METHODS(Eax)
REG_METHODS(Ecx)
REG_METHODS(Edx)

REG_METHODS(Ebx)
REG_METHODS(Esi)
REG_METHODS(Edi)
REG_METHODS(Ebp)

#undef REG_METHODS

TADDR PCTAddr;
};

Expand All @@ -90,13 +116,13 @@ inline void SetRegdisplaySP(REGDISPLAY *display, LPVOID sp ) {
inline TADDR GetRegdisplayFP(REGDISPLAY *display) {
LIMITED_METHOD_DAC_CONTRACT;

return (TADDR)*(display->pEbp);
return (TADDR)*display->GetEbpLocation();
}

inline LPVOID GetRegdisplayFPAddress(REGDISPLAY *display) {
LIMITED_METHOD_CONTRACT;

return (LPVOID)display->pEbp;
return (LPVOID)display->GetEbpLocation();
}

inline PCODE GetControlPC(REGDISPLAY *display) {
Expand Down Expand Up @@ -393,10 +419,10 @@ inline void FillRegDisplay(const PREGDISPLAY pRD, PT_CONTEXT pctx, PT_CONTEXT pC

pRD->ctxPtrsOne.Lr = &pctx->Lr;
#elif defined(_TARGET_X86_) // _TARGET_ARM_
pRD->ctxPtrsOne.Ebx = &pctx->Ebx;
pRD->ctxPtrsOne.Esi = &pctx->Esi;
pRD->ctxPtrsOne.Edi = &pctx->Edi;
pRD->ctxPtrsOne.Ebp = &pctx->Ebp;
for (int i = 0; i < 7; i++)
{
*(&pRD->ctxPtrsOne.Esi + i) = (&pctx->Esi + i);
}
#else // _TARGET_X86_
PORTABILITY_ASSERT("FillRegDisplay");
#endif // _TARGET_???_ (ELSE)
Expand Down
13 changes: 10 additions & 3 deletions src/pal/inc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1795,10 +1795,17 @@ typedef struct _CONTEXT {

typedef struct _KNONVOLATILE_CONTEXT_POINTERS {

// TODO WIP x86/Linux, need to fix this.
PDWORD Ebx;
PDWORD Esi;
// The ordering of these fields should be aligned with that
// of corresponding fields in CONTEXT
//
// (See FillRegDisplay in inc/regdisp.h for details)
PDWORD Edi;
PDWORD Esi;
PDWORD Ebx;
PDWORD Edx;
PDWORD Ecx;
PDWORD Eax;

PDWORD Ebp;

} KNONVOLATILE_CONTEXT_POINTERS, *PKNONVOLATILE_CONTEXT_POINTERS;
Expand Down
40 changes: 12 additions & 28 deletions src/unwinder/i386/unwinder_i386.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,26 +75,14 @@ OOPStackUnwinderX86::VirtualUnwind(

REGDISPLAY rd;

if (ContextPointers != NULL)
{
#define CALLEE_SAVED_REGISTER(reg) rd.p##reg = ContextPointers->reg;
ENUM_CALLEE_SAVED_REGISTERS();
#undef CALLEE_SAVED_REGISTER
}
else
{
#define CALLEE_SAVED_REGISTER(reg) rd.p##reg = NULL;
ENUM_CALLEE_SAVED_REGISTERS();
#undef CALLEE_SAVED_REGISTER
}
FillRegDisplay(&rd, ContextRecord);

rd.PCTAddr = (UINT_PTR)&(ContextRecord->Eip);

if (rd.pEbp == NULL)
if (ContextPointers)
{
rd.pEbp = &(ContextRecord->Ebp);
rd.pCurrentContextPointers = ContextPointers;
}
rd.SP = ContextRecord->Esp;
rd.ControlPC = (PCODE)(ContextRecord->Eip);
rd.PCTAddr = (UINT_PTR)&(ContextRecord->Eip);

CodeManState codeManState;
codeManState.dwIsSet = 0;
Expand All @@ -107,22 +95,18 @@ OOPStackUnwinderX86::VirtualUnwind(
return HRESULT_FROM_WIN32(ERROR_READ_FAULT);
}

#define CALLEE_SAVED_REGISTER(reg) if (rd.p##reg != NULL) { ContextRecord->reg = *rd.p##reg; }
ContextRecord->ContextFlags |= CONTEXT_UNWOUND_TO_CALL;

#define ARGUMENT_AND_SCRATCH_REGISTER(reg) if (rd.pCurrentContextPointers->reg) ContextRecord->reg = *rd.pCurrentContextPointers->reg;
ENUM_ARGUMENT_AND_SCRATCH_REGISTERS();
#undef ARGUMENT_AND_SCRATCH_REGISTER

#define CALLEE_SAVED_REGISTER(reg) if (rd.pCurrentContextPointers->reg) ContextRecord->reg = *rd.pCurrentContextPointers->reg;
ENUM_CALLEE_SAVED_REGISTERS();
#undef CALLEE_SAVED_REGISTER

if (ContextPointers != NULL)
{
#define CALLEE_SAVED_REGISTER(reg) if (rd.p##reg != &(ContextRecord->reg)) { ContextPointers->reg = rd.p##reg; }
ENUM_CALLEE_SAVED_REGISTERS();
#undef CALLEE_SAVED_REGISTER
}

ContextRecord->ContextFlags |= CONTEXT_UNWOUND_TO_CALL;

ContextRecord->Esp = rd.SP;
ContextRecord->Eip = rd.ControlPC;
ContextRecord->Ebp = *rd.pEbp;

return S_OK;
}
Expand Down
Loading