"Fossies" - the Fresh Open Source Software Archive

Member "mono-6.12.0.122/mono/utils/mach-support-amd64.c" (22 Feb 2021, 4724 Bytes) of package /linux/misc/mono-sources/mono/mono-6.12.0.122.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "mach-support-amd64.c": 6.12.0.107_vs_6.12.0.122.

    1 /**
    2  * \file
    3  * mach support for x86
    4  *
    5  * Authors:
    6  *   Geoff Norton (gnorton@novell.com)
    7  *   Rodrigo Kumpera (kumpera@gmail.com)
    8  *
    9  * (C) 2010 Novell, Inc.
   10  * (C) 2013 Xamarin, Inc.
   11  */
   12 
   13 #include <config.h>
   14 
   15 #if defined(__MACH__)
   16 #include <stdint.h>
   17 #include <glib.h>
   18 #include <pthread.h>
   19 #include "utils/mono-sigcontext.h"
   20 #include "mach-support.h"
   21 
   22 //For reg numbers
   23 #include <mono/arch/amd64/amd64-codegen.h>
   24 
   25 int
   26 mono_mach_arch_get_mcontext_size ()
   27 {
   28     return sizeof (struct __darwin_mcontext64);
   29 }
   30 
   31 void
   32 mono_mach_arch_thread_states_to_mcontext (thread_state_t state, thread_state_t fpstate, void *context)
   33 {
   34     x86_thread_state64_t *arch_state = (x86_thread_state64_t *) state;
   35     x86_float_state64_t *arch_fpstate = (x86_float_state64_t *) fpstate;
   36     struct __darwin_mcontext64 *ctx = (struct __darwin_mcontext64 *) context;
   37     ctx->__ss = *arch_state;
   38     ctx->__fs = *arch_fpstate;
   39 }
   40 
   41 void
   42 mono_mach_arch_mcontext_to_thread_states (void *context, thread_state_t state, thread_state_t fpstate)
   43 {
   44     x86_thread_state64_t *arch_state = (x86_thread_state64_t *) state;
   45     x86_float_state64_t *arch_fpstate = (x86_float_state64_t *) fpstate;
   46     struct __darwin_mcontext64 *ctx = (struct __darwin_mcontext64 *) context;
   47     *arch_state = ctx->__ss;
   48     *arch_fpstate = ctx->__fs;
   49 }
   50 
   51 void
   52 mono_mach_arch_thread_states_to_mono_context (thread_state_t state, thread_state_t fpstate, MonoContext *context)
   53 {
   54     x86_thread_state64_t *arch_state = (x86_thread_state64_t *) state;
   55     x86_float_state64_t *arch_fpstate = (x86_float_state64_t *) fpstate;
   56     context->gregs [AMD64_RAX] = arch_state->__rax;
   57     context->gregs [AMD64_RBX] = arch_state->__rbx;
   58     context->gregs [AMD64_RCX] = arch_state->__rcx;
   59     context->gregs [AMD64_RDX] = arch_state->__rdx;
   60     context->gregs [AMD64_RDI] = arch_state->__rdi;
   61     context->gregs [AMD64_RSI] = arch_state->__rsi;
   62     context->gregs [AMD64_RBP] = arch_state->__rbp;
   63     context->gregs [AMD64_RSP] = arch_state->__rsp;
   64     context->gregs [AMD64_R8] = arch_state->__r8;
   65     context->gregs [AMD64_R9] = arch_state->__r9;
   66     context->gregs [AMD64_R10] = arch_state->__r10;
   67     context->gregs [AMD64_R11] = arch_state->__r11;
   68     context->gregs [AMD64_R12] = arch_state->__r12;
   69     context->gregs [AMD64_R13] = arch_state->__r13;
   70     context->gregs [AMD64_R14] = arch_state->__r14;
   71     context->gregs [AMD64_R15] = arch_state->__r15;
   72     context->gregs [AMD64_RIP] = arch_state->__rip;
   73     context->fregs [AMD64_XMM0] = arch_fpstate->__fpu_xmm0;
   74     context->fregs [AMD64_XMM1] = arch_fpstate->__fpu_xmm1;
   75     context->fregs [AMD64_XMM2] = arch_fpstate->__fpu_xmm2;
   76     context->fregs [AMD64_XMM3] = arch_fpstate->__fpu_xmm3;
   77     context->fregs [AMD64_XMM4] = arch_fpstate->__fpu_xmm4;
   78     context->fregs [AMD64_XMM5] = arch_fpstate->__fpu_xmm5;
   79     context->fregs [AMD64_XMM6] = arch_fpstate->__fpu_xmm6;
   80     context->fregs [AMD64_XMM7] = arch_fpstate->__fpu_xmm7;
   81     context->fregs [AMD64_XMM8] = arch_fpstate->__fpu_xmm8;
   82     context->fregs [AMD64_XMM9] = arch_fpstate->__fpu_xmm9;
   83     context->fregs [AMD64_XMM10] = arch_fpstate->__fpu_xmm10;
   84     context->fregs [AMD64_XMM11] = arch_fpstate->__fpu_xmm11;
   85     context->fregs [AMD64_XMM12] = arch_fpstate->__fpu_xmm12;
   86     context->fregs [AMD64_XMM13] = arch_fpstate->__fpu_xmm13;
   87     context->fregs [AMD64_XMM14] = arch_fpstate->__fpu_xmm14;
   88     context->fregs [AMD64_XMM15] = arch_fpstate->__fpu_xmm15;
   89 }
   90 
   91 int
   92 mono_mach_arch_get_thread_state_size ()
   93 {
   94     return sizeof (x86_thread_state64_t);
   95 }
   96 
   97 int
   98 mono_mach_arch_get_thread_fpstate_size ()
   99 {
  100     return sizeof (x86_float_state64_t);
  101 }
  102 
  103 kern_return_t
  104 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)
  105 {
  106 #if defined(HOST_WATCHOS)
  107     g_error ("thread_get_state() is not supported by this platform");
  108 #else
  109     x86_thread_state64_t *arch_state = (x86_thread_state64_t *)state;
  110     x86_float_state64_t *arch_fpstate = (x86_float_state64_t *)fpstate;
  111     kern_return_t ret;
  112 
  113     *count = x86_THREAD_STATE64_COUNT;
  114     *fpcount = x86_FLOAT_STATE64_COUNT;
  115 
  116     ret = thread_get_state (thread, x86_THREAD_STATE64, (thread_state_t)arch_state, count);
  117     if (ret != KERN_SUCCESS)
  118         return ret;
  119 
  120     ret = thread_get_state (thread, x86_FLOAT_STATE64, (thread_state_t)arch_fpstate, fpcount);
  121     return ret;
  122 #endif
  123 }
  124 
  125 kern_return_t
  126 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)
  127 {
  128 #if defined(HOST_WATCHOS)
  129     g_error ("thread_set_state() is not supported by this platform");
  130 #else
  131     kern_return_t ret;
  132     ret = thread_set_state (thread, x86_THREAD_STATE64, state, count);
  133     if (ret != KERN_SUCCESS)
  134         return ret;
  135     ret = thread_set_state (thread, x86_FLOAT_STATE64, fpstate, fpcount);
  136     return ret;
  137 #endif
  138 }
  139 
  140 #endif