Merge pull request #496 from nicolas-raoul/unit-test-for-issue2907
[mono.git] / mono / utils / mach-support-x86.c
index a5b7def4337d00fb101e85de2a605c320f475b3b..e65fe6bdeefe05a40f603c9d482fedbb2baa8b04 100644 (file)
@@ -39,7 +39,7 @@ mono_mach_arch_get_mcontext_size ()
 }
 
 void
-mono_mach_arch_thread_state_to_mcontext (thread_state_t state, mcontext_t context)
+mono_mach_arch_thread_state_to_mcontext (thread_state_t state, void *context)
 {
        x86_thread_state32_t *arch_state = (x86_thread_state32_t *) state;
        struct __darwin_mcontext32 *ctx = (struct __darwin_mcontext32 *) context;
@@ -47,6 +47,15 @@ mono_mach_arch_thread_state_to_mcontext (thread_state_t state, mcontext_t contex
        ctx->__ss = *arch_state;
 }
 
+void
+mono_mach_arch_mcontext_to_thread_state (void *context, thread_state_t state)
+{
+       x86_thread_state32_t *arch_state = (x86_thread_state32_t *) state;
+       struct __darwin_mcontext32 *ctx = (struct __darwin_mcontext32 *) context;
+
+       *arch_state = ctx->__ss;
+}
+
 int
 mono_mach_arch_get_thread_state_size ()
 {
@@ -66,16 +75,30 @@ mono_mach_arch_get_thread_state (thread_port_t thread, thread_state_t state, mac
        return ret;
 }
 
+kern_return_t
+mono_mach_arch_set_thread_state (thread_port_t thread, thread_state_t state, mach_msg_type_number_t count)
+{
+       return thread_set_state (thread, x86_THREAD_STATE32, state, count);
+}
+
 void *
-mono_mach_arch_get_tls_value_from_thread (thread_port_t thread, guint32 key)
+mono_mach_get_tls_address_from_thread (pthread_t thread, pthread_key_t key)
 {
        /* OSX stores TLS values in a hidden array inside the pthread_t structure
         * They are keyed off a giant array offset 0x48 into the pointer.  This value
         * is baked into their pthread_getspecific implementation
         */
-       intptr_t *p = (intptr_t *) pthread_from_mach_thread_np (thread);
-       intptr_t **tsd = (intptr_t **) (p + 0x48);
+       intptr_t *p = (intptr_t *) thread;
+       intptr_t **tsd = (intptr_t **) ((char*)p + 0x48);
+
+       return (void *) &tsd [key];     
+}
 
-       return (void *) tsd [key];
+void *
+mono_mach_arch_get_tls_value_from_thread (pthread_t thread, guint32 key)
+{
+       return *(void**)mono_mach_get_tls_address_from_thread (thread, key);
 }
+
+
 #endif