Skip to content

Commit 35932d9

Browse files
VSadovagocke
authored andcommitted
Use CopyContext to restore saved context on X86 (dotnet#65490)
* Use CopyContext to restore saved context on X86 * PR feedback * more PR feedback
1 parent 8a375ed commit 35932d9

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/coreclr/src/vm/threadsuspend.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2780,6 +2780,7 @@ void RedirectedThreadFrame::ExceptionUnwind()
27802780
#ifndef TARGET_UNIX
27812781

27822782
#ifdef TARGET_X86
2783+
27832784
//****************************************************************************************
27842785
// This will check who caused the exception. If it was caused by the the redirect function,
27852786
// the reason is to resume the thread back at the point it was redirected in the first
@@ -2850,7 +2851,15 @@ int RedirectedHandledJITCaseExceptionFilter(
28502851
pFrame->Pop();
28512852

28522853
// Copy the saved context record into the EH context;
2853-
ReplaceExceptionContextRecord(pExcepPtrs->ContextRecord, pCtx);
2854+
// NB: cannot use ReplaceExceptionContextRecord here.
2855+
// these contexts may contain extended registers and may have different format
2856+
// for reasons such as alignment or context compaction
2857+
CONTEXT* pTarget = pExcepPtrs->ContextRecord;
2858+
if (!CopyContext(pTarget, pTarget->ContextFlags, pCtx))
2859+
{
2860+
STRESS_LOG1(LF_SYNC, LL_ERROR, "ERROR: Could not set context record, lastError = 0x%x\n", GetLastError());
2861+
EEPOLICY_HANDLE_FATAL_ERROR(COR_E_EXECUTIONENGINE);
2862+
}
28542863

28552864
DWORD espValue = pCtx->Esp;
28562865

0 commit comments

Comments
 (0)