[runtime] Don't consume exception if not allowed to
authorVlad Brezae <brezaevlad@gmail.com>
Wed, 10 May 2017 23:14:11 +0000 (02:14 +0300)
committerVlad Brezae <brezaevlad@gmail.com>
Wed, 10 May 2017 23:14:11 +0000 (02:14 +0300)
The thread_state indicates whether we have a pending exception that needs to be consumed (be it sync or async). Normally we check the state before calling mono_thread_execute_interruption, but make sure we don't consume an exception if the thread_state doesn't allow us to (we can have an abort requested but mono_thread_clear_interruption_requested can return FALSE if we are inside an abort protected block and shouldn't process it)

mono/metadata/threads.c

index 6ae7eaa0c72dcde34e6b49afac8aa7a7ce409048..5cc8e1d86f906d0541dff394a7f445f59fb8de8f 100644 (file)
@@ -4435,14 +4435,17 @@ mono_thread_execute_interruption (void)
        LOCK_THREAD (thread);
 
        /* MonoThread::interruption_requested can only be changed with atomics */
-       if (mono_thread_clear_interruption_requested (thread)) {
-               /* this will consume pending APC calls */
+       if (!mono_thread_clear_interruption_requested (thread)) {
+               UNLOCK_THREAD (thread);
+               return NULL;
+       }
+
+       /* this will consume pending APC calls */
 #ifdef HOST_WIN32
-               WaitForSingleObjectEx (GetCurrentThread(), 0, TRUE);
+       WaitForSingleObjectEx (GetCurrentThread(), 0, TRUE);
 #endif
-               /* Clear the interrupted flag of the thread so it can wait again */
-               mono_thread_info_clear_self_interrupt ();
-       }
+       /* Clear the interrupted flag of the thread so it can wait again */
+       mono_thread_info_clear_self_interrupt ();
 
        /* If there's a pending exception and an AbortRequested, the pending exception takes precedence */
        if (sys_thread->pending_exception) {