[runtime] Pass the MonoThreadInfo explicitly to mono_thread_state_init_from_handle...
authorRodrigo Kumpera <kumpera@gmail.com>
Wed, 14 May 2014 22:40:59 +0000 (18:40 -0400)
committerRodrigo Kumpera <kumpera@gmail.com>
Thu, 15 May 2014 19:52:54 +0000 (15:52 -0400)
This function was called from code that uses hazard pointers, so their values could get overridden.
Besides that, we did not clean up the hazard pointer table afterwards, which is wrong too.

mono/mini/mini-darwin.c
mono/mini/mini-gc.c
mono/mini/mini-posix.c
mono/mini/mini-windows.c
mono/mini/mini.h
mono/utils/mono-threads-mach.c
mono/utils/mono-threads.h

index 2e44981e2db822890bcd797b21162beefe2430a7..9a57d363ce2dae59aabfb87a9d6c56d30ffca62e 100644 (file)
@@ -290,7 +290,7 @@ mono_gdb_render_native_backtraces (pid_t crashed_pid)
 }
 
 gboolean
-mono_thread_state_init_from_handle (MonoThreadUnwindState *tctx, MonoNativeThreadId thread_id, MonoNativeThreadHandle thread_handle)
+mono_thread_state_init_from_handle (MonoThreadUnwindState *tctx, MonoThreadInfo *info)
 {
        kern_return_t ret;
        mach_msg_type_number_t num_state;
@@ -299,9 +299,10 @@ mono_thread_state_init_from_handle (MonoThreadUnwindState *tctx, MonoNativeThrea
        mcontext_t mctx;
        MonoJitTlsData *jit_tls;
        void *domain;
-       MonoLMF *lmf;
-       MonoThreadInfo *info;
+       MonoLMF *lmf = NULL;
+       gpointer *addr;
 
+       g_assert (info);
        /*Zero enough state to make sure the caller doesn't confuse itself*/
        tctx->valid = FALSE;
        tctx->unwind_data [MONO_UNWIND_DATA_DOMAIN] = NULL;
@@ -311,7 +312,7 @@ mono_thread_state_init_from_handle (MonoThreadUnwindState *tctx, MonoNativeThrea
        state = (thread_state_t) alloca (mono_mach_arch_get_thread_state_size ());
        mctx = (mcontext_t) alloca (mono_mach_arch_get_mcontext_size ());
 
-       ret = mono_mach_arch_get_thread_state (thread_handle, state, &num_state);
+       ret = mono_mach_arch_get_thread_state (info->native_handle, state, &num_state);
        if (ret != KERN_SUCCESS)
                return FALSE;
 
@@ -320,17 +321,10 @@ mono_thread_state_init_from_handle (MonoThreadUnwindState *tctx, MonoNativeThrea
 
        mono_sigctx_to_monoctx (&ctx, &tctx->ctx);
 
-       info = mono_thread_info_lookup (thread_id);
-
-       if (info) {
-               /* mono_set_jit_tls () sets this */
-               jit_tls = mono_thread_info_tls_get (info, TLS_KEY_JIT_TLS);
-               /* SET_APPDOMAIN () sets this */
-               domain = mono_thread_info_tls_get (info, TLS_KEY_DOMAIN);
-       } else {
-               jit_tls = NULL;
-               domain = NULL;
-       }
+       /* mono_set_jit_tls () sets this */
+       jit_tls = mono_thread_info_tls_get (info, TLS_KEY_JIT_TLS);
+       /* SET_APPDOMAIN () sets this */
+       domain = mono_thread_info_tls_get (info, TLS_KEY_DOMAIN);
 
        /*Thread already started to cleanup, can no longer capture unwind state*/
        if (!jit_tls || !domain)
@@ -341,15 +335,11 @@ mono_thread_state_init_from_handle (MonoThreadUnwindState *tctx, MonoNativeThrea
         * arch-specific code. But the address of the TLS variable is stored in another TLS variable which
         * can be accessed through MonoThreadInfo.
         */
-       lmf = NULL;
-       if (info) {
-               gpointer *addr;
-
-               /* mono_set_lmf_addr () sets this */
-               addr = mono_thread_info_tls_get (info, TLS_KEY_LMF_ADDR);
-               if (addr)
-                       lmf = *addr;
-       }
+       /* mono_set_lmf_addr () sets this */
+       addr = mono_thread_info_tls_get (info, TLS_KEY_LMF_ADDR);
+       if (addr)
+               lmf = *addr;
+
 
        tctx->unwind_data [MONO_UNWIND_DATA_DOMAIN] = domain;
        tctx->unwind_data [MONO_UNWIND_DATA_JIT_TLS] = jit_tls;
index a2e1f2f602962a8cbbfd3298c117031e0e00e691..5589d99eabb0e1f78f2ded0de3c90e7d7e1b0b27 100644 (file)
@@ -604,7 +604,7 @@ thread_suspend_func (gpointer user_data, void *sigctx, MonoContext *ctx)
 #ifdef TARGET_WIN32
                return;
 #else
-               res = mono_thread_state_init_from_handle (&tls->unwind_state, (MonoNativeThreadId)tls->tid, tls->info->native_handle);
+               res = mono_thread_state_init_from_handle (&tls->unwind_state, tls->info);
 #endif
        } else {
                tls->unwind_state.unwind_data [MONO_UNWIND_DATA_LMF] = mono_get_lmf ();
index 4bbedb2897c95c5eef9cf7070592d12eec4695cb..67f5725de6ae2db75799a1b7a7f980ed203a4de6 100644 (file)
@@ -728,7 +728,7 @@ mono_gdb_render_native_backtraces (pid_t crashed_pid)
 #if !defined (__MACH__)
 
 gboolean
-mono_thread_state_init_from_handle (MonoThreadUnwindState *tctx, MonoNativeThreadId thread_id, MonoNativeThreadHandle thread_handle)
+mono_thread_state_init_from_handle (MonoThreadUnwindState *tctx, MonoThreadInfo *info)
 {
        g_error ("Posix systems don't support mono_thread_state_init_from_handle");
        return FALSE;
index 46a317c4fc460009c139ed1a4101ec62f986910b..bb71ec48192694ee29ae91b9ad4c347c23f7bddf 100644 (file)
@@ -136,7 +136,7 @@ mono_runtime_shutdown_stat_profiler (void)
 }
 
 gboolean
-mono_thread_state_init_from_handle (MonoThreadUnwindState *tctx, MonoNativeThreadId thread_id, MonoNativeThreadHandle thread_handle)
+mono_thread_state_init_from_handle (MonoThreadUnwindState *tctx, MonoThreadInfo *info)
 {
        g_error ("Windows systems haven't been ported to support mono_thread_state_init_from_handle");
        return FALSE;
index eab8bfb0df6b1a4c2552637e57a717d49caaa7f4..702daa6b813a5e0485b984bc780da12894b300d4 100644 (file)
@@ -2445,7 +2445,7 @@ void
 mono_arch_setup_async_callback (MonoContext *ctx, void (*async_cb)(void *fun), gpointer user_data) MONO_INTERNAL;
 
 gboolean
-mono_thread_state_init_from_handle (MonoThreadUnwindState *tctx, MonoNativeThreadId thread_id, MonoNativeThreadHandle thread_handle) MONO_INTERNAL;
+mono_thread_state_init_from_handle (MonoThreadUnwindState *tctx, MonoThreadInfo *info) MONO_INTERNAL;
 
 
 /* Exception handling */
index 2f0e3ad5916513b7bc7bb2033df8163cf2994fed..f4ad2637e57e51c2f04688c586e67870e05041c4 100644 (file)
@@ -58,7 +58,7 @@ mono_threads_core_suspend (MonoThreadInfo *info)
        if (ret != KERN_SUCCESS)
                return FALSE;
        res = mono_threads_get_runtime_callbacks ()->
-               thread_state_init_from_handle (&info->suspend_state, mono_thread_info_get_tid (info), info->native_handle);
+               thread_state_init_from_handle (&info->suspend_state, info);
        if (!res)
                thread_resume (info->native_handle);
        return res;
index b2d9f26c199f1747bd1831cdb8eb5c7755ad7392..c7b31e70014f439ec9e217ad9d5bf78c3ce3f3a4 100644 (file)
@@ -184,7 +184,7 @@ typedef struct {
 typedef struct {
        void (*setup_async_callback) (MonoContext *ctx, void (*async_cb)(void *fun), gpointer user_data);
        gboolean (*thread_state_init_from_sigctx) (MonoThreadUnwindState *state, void *sigctx);
-       gboolean (*thread_state_init_from_handle) (MonoThreadUnwindState *tctx, MonoNativeThreadId thread_id, MonoNativeThreadHandle thread_handle);
+       gboolean (*thread_state_init_from_handle) (MonoThreadUnwindState *tctx, MonoThreadInfo *info);
 } MonoThreadInfoRuntimeCallbacks;
 
 /*