[runtime] Use mono_restore_context () to reduce code duplication in the back ends.
authorZoltan Varga <vargaz@gmail.com>
Tue, 22 Oct 2013 12:12:38 +0000 (14:12 +0200)
committerZoltan Varga <vargaz@gmail.com>
Tue, 22 Oct 2013 12:12:38 +0000 (14:12 +0200)
mono/mini/debugger-agent.c
mono/mini/exceptions-amd64.c
mono/mini/exceptions-arm.c
mono/mini/exceptions-mips.c
mono/mini/exceptions-ppc.c
mono/mini/exceptions-s390x.c
mono/mini/exceptions-x86.c
mono/mini/mini-exceptions.c

index a58d5496b6ab22e5cc2ac47f9ade0e1f7f7c7028..0f9eaa79cb5ee81c0a1143791db24f4b16a8404a 100755 (executable)
@@ -4602,10 +4602,6 @@ process_signal_event (void (*func) (DebuggerTlsData*))
 {
        DebuggerTlsData *tls;
        MonoContext orig_restore_ctx, ctx;
-       static void (*restore_context) (void *);
-
-       if (!restore_context)
-               restore_context = mono_get_restore_context ();
 
        tls = mono_native_tls_get_value (debugger_tls_id);
        /* Have to save/restore the restore_ctx as we can be called recursively during invokes etc. */
@@ -4617,7 +4613,7 @@ process_signal_event (void (*func) (DebuggerTlsData*))
        /* This is called when resuming from a signal handler, so it shouldn't return */
        memcpy (&ctx, &tls->restore_ctx, sizeof (MonoContext));
        memcpy (&tls->restore_ctx, &orig_restore_ctx, sizeof (MonoContext));
-       restore_context (&ctx);
+       mono_restore_context (&ctx);
        g_assert_not_reached ();
 }
 
@@ -6388,13 +6384,9 @@ invoke_method (void)
        int id;
        int i, err, mindex;
        Buffer buf;
-       static void (*restore_context) (void *);
        MonoContext restore_ctx;
        guint8 *p;
 
-       if (!restore_context)
-               restore_context = mono_get_restore_context ();
-
        tls = mono_native_tls_get_value (debugger_tls_id);
        g_assert (tls);
 
