Skip to content

Commit c9edbb3

Browse files
github-actions[bot]Diagmikelle-rogersjanvorli
authored
[release/8.0-staging] Get ThreadContext for AVX registers (#104818)
* some logs * debugging the adventure * using the XSTATE_SUPPORTED macro * use minipal getcpufeatures * add conditional in MachExceptionInfo constructor * fix whitespace and remove logs * whitepace * remove conditional checks and rely on Fallthrough * remove uneeded dependencies * Remove logging that should not be there --------- Co-authored-by: Diag <[email protected]> Co-authored-by: Mikelle <[email protected]> Co-authored-by: Jan Vorlicek <[email protected]>
1 parent cb3d70f commit c9edbb3

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

src/coreclr/pal/src/exception/machexception.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,8 @@ HijackFaultingThread(
681681
BuildExceptionRecord(exceptionInfo, &exceptionRecord);
682682

683683
#if defined(HOST_AMD64)
684-
threadContext.ContextFlags = CONTEXT_FLOATING_POINT;
685-
CONTEXT_GetThreadContextFromThreadState(x86_FLOAT_STATE, (thread_state_t)&exceptionInfo.FloatState, &threadContext);
684+
threadContext.ContextFlags = CONTEXT_FLOATING_POINT | CONTEXT_XSTATE;
685+
CONTEXT_GetThreadContextFromThreadState(x86_AVX512_STATE, (thread_state_t)&exceptionInfo.FloatState, &threadContext);
686686

687687
threadContext.ContextFlags |= CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS;
688688
CONTEXT_GetThreadContextFromThreadState(x86_THREAD_STATE, (thread_state_t)&exceptionInfo.ThreadState, &threadContext);
@@ -1265,10 +1265,19 @@ MachExceptionInfo::MachExceptionInfo(mach_port_t thread, MachMessage& message)
12651265
machret = thread_get_state(thread, x86_THREAD_STATE, (thread_state_t)&ThreadState, &count);
12661266
CHECK_MACH("thread_get_state", machret);
12671267

1268-
count = x86_FLOAT_STATE_COUNT;
1269-
machret = thread_get_state(thread, x86_FLOAT_STATE, (thread_state_t)&FloatState, &count);
1270-
CHECK_MACH("thread_get_state(float)", machret);
1271-
1268+
count = x86_AVX512_STATE_COUNT;
1269+
machret = thread_get_state(thread, x86_AVX512_STATE, (thread_state_t)&FloatState, &count);
1270+
if (machret != KERN_SUCCESS)
1271+
{
1272+
count = x86_AVX_STATE_COUNT;
1273+
machret = thread_get_state(thread, x86_AVX_STATE, (thread_state_t)&FloatState, &count);
1274+
if (machret != KERN_SUCCESS)
1275+
{
1276+
count = x86_FLOAT_STATE_COUNT;
1277+
machret = thread_get_state(thread, x86_FLOAT_STATE, (thread_state_t)&FloatState, &count);
1278+
CHECK_MACH("thread_get_state(float)", machret);
1279+
}
1280+
}
12721281
count = x86_DEBUG_STATE_COUNT;
12731282
machret = thread_get_state(thread, x86_DEBUG_STATE, (thread_state_t)&DebugState, &count);
12741283
CHECK_MACH("thread_get_state(debug)", machret);

src/coreclr/pal/src/exception/machmessage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ struct MachExceptionInfo
8484
mach_exception_data_type_t Subcodes[2];
8585
#if defined(HOST_AMD64)
8686
x86_thread_state_t ThreadState;
87-
x86_float_state_t FloatState;
87+
x86_avx512_state_t FloatState;
8888
x86_debug_state_t DebugState;
8989
#elif defined(HOST_ARM64)
9090
arm_thread_state64_t ThreadState;

src/coreclr/pal/src/thread/context.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,6 +1513,18 @@ CONTEXT_GetThreadContextFromThreadState(
15131513
CONTEXT_GetThreadContextFromThreadState((thread_state_flavor_t)pState->fsh.flavor, (thread_state_t)&pState->ufs, lpContext);
15141514
}
15151515
break;
1516+
case x86_AVX_STATE:
1517+
{
1518+
x86_avx_state_t *pState = (x86_avx_state_t *)threadState;
1519+
CONTEXT_GetThreadContextFromThreadState((thread_state_flavor_t)pState->ash.flavor, (thread_state_t)&pState->ufs, lpContext);
1520+
}
1521+
break;
1522+
case x86_AVX512_STATE:
1523+
{
1524+
x86_avx512_state_t *pState = (x86_avx512_state_t *)threadState;
1525+
CONTEXT_GetThreadContextFromThreadState((thread_state_flavor_t)pState->ash.flavor, (thread_state_t)&pState->ufs, lpContext);
1526+
}
1527+
break;
15161528
#elif defined(HOST_ARM64)
15171529
case ARM_THREAD_STATE64:
15181530
if (lpContext->ContextFlags & (CONTEXT_CONTROL | CONTEXT_INTEGER) & CONTEXT_AREA_MASK)

0 commit comments

Comments
 (0)