[arm64] Scan simd registers on apple
authorVlad Brezae <brezaevlad@gmail.com>
Mon, 25 Sep 2017 23:30:33 +0000 (02:30 +0300)
committerVlad Brezae <brezaevlad@gmail.com>
Wed, 27 Sep 2017 18:30:42 +0000 (21:30 +0300)
Fix for #50190

mono/utils/mach-support-arm64.c
mono/utils/mono-context.h

index 5033eb19d66807abf1b506ce51700085d5858517..33c076974114e42346192fd12c7ed6503408e3d5 100644 (file)
@@ -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 *
index 290f24f115cb8ef7a412716205b0515e4d846779..367449edd8f7e0c36d94a9520661e742cbf9edff 100644 (file)
@@ -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);