index 004cb0d430a2a7e17b86a501bf194083526c265e..31060ca16da34d5417918eb73048d2e0eb25c0fc 100644 (file)
@@ -347,12 +347,8 @@ mono_amd64_throw_exception (guint64 dummy1, guint64 dummy2, guint64 dummy3, guin
                                                        mgreg_t *regs, mgreg_t rip,
                                                        MonoObject *exc, gboolean rethrow)
 {
-       static void (*restore_context) (MonoContext *);
        MonoContext ctx;
 
-       if (!restore_context)
-               restore_context = mono_get_restore_context ();
-
        ctx.rsp = regs [AMD64_RSP];
        ctx.rip = rip;
        ctx.rbx = regs [AMD64_RBX];
@@ -383,7 +379,7 @@ mono_amd64_throw_exception (guint64 dummy1, guint64 dummy2, guint64 dummy3, guin
                        ctx_cp.rip = rip - 5;
 
                        if (mono_debugger_handle_exception (&ctx_cp, exc)) {
-                               restore_context (&ctx_cp);
+                               mono_restore_context (&ctx_cp);
                                g_assert_not_reached ();
                        }
                }
@@ -393,8 +389,7 @@ mono_amd64_throw_exception (guint64 dummy1, guint64 dummy2, guint64 dummy3, guin
        ctx.rip -= 1;
 
        mono_handle_exception (&ctx, exc);
-       restore_context (&ctx);
-
+       mono_restore_context (&ctx);
        g_assert_not_reached ();
 }
 
@@ -757,10 +752,6 @@ handle_signal_exception (gpointer obj)
 {
        MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
        MonoContext ctx;
-       static void (*restore_context) (MonoContext *);
-
-       if (!restore_context)
-               restore_context = mono_get_restore_context ();
 
        memcpy (&ctx, &jit_tls->ex_ctx, sizeof (MonoContext));
 
@@ -769,7 +760,7 @@ handle_signal_exception (gpointer obj)
 
        mono_handle_exception (&ctx, obj);
 
-       restore_context (&ctx);
+       mono_restore_context (&ctx);
 }
 
 void
@@ -885,22 +876,20 @@ prepare_for_guard_pages (MonoContext *mctx)
 static void
 altstack_handle_and_restore (void *sigctx, gpointer obj, gboolean stack_ovf)
 {
-       void (*restore_context) (MonoContext *);
        MonoContext mctx;
 
-       restore_context = mono_get_restore_context ();
        mono_arch_sigctx_to_monoctx (sigctx, &mctx);
 
        if (mono_debugger_handle_exception (&mctx, (MonoObject *)obj)) {
                if (stack_ovf)
                        prepare_for_guard_pages (&mctx);
-               restore_context (&mctx);
+               mono_restore_context (&mctx);
        }
 
        mono_handle_exception (&mctx, obj);
        if (stack_ovf)
                prepare_for_guard_pages (&mctx);
-       restore_context (&mctx);
+       mono_restore_context (&mctx);
 }
 
 void
index 8931dd8467e20dd0a7c77486a25ffdfac78112d7..e9059a9aa34c9bbb8fdebabba71b129d1ef070dc 100644 (file)
@@ -135,13 +135,9 @@ mono_arch_get_call_filter (MonoTrampInfo **info, gboolean aot)
 void
 mono_arm_throw_exception (MonoObject *exc, mgreg_t pc, mgreg_t sp, mgreg_t *int_regs, gdouble *fp_regs)
 {
-       static void (*restore_context) (MonoContext *);
        MonoContext ctx;
        gboolean rethrow = pc & 1;
 
-       if (!restore_context)
-               restore_context = mono_get_restore_context ();
-
        pc &= ~1; /* clear the optional rethrow bit */
        /* adjust eip so that it point into the call instruction */
        pc -= 4;
@@ -159,7 +155,7 @@ mono_arm_throw_exception (MonoObject *exc, mgreg_t pc, mgreg_t sp, mgreg_t *int_
                        mono_ex->stack_trace = NULL;
        }
        mono_handle_exception (&ctx, exc);
-       restore_context (&ctx);
+       mono_restore_context (&ctx);
        g_assert_not_reached ();
 }
 
@@ -517,16 +513,12 @@ handle_signal_exception (gpointer obj)
 {
        MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
        MonoContext ctx;
-       static void (*restore_context) (MonoContext *);
-
-       if (!restore_context)
-               restore_context = mono_get_restore_context ();
 
        memcpy (&ctx, &jit_tls->ex_ctx, sizeof (MonoContext));
 
        mono_handle_exception (&ctx, obj);
 
-       restore_context (&ctx);
+       mono_restore_context (&ctx);
 }
 
 /*
index ea38a836aab28b452bba4658198d47d4be1369ef..ea58f176176baf50b9be20ef4ddaca1837c268d7 100644 (file)
@@ -174,7 +174,6 @@ mono_arch_get_call_filter (MonoTrampInfo **info, gboolean aot)
 static void
 throw_exception (MonoObject *exc, unsigned long eip, unsigned long esp, gboolean rethrow)
 {
-       static void (*restore_context) (MonoContext *);
        MonoContext ctx;
 
 #ifdef DEBUG_EXCEPTIONS
@@ -182,9 +181,6 @@ throw_exception (MonoObject *exc, unsigned long eip, unsigned long esp, gboolean
                 exc, (void *)eip, (void *) esp, rethrow);
 #endif
 
-       if (!restore_context)
-               restore_context = mono_get_restore_context ();
-
        /* adjust eip so that it point into the call instruction */
        eip -= 8;
 
@@ -207,7 +203,7 @@ throw_exception (MonoObject *exc, unsigned long eip, unsigned long esp, gboolean
                 (void *) ctx.sc_pc, (void *) ctx.sc_regs[mips_sp],
                 (void *) ctx.sc_regs[mips_fp], &ctx);
 #endif
-       restore_context (&ctx);
+       mono_restore_context (&ctx);
 
        g_assert_not_reached ();
 }
