Changed mono_win_chained_exception_needs_run to be a JIT TLS variable.
authorJoao Matos <joao.matos@xamarin.com>
Tue, 10 Jun 2014 15:55:24 +0000 (16:55 +0100)
committerJoao Matos <joao.matos@xamarin.com>
Tue, 10 Jun 2014 16:05:14 +0000 (17:05 +0100)
This fixes a potential race condition that might happen if two threads try to handle an exception at the same time.

mono/mini/exceptions-amd64.c
mono/mini/exceptions-x86.c
mono/mini/mini-windows.c
mono/mini/mini.h

index bd9847c4172f923b42056dd68a6e4b6914378674..a27176d295a4540461bb37eabce39085e37a771a 100644 (file)
@@ -48,7 +48,6 @@ static MonoW32ExceptionHandler segv_handler;
 
 LPTOP_LEVEL_EXCEPTION_FILTER mono_old_win_toplevel_exception_filter;
 void *mono_win_vectored_exception_handle;
-extern gboolean mono_win_chained_exception_needs_run;
 
 #define W32_SEH_HANDLE_EX(_ex) \
        if (_ex##_handler) _ex##_handler(0, ep, sctx)
@@ -76,8 +75,9 @@ static LONG CALLBACK seh_vectored_exception_handler(EXCEPTION_POINTERS* ep)
        CONTEXT* ctx;
        MonoContext* sctx;
        LONG res;
+       MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
 
-       mono_win_chained_exception_needs_run = FALSE;
+       jit_tls->mono_win_chained_exception_needs_run = FALSE;
        res = EXCEPTION_CONTINUE_EXECUTION;
 
        er = ep->ExceptionRecord;
@@ -118,7 +118,7 @@ static LONG CALLBACK seh_vectored_exception_handler(EXCEPTION_POINTERS* ep)
                break;
        }
 
-       if (mono_win_chained_exception_needs_run) {
+       if (jit_tls->mono_win_chained_exception_needs_run) {
                /* Don't copy context back if we chained exception
                * as the handler may have modfied the EXCEPTION_POINTERS
                * directly. We don't pass sigcontext to chained handlers.
index 86a28e08ab4062f14f3439e1575123fdf04a72d7..0505633d1bcf17a15931be28beff90f6e43d4f5d 100644 (file)
@@ -47,7 +47,6 @@ static MonoW32ExceptionHandler segv_handler;
 
 LPTOP_LEVEL_EXCEPTION_FILTER mono_old_win_toplevel_exception_filter;
 gpointer mono_win_vectored_exception_handle;
-extern gboolean mono_win_chained_exception_needs_run;
 extern int (*gUnhandledExceptionHandler)(EXCEPTION_POINTERS*);
 
 #ifndef PROCESS_CALLBACK_FILTER_ENABLED
@@ -196,8 +195,9 @@ LONG CALLBACK seh_vectored_exception_handler(EXCEPTION_POINTERS* ep)
        CONTEXT* ctx;
        struct sigcontext* sctx;
        LONG res;
+       MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
 
-       mono_win_chained_exception_needs_run = FALSE;
+       jit_tls->mono_win_chained_exception_needs_run = FALSE;
        res = EXCEPTION_CONTINUE_EXECUTION;
 
        er = ep->ExceptionRecord;
@@ -237,7 +237,7 @@ LONG CALLBACK seh_vectored_exception_handler(EXCEPTION_POINTERS* ep)
                break;
        }
 
-       if (mono_win_chained_exception_needs_run) {
+       if (jit_tls->mono_win_chained_exception_needs_run) {
                /* Don't copy context back if we chained exception
                * as the handler may have modfied the EXCEPTION_POINTERS
                * directly. We don't pass sigcontext to chained handlers.
index bb71ec48192694ee29ae91b9ad4c347c23f7bddf..c43b1d0102f6d156e58b801e317e1c9bac36a8b5 100644 (file)
@@ -50,8 +50,6 @@
 
 #include "jit-icalls.h"
 
-gboolean mono_win_chained_exception_needs_run;
-
 void
 mono_runtime_install_handlers (void)
 {
@@ -83,7 +81,8 @@ mono_runtime_cleanup_handlers (void)
 gboolean
 SIG_HANDLER_SIGNATURE (mono_chain_signal)
 {
-       mono_win_chained_exception_needs_run = TRUE;
+       MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
+       jit_tls->mono_win_chained_exception_needs_run = TRUE;
        return TRUE;
 }
 
index ff3d5537ad28b22cb4718acd8357fe1f20a0effe..76cbdf32022f906d8c4fb701b8cc443cb3d2aa68 100644 (file)
@@ -1060,6 +1060,11 @@ typedef struct {
         */
        MonoContext orig_ex_ctx;
        gboolean orig_ex_ctx_set;
+
+       /* 
+        * Stores if we need to run a chained exception in Windows.
+        */
+       gboolean mono_win_chained_exception_needs_run;
 } MonoJitTlsData;
 
 /*