Skip to content

Commit b212ef0

Browse files
authored
Correctly restore floating point context on x86 interop step-in scenarios (#117632)
* Correctly restore floating point context on x86 interop step-in scenarios * Update DAC Hijack context assert for cross-plat * Exclude XStateFeaturesMask in assert outside of amd64 and arm64
1 parent 02b1214 commit b212ef0

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

src/coreclr/debug/daccess/dacdbiimpl.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4963,9 +4963,21 @@ void DacDbiInterfaceImpl::Hijack(
49634963
// Setup context for hijack
49644964
//
49654965
T_CONTEXT ctx;
4966+
#if !defined(CROSS_COMPILE) && !defined(TARGET_WINDOWS) && (defined(DTCONTEXT_IS_AMD64) || defined(DTCONTEXT_IS_ARM64))
4967+
// If the host or target is not Windows, then we can assume that the DT_CONTEXT
4968+
// is the same as the T_CONTEXT, except for the XSTATE registers.
4969+
static_assert(sizeof(DT_CONTEXT) == offsetof(T_CONTEXT, XStateFeaturesMask), "DT_CONTEXT does not include the XSTATE registers");
4970+
#else
4971+
// Since Dac + DBI are tightly coupled, context sizes should be the same.
4972+
static_assert(sizeof(DT_CONTEXT) == sizeof(T_CONTEXT), "DT_CONTEXT size must equal the T_CONTEXT size");
4973+
#endif
49664974
HRESULT hr = m_pTarget->GetThreadContext(
49674975
dwThreadId,
4968-
CONTEXT_FULL,
4976+
CONTEXT_FULL | CONTEXT_FLOATING_POINT
4977+
#ifdef CONTEXT_EXTENDED_REGISTERS
4978+
| CONTEXT_EXTENDED_REGISTERS
4979+
#endif
4980+
,
49694981
sizeof(DT_CONTEXT),
49704982
(BYTE*) &ctx);
49714983
IfFailThrow(hr);

src/coreclr/debug/di/process.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13281,9 +13281,9 @@ void CordbProcess::HandleDebugEventForInteropDebugging(const DEBUG_EVENT * pEven
1328113281
LOG((LF_CORDB, LL_INFO100000, "W32ET::W32EL: hijack complete will restore context...\n"));
1328213282
DT_CONTEXT tempContext = { 0 };
1328313283
#if defined(DT_CONTEXT_EXTENDED_REGISTERS)
13284-
tempContext.ContextFlags = DT_CONTEXT_FULL | DT_CONTEXT_EXTENDED_REGISTERS;
13284+
tempContext.ContextFlags = DT_CONTEXT_FULL | DT_CONTEXT_FLOATING_POINT | DT_CONTEXT_EXTENDED_REGISTERS;
1328513285
#else
13286-
tempContext.ContextFlags = DT_CONTEXT_FULL;
13286+
tempContext.ContextFlags = DT_CONTEXT_FULL | DT_CONTEXT_FLOATING_POINT;
1328713287
#endif
1328813288
HRESULT hr = pUnmanagedThread->GetThreadContext(&tempContext);
1328913289
_ASSERTE(SUCCEEDED(hr));

src/coreclr/debug/di/rsthread.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3706,9 +3706,9 @@ HRESULT CordbUnmanagedThread::SetupFirstChanceHijackForSync()
37063706
// to avoid getting incomplete information and corrupt the thread context
37073707
DT_CONTEXT context;
37083708
#if defined(DT_CONTEXT_EXTENDED_REGISTERS)
3709-
context.ContextFlags = DT_CONTEXT_FULL | DT_CONTEXT_EXTENDED_REGISTERS;
3709+
context.ContextFlags = DT_CONTEXT_FULL | DT_CONTEXT_FLOATING_POINT | DT_CONTEXT_EXTENDED_REGISTERS;
37103710
#else
3711-
context.ContextFlags = DT_CONTEXT_FULL;
3711+
context.ContextFlags = DT_CONTEXT_FULL | DT_CONTEXT_FLOATING_POINT;
37123712
#endif
37133713
BOOL succ = DbiGetThreadContext(m_handle, &context);
37143714
_ASSERTE(succ);
@@ -3719,9 +3719,9 @@ HRESULT CordbUnmanagedThread::SetupFirstChanceHijackForSync()
37193719
LOG((LF_CORDB, LL_ERROR, "CUT::SFCHFS: DbiGetThreadContext error=0x%x\n", error));
37203720
}
37213721
#if defined(DT_CONTEXT_EXTENDED_REGISTERS)
3722-
GetHijackCtx()->ContextFlags = DT_CONTEXT_FULL | DT_CONTEXT_EXTENDED_REGISTERS;
3722+
GetHijackCtx()->ContextFlags = DT_CONTEXT_FULL | DT_CONTEXT_FLOATING_POINT | DT_CONTEXT_EXTENDED_REGISTERS;
37233723
#else
3724-
GetHijackCtx()->ContextFlags = DT_CONTEXT_FULL;
3724+
GetHijackCtx()->ContextFlags = DT_CONTEXT_FULL | DT_CONTEXT_FLOATING_POINT;
37253725
#endif
37263726
CORDbgCopyThreadContext(GetHijackCtx(), &context);
37273727
LOG((LF_CORDB, LL_INFO10000, "CUT::SFCHFS: thread=0x%x Hijacking for sync. Original context is:\n", this));

src/coreclr/debug/inc/dbgtargetcontext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ typedef DECLSPEC_ALIGN(16) struct {
474474

475475

476476
#if !defined(CROSS_COMPILE) && !defined(TARGET_WINDOWS)
477-
static_assert(sizeof(DT_CONTEXT) == offsetof(T_CONTEXT, XStateFeaturesMask), "DT_CONTEXT must not include the SVE registers on AMD64");
477+
static_assert(sizeof(DT_CONTEXT) == offsetof(T_CONTEXT, XStateFeaturesMask), "DT_CONTEXT must not include the SVE registers on ARM64");
478478
#else
479479
static_assert(sizeof(DT_CONTEXT) == sizeof(T_CONTEXT), "DT_CONTEXT size must equal the T_CONTEXT size on ARM64");
480480
#endif

0 commit comments

Comments
 (0)