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

Commit a586896

Browse files
committed
Fix Up ResumeEsp inside ProcessCLRException
1 parent 25637dd commit a586896

File tree

4 files changed

+30
-21
lines changed

4 files changed

+30
-21
lines changed

src/inc/eetwain.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ HRESULT FixContextForEnC(PCONTEXT pCtx,
653653
static void EnsureCallerContextIsValid( PREGDISPLAY pRD, StackwalkCacheEntry* pCacheEntry, EECodeInfo * pCodeInfo = NULL );
654654
static size_t GetCallerSp( PREGDISPLAY pRD );
655655
#ifdef _TARGET_X86_
656-
static size_t GetResumeSp( PREGDISPLAY pRD );
656+
static size_t GetResumeSp( PCONTEXT pContext );
657657
#endif // _TARGET_X86_
658658
#endif // WIN64EXCEPTIONS
659659

src/vm/eetwain.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4035,9 +4035,13 @@ bool UnwindStackFrame(PREGDISPLAY pContext,
40354035

40364036
#ifdef WIN64EXCEPTIONS
40374037
#ifdef _TARGET_X86_
4038-
size_t EECodeManager::GetResumeSp( PREGDISPLAY pRD )
4038+
size_t EECodeManager::GetResumeSp( PCONTEXT pContext )
40394039
{
4040-
EECodeInfo codeInfo(pRD->ControlPC);
4040+
PCODE currentPc = PCODE(pContext->Eip);
4041+
4042+
_ASSERTE(ExecutionManager::IsManagedCode(currentPc));
4043+
4044+
EECodeInfo codeInfo(currentPc);
40414045

40424046
PTR_CBYTE methodStart = PTR_CBYTE(codeInfo.GetSavedMethodCode());
40434047

@@ -4067,11 +4071,11 @@ size_t EECodeManager::GetResumeSp( PREGDISPLAY pRD )
40674071

40684072
if (isESPFrame)
40694073
{
4070-
const size_t curESP = pRD->SP;
4074+
const size_t curESP = (size_t)(pContext->Esp);
40714075
return curESP + GetPushedArgSize(info, table, curOffs);
40724076
}
40734077

4074-
const size_t curEBP = *pRD->GetEbpLocation();
4078+
const size_t curEBP = (size_t)(pContext->Ebp);
40754079
return GetOutermostBaseFP(curEBP, info);
40764080
}
40774081
#endif // _TARGET_X86_

src/vm/exceptionhandling.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,24 @@ bool FixNonvolatileRegisters(UINT_PTR uOriginalSP,
123123
bool fAborting
124124
);
125125

126+
void FixContext(PCONTEXT *pContextRecord)
127+
{
128+
#define FIXUPREG(reg, value) \
129+
do { \
130+
STRESS_LOG2(LF_GCROOTS, LL_INFO100, "Updating " #reg " %p to %p\n", \
131+
pContextRecord->reg, \
132+
(value)); \
133+
pContextRecord->reg = (value); \
134+
} while (0)
135+
136+
#ifdef _TARGET_X86_
137+
size_t resumeSp = EECodeManager::GetResumeSp(pContextRecord);
138+
FIXUPREG(ResumeEsp, resumeSp);
139+
#endif // _TARGET_X86_
140+
141+
#undef FIXUPREG
142+
}
143+
126144
MethodDesc * GetUserMethodForILStub(Thread * pThread, UINT_PTR uStubSP, MethodDesc * pILStubMD, Frame ** ppFrameOut);
127145

128146
#ifdef FEATURE_PAL
@@ -441,14 +459,6 @@ void ExceptionTracker::UpdateNonvolatileRegisters(CONTEXT *pContextRecord, REGDI
441459
} \
442460
} while (0)
443461

444-
#define UPDATEREG_VAL(reg) \
445-
do { \
446-
STRESS_LOG2(LF_GCROOTS, LL_INFO100, "Updating " #reg " %p to %p\n", \
447-
pContextRecord->reg, \
448-
pRegDisplay->pCurrentContext->reg); \
449-
pContextRecord->reg = pRegDisplay->pCurrentContext->reg; \
450-
} while (0)
451-
452462

453463
#if defined(_TARGET_X86_)
454464

@@ -457,8 +467,6 @@ void ExceptionTracker::UpdateNonvolatileRegisters(CONTEXT *pContextRecord, REGDI
457467
UPDATEREG(Edi);
458468
UPDATEREG(Ebp);
459469

460-
UPDATEREG_VAL(ResumeEsp);
461-
462470
#elif defined(_TARGET_AMD64_)
463471

464472
UPDATEREG(Rbx);
@@ -1195,6 +1203,8 @@ ProcessCLRException(IN PEXCEPTION_RECORD pExceptionRecord
11951203
SetIP(pContextRecord, (PCODE)uResumePC);
11961204
}
11971205

1206+
FixContext(pContextRecord);
1207+
11981208
#ifdef STACK_GUARDS_DEBUG
11991209
// We are transitioning back to managed code, so ensure that we are in
12001210
// SO-tolerant mode before we do so.

src/vm/i386/cgenx86.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ void HelperMethodFrame::UpdateRegDisplay(const PREGDISPLAY pRD)
384384
#endif // DACCESS_COMPILE
385385

386386
pRD->pCurrentContext->Eip = pRD->ControlPC = m_MachState.GetRetAddr();
387-
pRD->pCurrentContext->Esp = pRD->SP = (DWORD) m_MachState.esp();
387+
pRD->pCurrentContext->Esp = pRD->pCurrentContext->ResumeEsp = pRD->SP = (DWORD) m_MachState.esp();
388388

389389
#define CALLEE_SAVED_REGISTER(regname) pRD->pCurrentContext->regname = *((DWORD*) m_MachState.p##regname());
390390
ENUM_CALLEE_SAVED_REGISTERS();
@@ -402,11 +402,6 @@ void HelperMethodFrame::UpdateRegDisplay(const PREGDISPLAY pRD)
402402

403403
ClearRegDisplayArgumentAndScratchRegisters(pRD);
404404

405-
//
406-
// Fix up ResumeSp
407-
//
408-
pRD->pCurrentContext->ResumeEsp = EECodeManager::GetResumeSp(pRD);
409-
410405
#else // WIN64EXCEPTIONS
411406

412407
// reset pContext; it's only valid for active (top-most) frame

0 commit comments

Comments
 (0)