@@ -518,16 +514,12 @@ handle_signal_exception (gpointer obj)
 {
        MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
        MonoContext ctx;
-       static void (*restore_context) (MonoContext *);
-
-       if (!restore_context)
-               restore_context = mono_get_restore_context ();
 
        memcpy (&ctx, &jit_tls->ex_ctx, sizeof (MonoContext));
 
        mono_handle_exception (&ctx, obj);
 
-       restore_context (&ctx);
+       mono_restore_context (&ctx);
 }
 
 /*
index 38e1d2736f94c8d782cc7e5cb681c45514fb1745..80bbb3f9190d461b8503ca31569dd93d2ed5c9a6 100644 (file)
@@ -316,12 +316,8 @@ mono_arch_get_call_filter (MonoTrampInfo **info, gboolean aot)
 void
 mono_ppc_throw_exception (MonoObject *exc, unsigned long eip, unsigned long esp, mgreg_t *int_regs, gdouble *fp_regs, gboolean rethrow)
 {
-       static void (*restore_context) (MonoContext *);
        MonoContext ctx;
 
-       if (!restore_context)
-               restore_context = mono_get_restore_context ();
-
        /* adjust eip so that it point into the call instruction */
        eip -= 4;
 
@@ -339,7 +335,7 @@ mono_ppc_throw_exception (MonoObject *exc, unsigned long eip, unsigned long esp,
                        mono_ex->stack_trace = NULL;
        }
        mono_handle_exception (&ctx, exc);
-       restore_context (&ctx);
+       mono_restore_context (&ctx);
 
        g_assert_not_reached ();
 }
@@ -669,13 +665,11 @@ mono_ppc_set_func_into_sigctx (void *sigctx, void *func)
 static void
 altstack_handle_and_restore (void *sigctx, gpointer obj)
 {
-       void (*restore_context) (MonoContext *);
        MonoContext mctx;
 
-       restore_context = mono_get_restore_context ();
        mono_arch_sigctx_to_monoctx (sigctx, &mctx);
        mono_handle_exception (&mctx, obj);
-       restore_context (&mctx);
+       mono_restore_context (&mctx);
 }
 
 void
@@ -754,16 +748,12 @@ handle_signal_exception (gpointer obj)
 {
        MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
        MonoContext ctx;
-       static void (*restore_context) (MonoContext *);
-
-       if (!restore_context)
-               restore_context = mono_get_restore_context ();
 
        memcpy (&ctx, &jit_tls->ex_ctx, sizeof (MonoContext));
 
        mono_handle_exception (&ctx, obj);
 
-       restore_context (&ctx);
+       mono_restore_context (&ctx);
 }
 
 static void
