[runtime] Fix abort ignore when suspended in first instruction from finally block
[mono.git] / mono / mini / mini-exceptions.c
index 2b8374596e0f30adefe21b196d3c2f1857bd90b9..47350c4377bef77cf31a49cbc827ae02439db84f 100644 (file)
@@ -60,7 +60,7 @@
 #include <mono/metadata/gc-internals.h>
 #include <mono/metadata/debug-internals.h>
 #include <mono/metadata/mono-debug.h>
-#include <mono/metadata/profiler.h>
+#include <mono/metadata/profiler-private.h>
 #include <mono/metadata/mono-endian.h>
 #include <mono/metadata/environment.h>
 #include <mono/metadata/mono-mlist.h>
@@ -349,7 +349,7 @@ is_address_protected (MonoJitInfo *ji, MonoJitExceptionInfo *ei, gpointer ip)
 
        for (i = 0; i < table->num_holes; ++i) {
                MonoTryBlockHoleJitInfo *hole = &table->holes [i];
-               if (hole->clause == clause && hole->offset <= offset && hole->offset + hole->length > offset)
+               if (ji->clauses [hole->clause].try_offset == ji->clauses [clause].try_offset && hole->offset <= offset && hole->offset + hole->length > offset)
                        return FALSE;
        }
        return TRUE;
@@ -1937,7 +1937,7 @@ mono_handle_exception_internal (MonoContext *ctx, MonoObject *obj, gboolean resu
                                mono_print_thread_dump_from_ctx (ctx);
                }
                jit_tls->orig_ex_ctx_set = TRUE;
-               mono_profiler_exception_thrown (obj);
+               MONO_PROFILER_RAISE (exception_throw, (obj));
                jit_tls->orig_ex_ctx_set = FALSE;
 
                res = mono_handle_exception_internal_first_pass (&ctx_cp, obj, &first_filter_idx, &ji, &prev_ji, non_exception);
@@ -2139,7 +2139,7 @@ mono_handle_exception_internal (MonoContext *ctx, MonoObject *obj, gboolean resu
                                        if (mono_trace_is_enabled () && mono_trace_eval (method))
                                                g_print ("EXCEPTION: catch found at clause %d of %s\n", i, mono_method_full_name (method, TRUE));
                                        jit_tls->orig_ex_ctx_set = TRUE;
-                                       mono_profiler_exception_clause_handler (method, ei->flags, i, ex_obj);
+                                       MONO_PROFILER_RAISE (exception_clause, (method, i, ei->flags, ex_obj));
                                        jit_tls->orig_ex_ctx_set = FALSE;
                                        mini_set_abort_threshold (ctx);
 
@@ -2183,7 +2183,7 @@ mono_handle_exception_internal (MonoContext *ctx, MonoObject *obj, gboolean resu
                                        if (mono_trace_is_enabled () && mono_trace_eval (method))
                                                g_print ("EXCEPTION: fault clause %d of %s\n", i, mono_method_full_name (method, TRUE));
                                        jit_tls->orig_ex_ctx_set = TRUE;
-                                       mono_profiler_exception_clause_handler (method, ei->flags, i, ex_obj);
+                                       MONO_PROFILER_RAISE (exception_clause, (method, i, ei->flags, ex_obj));
                                        jit_tls->orig_ex_ctx_set = FALSE;
                                        mini_set_abort_threshold (ctx);
                                        call_filter (ctx, ei->handler_start);
@@ -2192,7 +2192,7 @@ mono_handle_exception_internal (MonoContext *ctx, MonoObject *obj, gboolean resu
                                        if (mono_trace_is_enabled () && mono_trace_eval (method))
                                                g_print ("EXCEPTION: finally clause %d of %s\n", i, mono_method_full_name (method, TRUE));
                                        jit_tls->orig_ex_ctx_set = TRUE;
-                                       mono_profiler_exception_clause_handler (method, ei->flags, i, ex_obj);
+                                       MONO_PROFILER_RAISE (exception_clause, (method, i, ei->flags, ex_obj));
                                        jit_tls->orig_ex_ctx_set = FALSE;
 #ifndef DISABLE_PERFCOUNTERS
                                        mono_perfcounters->exceptions_finallys++;
@@ -2230,7 +2230,7 @@ mono_handle_exception_internal (MonoContext *ctx, MonoObject *obj, gboolean resu
                }
 
                jit_tls->orig_ex_ctx_set = TRUE;
-               mono_profiler_exception_method_leave (method);
+               MONO_PROFILER_RAISE (method_exception_leave, (method, ex_obj));
                jit_tls->orig_ex_ctx_set = FALSE;
 
                *ctx = new_ctx;
@@ -2917,7 +2917,7 @@ find_last_handler_block (StackFrameInfo *frame, MonoContext *ctx, gpointer data)
                        continue;
                /*If ip points to the first instruction it means the handler block didn't start
                 so we can leave its execution to the EH machinery*/
-               if (ei->handler_start < ip && ip < ei->data.handler_end) {
+               if (ei->handler_start <= ip && ip < ei->data.handler_end) {
                        pdata->ji = ji;
                        pdata->ei = ei;
                        pdata->ctx = *ctx;
@@ -2941,7 +2941,7 @@ install_handler_block_guard (MonoJitInfo *ji, MonoContext *ctx)
                clause = &ji->clauses [i];
                if (clause->flags != MONO_EXCEPTION_CLAUSE_FINALLY)
                        continue;
-               if (clause->handler_start < ip && clause->data.handler_end > ip)
+               if (clause->handler_start <= ip && clause->data.handler_end > ip)
                        break;
        }
 
@@ -2949,10 +2949,6 @@ install_handler_block_guard (MonoJitInfo *ji, MonoContext *ctx)
        if (i == ji->num_clauses)
                return NULL;
 
-       /*If we stopped on the instruction right before the try, we haven't actually started executing it*/
-       if (ip == clause->handler_start)
-               return NULL;
-
        return mono_arch_install_handler_block_guard (ji, clause, ctx, mono_create_handler_block_trampoline ());
 }