Skip to content
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
4 changes: 4 additions & 0 deletions src/coreclr/debug/di/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13317,7 +13317,11 @@ void CordbProcess::HandleDebugEventForInteropDebugging(const DEBUG_EVENT * pEven
{
LOG((LF_CORDB, LL_INFO100000, "W32ET::W32EL: hijack complete will restore context...\n"));
DT_CONTEXT tempContext = { 0 };
#if defined(DT_CONTEXT_EXTENDED_REGISTERS)
tempContext.ContextFlags = DT_CONTEXT_FULL | DT_CONTEXT_EXTENDED_REGISTERS;
#else
tempContext.ContextFlags = DT_CONTEXT_FULL;
#endif
HRESULT hr = pUnmanagedThread->GetThreadContext(&tempContext);
_ASSERTE(SUCCEEDED(hr));

Expand Down
12 changes: 10 additions & 2 deletions src/coreclr/debug/di/rsthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3721,9 +3721,14 @@ HRESULT CordbUnmanagedThread::SetupFirstChanceHijackForSync()
LOG((LF_CORDB, LL_INFO10000, "CUT::SFCHFS: hijackCtx started as:\n"));
LogContext(GetHijackCtx());

// Save the thread's full context.
// Save the thread's full context + DT_CONTEXT_EXTENDED_REGISTERS
// to avoid getting incomplete information and corrupt the thread context
DT_CONTEXT context;
#if defined(DT_CONTEXT_EXTENDED_REGISTERS)
context.ContextFlags = DT_CONTEXT_FULL | DT_CONTEXT_EXTENDED_REGISTERS;
#else
context.ContextFlags = DT_CONTEXT_FULL;
#endif
BOOL succ = DbiGetThreadContext(m_handle, &context);
_ASSERTE(succ);
// for debugging when GetThreadContext fails
Expand All @@ -3732,8 +3737,11 @@ HRESULT CordbUnmanagedThread::SetupFirstChanceHijackForSync()
DWORD error = GetLastError();
LOG((LF_CORDB, LL_ERROR, "CUT::SFCHFS: DbiGetThreadContext error=0x%x\n", error));
}

#if defined(DT_CONTEXT_EXTENDED_REGISTERS)
GetHijackCtx()->ContextFlags = DT_CONTEXT_FULL | DT_CONTEXT_EXTENDED_REGISTERS;
#else
GetHijackCtx()->ContextFlags = DT_CONTEXT_FULL;
#endif
CORDbgCopyThreadContext(GetHijackCtx(), &context);
LOG((LF_CORDB, LL_INFO10000, "CUT::SFCHFS: thread=0x%x Hijacking for sync. Original context is:\n", this));
LogContext(GetHijackCtx());
Expand Down
Loading