From c334db5e2ced29fb03fe2be4b603bbacb91021f8 Mon Sep 17 00:00:00 2001 From: Vlad Brezae Date: Tue, 26 Sep 2017 02:30:33 +0300 Subject: [PATCH] [arm64] Scan simd registers on apple Fix for #50190 --- mono/utils/mach-support-arm64.c | 23 +++++++++++++++++++++-- mono/utils/mono-context.h | 7 ++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/mono/utils/mach-support-arm64.c b/mono/utils/mach-support-arm64.c index 5033eb19d66..33c07697411 100644 --- a/mono/utils/mach-support-arm64.c +++ b/mono/utils/mach-support-arm64.c @@ -70,18 +70,22 @@ void mono_mach_arch_thread_states_to_mcontext (thread_state_t state, thread_state_t fpstate, void *context) { arm_unified_thread_state_t *arch_state = (arm_unified_thread_state_t *) state; + arm_neon_state64_t *arch_fpstate = (arm_neon_state64_t*) fpstate; struct __darwin_mcontext64 *ctx = (struct __darwin_mcontext64 *) context; ctx->__ss = arch_state->ts_64; + ctx->__ns = *arch_fpstate; } void mono_mach_arch_mcontext_to_thread_states (void *context, thread_state_t state, thread_state_t fpstate) { arm_unified_thread_state_t *arch_state = (arm_unified_thread_state_t *) state; + arm_neon_state64_t *arch_fpstate = (arm_neon_state64_t*) fpstate; struct __darwin_mcontext64 *ctx = (struct __darwin_mcontext64 *) context; arch_state->ts_64 = ctx->__ss; + *arch_fpstate = ctx->__ns; } void @@ -89,6 +93,8 @@ mono_mach_arch_thread_states_to_mono_context (thread_state_t state, thread_state { int i; arm_unified_thread_state_t *arch_state = (arm_unified_thread_state_t *) state; + arm_neon_state64_t *arch_fpstate = (arm_neon_state64_t*) fpstate; + for (i = 0; i < 29; ++i) context->regs [i] = arch_state->ts_64.__x [i]; @@ -96,6 +102,9 @@ mono_mach_arch_thread_states_to_mono_context (thread_state_t state, thread_state context->regs [ARMREG_R30] = arch_state->ts_64.__lr; context->regs [ARMREG_SP] = arch_state->ts_64.__sp; context->pc = arch_state->ts_64.__pc; + + for (i = 0; i < 32; ++i) + context->fregs [i] = arch_fpstate->__v [i]; } int @@ -114,18 +123,28 @@ kern_return_t mono_mach_arch_get_thread_states (thread_port_t thread, thread_state_t state, mach_msg_type_number_t *count, thread_state_t fpstate, mach_msg_type_number_t *fpcount) { arm_unified_thread_state_t *arch_state = (arm_unified_thread_state_t *) state; + arm_neon_state64_t *arch_fpstate = (arm_neon_state64_t *) fpstate; kern_return_t ret; *count = ARM_UNIFIED_THREAD_STATE_COUNT; - ret = thread_get_state (thread, ARM_UNIFIED_THREAD_STATE, (thread_state_t) arch_state, count); + if (ret != KERN_SUCCESS) + return ret; + + *fpcount = ARM_NEON_STATE64_COUNT; + ret = thread_get_state (thread, ARM_NEON_STATE64, (thread_state_t) arch_fpstate, fpcount); return ret; } kern_return_t mono_mach_arch_set_thread_states (thread_port_t thread, thread_state_t state, mach_msg_type_number_t count, thread_state_t fpstate, mach_msg_type_number_t fpcount) { - return thread_set_state (thread, ARM_UNIFIED_THREAD_STATE, state, count); + kern_return_t ret; + ret = thread_set_state (thread, ARM_UNIFIED_THREAD_STATE, state, count); + if (ret != KERN_SUCCESS) + return ret; + ret = thread_set_state (thread, ARM_NEON_STATE64, fpstate, fpcount); + return ret; } void * diff --git a/mono/utils/mono-context.h b/mono/utils/mono-context.h index 290f24f115c..367449edd8f 100644 --- a/mono/utils/mono-context.h +++ b/mono/utils/mono-context.h @@ -449,12 +449,17 @@ typedef struct { #define MONO_CONTEXT_GET_CURRENT(ctx) do { \ arm_unified_thread_state_t thread_state; \ + arm_neon_state64_t thread_fpstate; \ int state_flavor = ARM_UNIFIED_THREAD_STATE; \ + int fpstate_flavor = ARM_NEON_STATE64; \ unsigned state_count = ARM_UNIFIED_THREAD_STATE_COUNT; \ + unsigned fpstate_count = ARM_NEON_STATE64_COUNT; \ thread_port_t self = mach_thread_self (); \ kern_return_t ret = thread_get_state (self, state_flavor, (thread_state_t) &thread_state, &state_count); \ g_assert (ret == 0); \ - mono_mach_arch_thread_states_to_mono_context ((thread_state_t)&thread_state, (thread_state_t)NULL, &ctx); \ + ret = thread_get_state (self, fpstate_flavor, (thread_state_t) &thread_fpstate, &fpstate_count); \ + g_assert (ret == 0); \ + mono_mach_arch_thread_states_to_mono_context ((thread_state_t) &thread_state, (thread_state_t) &thread_fpstate, &ctx); \ mach_port_deallocate (current_task (), self); \ } while (0); -- 2.25.1