index b95c6ed30185eb0e26916800ce2cc4b14352b60c..17bb8b044d0ea92945ed50c96f4d9c0cf3dfeedc 100644 (file)
@@ -237,11 +237,7 @@ throw_exception (MonoObject *exc, unsigned long ip, unsigned long sp,
 {
        MonoContext ctx;
        int iReg;
-       static void (*restore_context) (MonoContext *);
 
-       if (!restore_context)
-               restore_context = mono_get_restore_context();
-       
        memset(&ctx, 0, sizeof(ctx));
 
        setup_context(&ctx);
@@ -267,7 +263,7 @@ throw_exception (MonoObject *exc, unsigned long ip, unsigned long sp,
        }
 //     mono_arch_handle_exception (&ctx, exc, FALSE);
        mono_handle_exception (&ctx, exc);
-       restore_context(&ctx);
+       mono_restore_context(&ctx);
 
        g_assert_not_reached ();
 }
index 669f18330234eac828c89402bac5c8405efadfaa..8c1222c42ec26e37e75bf5fda057e4d588357d76 100644 (file)
@@ -473,12 +473,8 @@ void
 mono_x86_throw_exception (mgreg_t *regs, MonoObject *exc, 
                                                  mgreg_t eip, gboolean rethrow)
 {
-       static void (*restore_context) (MonoContext *);
        MonoContext ctx;
 
-       if (!restore_context)
-               restore_context = mono_get_restore_context ();
-
        ctx.esp = regs [X86_ESP];
        ctx.eip = eip;
        ctx.ebp = regs [X86_EBP];
@@ -511,7 +507,7 @@ mono_x86_throw_exception (mgreg_t *regs, MonoObject *exc,
                        ctx_cp.eip = eip - 5;
 
                        if (mono_debugger_handle_exception (&ctx_cp, exc)) {
-                               restore_context (&ctx_cp);
+                               mono_restore_context (&ctx_cp);
                                g_assert_not_reached ();
                        }
                }
@@ -522,7 +518,7 @@ mono_x86_throw_exception (mgreg_t *regs, MonoObject *exc,
 
        mono_handle_exception (&ctx, exc);
 
-       restore_context (&ctx);
+       mono_restore_context (&ctx);
 
        g_assert_not_reached ();
 }
@@ -989,10 +985,6 @@ handle_signal_exception (gpointer obj)
 {
        MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
        MonoContext ctx;
-       static void (*restore_context) (MonoContext *);
-
-       if (!restore_context)
-               restore_context = mono_get_restore_context ();
 
        memcpy (&ctx, &jit_tls->ex_ctx, sizeof (MonoContext));
 
@@ -1001,7 +993,7 @@ handle_signal_exception (gpointer obj)
 
        mono_handle_exception (&ctx, obj);
 
-       restore_context (&ctx);
+       mono_restore_context (&ctx);
 }
 
 /*
@@ -1149,22 +1141,20 @@ prepare_for_guard_pages (MonoContext *mctx)
 static void
 altstack_handle_and_restore (MonoContext *ctx, gpointer obj, gboolean stack_ovf)
 {
-       void (*restore_context) (MonoContext *);
        MonoContext mctx;
 
-       restore_context = mono_get_restore_context ();
        mctx = *ctx;
 
        if (mono_debugger_handle_exception (&mctx, (MonoObject *)obj)) {
                if (stack_ovf)
                        prepare_for_guard_pages (&mctx);
-               restore_context (&mctx);
+               mono_restore_context (&mctx);
        }
 
        mono_handle_exception (&mctx, obj);
        if (stack_ovf)
                prepare_for_guard_pages (&mctx);
-       restore_context (&mctx);
+       mono_restore_context (&mctx);
 }
 
 void
index 0ff39628db4a5aa51250aa059efa4fc1b2ad005a..11dce07c27b566af4661f98cba3f69554144b4fd 100644 (file)
@@ -1520,7 +1520,6 @@ mono_handle_exception_internal (MonoContext *ctx, gpointer obj, gboolean resume,
        MonoDomain *domain = mono_domain_get ();
        MonoJitInfo *ji, *prev_ji;
        static int (*call_filter) (MonoContext *, gpointer) = NULL;
-       static void (*restore_context) (void *);
        MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
        MonoLMF *lmf = mono_get_lmf ();
        MonoException *mono_ex;
@@ -1591,9 +1590,6 @@ mono_handle_exception_internal (MonoContext *ctx, gpointer obj, gboolean resume,
        if (!call_filter)
                call_filter = mono_get_call_filter ();
 
-       if (!restore_context)
-               restore_context = mono_get_restore_context ();
-
        g_assert (jit_tls->end_of_stack);
        g_assert (jit_tls->abort_func);
 
@@ -2496,7 +2492,6 @@ void
 mono_resume_unwind (MonoContext *ctx)
 {
        MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
-       static void (*restore_context) (MonoContext *);
        MonoContext new_ctx;
 
        MONO_CONTEXT_SET_IP (ctx, MONO_CONTEXT_GET_IP (&jit_tls->resume_state.ctx));
@@ -2505,10 +2500,7 @@ mono_resume_unwind (MonoContext *ctx)
 
        mono_handle_exception_internal (&new_ctx, jit_tls->resume_state.ex_obj, TRUE, NULL);
 
-       if (!restore_context)
-               restore_context = mono_get_restore_context ();
-
-       restore_context (&new_ctx);
+       mono_restore_context (&new_ctx);
 }
 
 #ifdef MONO_ARCH_HAVE_HANDLER_BLOCK_GUARD
@@ -2717,11 +2709,8 @@ mono_thread_state_init_from_current (MonoThreadUnwindState *ctx)
 static void
 mono_raise_exception_with_ctx (MonoException *exc, MonoContext *ctx)
 {
-       void (*restore_context) (MonoContext *);
-       restore_context = mono_get_restore_context ();
-
        mono_handle_exception (ctx, exc);
-       restore_context (ctx);
+       mono_restore_context (ctx);
 }
 
 /*FIXME Move all monoctx -> sigctx conversion to signal handlers once all archs support utils/mono-context */