Fix guard interrupt protection.
authorRodrigo Kumpera <kumpera@gmail.com>
Tue, 4 Jan 2011 02:56:39 +0000 (10:56 +0800)
committerRodrigo Kumpera <kumpera@gmail.com>
Tue, 4 Jan 2011 03:13:34 +0000 (11:13 +0800)
* mini.h: Introduce a new MonoContext variable to be used
by the interrupt protection code.

* mini-exceptions.c: Use new field.

* mini-trampolines.c: Ditto.

This fixes finally_guard.exe on OSX.

mono/mini/mini-exceptions.c
mono/mini/mini-trampolines.c
mono/mini/mini.h

index 41e27427f41d74873a89615ca5afa923836139ed..ca637adbe5e7be82964c1b41e774a009f3c11527 100644 (file)
@@ -1584,7 +1584,7 @@ mono_handle_exception_internal (MonoContext *ctx, gpointer obj, gpointer origina
                                         */
                                        if (G_UNLIKELY (jit_tls->handler_block_return_address)) {
                                                gboolean is_outside = FALSE;
-                                               gpointer prot_bp = MONO_CONTEXT_GET_BP (&jit_tls->ex_ctx);
+                                               gpointer prot_bp = MONO_CONTEXT_GET_BP (&jit_tls->handler_block_context);
                                                gpointer catch_bp = MONO_CONTEXT_GET_BP (ctx);
                                                //FIXME make this stack direction aware
                                                if (catch_bp > prot_bp) {
@@ -1599,7 +1599,7 @@ mono_handle_exception_internal (MonoContext *ctx, gpointer obj, gpointer origina
                                                         *      There aren't any further finally/fault handler blocks down the stack over this exception.
                                                         *   This must be ensured by the code that installs the guard trampoline.
                                                         */
-                                                       g_assert (ji == mini_jit_info_table_find (domain, MONO_CONTEXT_GET_IP (&jit_tls->ex_ctx), NULL));
+                                                       g_assert (ji == mini_jit_info_table_find (domain, MONO_CONTEXT_GET_IP (&jit_tls->handler_block_context), NULL));
 
                                                        if (!is_address_protected (ji, jit_tls->handler_block, ei->handler_start)) {
                                                                is_outside = TRUE;
@@ -2337,7 +2337,7 @@ mono_install_handler_block_guard (MonoInternalThread *thread, MonoContext *ctx)
        if (!data.ji)
                return FALSE;
 
-       memcpy (&jit_tls->ex_ctx, &data.ctx, sizeof (MonoContext));
+       memcpy (&jit_tls->handler_block_context, &data.ctx, sizeof (MonoContext));
 
        resume_ip = install_handler_block_guard (data.ji, &data.ctx);
        if (resume_ip == NULL)
index f9c790b6a988f919747f470d6db67fcb102cb9ad..147073ba800a1409cb928588a0b7708dbc83bbfd 100644 (file)
@@ -976,7 +976,7 @@ mono_handler_block_guard_trampoline (mgreg_t *regs, guint8 *code, gpointer *tram
        MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
        gpointer resume_ip = jit_tls->handler_block_return_address;
 
-       memcpy (&ctx, &jit_tls->ex_ctx, sizeof (MonoContext));
+       memcpy (&ctx, &jit_tls->handler_block_context, sizeof (MonoContext));
        MONO_CONTEXT_SET_IP (&ctx, jit_tls->handler_block_return_address);
 
        jit_tls->handler_block_return_address = NULL;
index 0132834b4f93707c5830b8ba33de82adcae4a497..5901ab58450b2d0c99f782db0409f1d541af6830 100644 (file)
@@ -969,11 +969,17 @@ typedef struct {
        /* Stores state needed by handler block with a guard */
        MonoContext     ex_ctx;
        ResumeState resume_state;
-       /* handle block return address */
+
+       /*Variabled use to implement handler blocks (finally/catch/etc) guards during interruption*/
+       /* handler block return address */
        gpointer handler_block_return_address;
-       /* handler block been guarded */
+
+       /* handler block been guarded. It's safe to store this even for dynamic methods since there
+       is an activation on stack making sure it will remain alive.*/
        MonoJitExceptionInfo *handler_block;
 
+       /* context to be used by the guard trampoline when resuming interruption.*/
+       MonoContext handler_block_context;
        /* 
         * Stores the state at the exception throw site to be used by mono_stack_walk ()
         * when it is called from profiler functions during exception handling.