From c9edbb3e02719b8c080798f331f0e41f9cbfd207 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 16 Jul 2024 00:40:57 +0200 Subject: [PATCH] [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 Co-authored-by: Mikelle Co-authored-by: Jan Vorlicek --- .../pal/src/exception/machexception.cpp | 21 +++++++++++++------ src/coreclr/pal/src/exception/machmessage.h | 2 +- src/coreclr/pal/src/thread/context.cpp | 12 +++++++++++ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/coreclr/pal/src/exception/machexception.cpp b/src/coreclr/pal/src/exception/machexception.cpp index 50db83248fe7a..3ac06bcde18af 100644 --- a/src/coreclr/pal/src/exception/machexception.cpp +++ b/src/coreclr/pal/src/exception/machexception.cpp @@ -681,8 +681,8 @@ HijackFaultingThread( BuildExceptionRecord(exceptionInfo, &exceptionRecord); #if defined(HOST_AMD64) - threadContext.ContextFlags = CONTEXT_FLOATING_POINT; - CONTEXT_GetThreadContextFromThreadState(x86_FLOAT_STATE, (thread_state_t)&exceptionInfo.FloatState, &threadContext); + threadContext.ContextFlags = CONTEXT_FLOATING_POINT | CONTEXT_XSTATE; + CONTEXT_GetThreadContextFromThreadState(x86_AVX512_STATE, (thread_state_t)&exceptionInfo.FloatState, &threadContext); threadContext.ContextFlags |= CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS; CONTEXT_GetThreadContextFromThreadState(x86_THREAD_STATE, (thread_state_t)&exceptionInfo.ThreadState, &threadContext); @@ -1265,10 +1265,19 @@ MachExceptionInfo::MachExceptionInfo(mach_port_t thread, MachMessage& message) machret = thread_get_state(thread, x86_THREAD_STATE, (thread_state_t)&ThreadState, &count); CHECK_MACH("thread_get_state", machret); - count = x86_FLOAT_STATE_COUNT; - machret = thread_get_state(thread, x86_FLOAT_STATE, (thread_state_t)&FloatState, &count); - CHECK_MACH("thread_get_state(float)", machret); - + count = x86_AVX512_STATE_COUNT; + machret = thread_get_state(thread, x86_AVX512_STATE, (thread_state_t)&FloatState, &count); + if (machret != KERN_SUCCESS) + { + count = x86_AVX_STATE_COUNT; + machret = thread_get_state(thread, x86_AVX_STATE, (thread_state_t)&FloatState, &count); + if (machret != KERN_SUCCESS) + { + count = x86_FLOAT_STATE_COUNT; + machret = thread_get_state(thread, x86_FLOAT_STATE, (thread_state_t)&FloatState, &count); + CHECK_MACH("thread_get_state(float)", machret); + } + } count = x86_DEBUG_STATE_COUNT; machret = thread_get_state(thread, x86_DEBUG_STATE, (thread_state_t)&DebugState, &count); CHECK_MACH("thread_get_state(debug)", machret); diff --git a/src/coreclr/pal/src/exception/machmessage.h b/src/coreclr/pal/src/exception/machmessage.h index 4245d2b6fb0c6..194f066dce4cd 100644 --- a/src/coreclr/pal/src/exception/machmessage.h +++ b/src/coreclr/pal/src/exception/machmessage.h @@ -84,7 +84,7 @@ struct MachExceptionInfo mach_exception_data_type_t Subcodes[2]; #if defined(HOST_AMD64) x86_thread_state_t ThreadState; - x86_float_state_t FloatState; + x86_avx512_state_t FloatState; x86_debug_state_t DebugState; #elif defined(HOST_ARM64) arm_thread_state64_t ThreadState; diff --git a/src/coreclr/pal/src/thread/context.cpp b/src/coreclr/pal/src/thread/context.cpp index a9ed8c269a89c..b7e7c6fab35f0 100644 --- a/src/coreclr/pal/src/thread/context.cpp +++ b/src/coreclr/pal/src/thread/context.cpp @@ -1513,6 +1513,18 @@ CONTEXT_GetThreadContextFromThreadState( CONTEXT_GetThreadContextFromThreadState((thread_state_flavor_t)pState->fsh.flavor, (thread_state_t)&pState->ufs, lpContext); } break; + case x86_AVX_STATE: + { + x86_avx_state_t *pState = (x86_avx_state_t *)threadState; + CONTEXT_GetThreadContextFromThreadState((thread_state_flavor_t)pState->ash.flavor, (thread_state_t)&pState->ufs, lpContext); + } + break; + case x86_AVX512_STATE: + { + x86_avx512_state_t *pState = (x86_avx512_state_t *)threadState; + CONTEXT_GetThreadContextFromThreadState((thread_state_flavor_t)pState->ash.flavor, (thread_state_t)&pState->ufs, lpContext); + } + break; #elif defined(HOST_ARM64) case ARM_THREAD_STATE64: if (lpContext->ContextFlags & (CONTEXT_CONTROL | CONTEXT_INTEGER) & CONTEXT_AREA_MASK)