[jit] Assert that the trampoline code is called in gc unsafe mode, throw exceptions...
authorZoltan Varga <vargaz@gmail.com>
Sat, 26 Aug 2017 08:53:24 +0000 (04:53 -0400)
committerGitHub <noreply@github.com>
Sat, 26 Aug 2017 08:53:24 +0000 (04:53 -0400)
mono/mini/mini-trampolines.c
mono/utils/mono-threads-state-machine.c
mono/utils/mono-threads.h

index c78abccad633d929d1dcef391ef5ba360dd0ee16..a63b8ea322368427b297bc4a29397b1d97facadc 100644 (file)
@@ -824,19 +824,19 @@ gpointer
 mono_magic_trampoline (mgreg_t *regs, guint8 *code, gpointer arg, guint8* tramp)
 {
        gpointer res;
+       MonoError error;
 
-       MONO_ENTER_GC_UNSAFE_UNBALANCED;
+       MONO_REQ_GC_UNSAFE_MODE;
 
-       MonoError error;
+       g_assert (mono_thread_is_gc_unsafe_mode ());
 
        trampoline_calls ++;
 
        res = common_call_trampoline (regs, code, (MonoMethod *)arg, NULL, NULL, &error);
-       mono_error_set_pending_exception (&error);
-
-       mono_interruption_checkpoint_from_trampoline ();
-
-       MONO_EXIT_GC_UNSAFE_UNBALANCED;
+       if (!is_ok (&error)) {
+               mono_error_set_pending_exception (&error);
+               return NULL;
+       }
 
        return res;
 }
index 38e869cd040e9ffb3504349cbd9bb7c25aa0babb..1518438babbb9a99d2f1844bf65b3a35888d8bd0 100644 (file)
@@ -633,3 +633,21 @@ mono_thread_state_name (int state)
 {
        return state_name (state);
 }
+
+gboolean
+mono_thread_is_gc_unsafe_mode (void)
+{
+       MonoThreadInfo *cur = mono_thread_info_current ();
+
+       if (!cur)
+               return FALSE;
+
+       switch (mono_thread_info_current_state (cur)) {
+       case STATE_RUNNING:
+       case STATE_ASYNC_SUSPEND_REQUESTED:
+       case STATE_SELF_SUSPEND_REQUESTED:
+               return TRUE;
+       default:
+               return FALSE;
+       }
+}
index ffa9de63a66e5468d8cd5fe58989202cb73755b1..b95784fa6fd9ebeb5d69a5f94eba78e658ad4809 100644 (file)
@@ -612,6 +612,7 @@ gboolean mono_thread_info_is_live (THREAD_INFO_TYPE *info);
 int mono_thread_info_suspend_count (THREAD_INFO_TYPE *info);
 int mono_thread_info_current_state (THREAD_INFO_TYPE *info);
 const char* mono_thread_state_name (int state);
+gboolean mono_thread_is_gc_unsafe_mode (void);
 
 gboolean mono_thread_info_in_critical_location (THREAD_INFO_TYPE *info);
 gboolean mono_thread_info_begin_suspend (THREAD_INFO_TYPE *info);