Merge pull request #901 from Blewzman/FixAggregateExceptionGetBaseException
[mono.git] / mono / mini / tramp-x86.c
index e48929831c7a0226d97fd22e60491b736cd1cc5a..e98fe36d5144a649189b24ac1cc36af0f8cc67cf 100644 (file)
@@ -861,7 +861,15 @@ mono_arch_create_monitor_enter_trampoline (MonoTrampInfo **info, gboolean aot)
                x86_branch8 (code, X86_CC_Z, -1, 1);
 
                /* load MonoInternalThread* into EDX */
-               code = mono_x86_emit_tls_get (code, X86_EDX, mono_thread_get_tls_offset ());
+               if (aot) {
+                       /* load_aotconst () puts the result into EAX */
+                       x86_mov_reg_reg (code, X86_EDX, X86_EAX, sizeof (mgreg_t));
+                       code = mono_arch_emit_load_aotconst (buf, code, &ji, MONO_PATCH_INFO_TLS_OFFSET, GINT_TO_POINTER (TLS_KEY_THREAD));
+                       code = mono_x86_emit_tls_get_reg (code, X86_EAX, X86_EAX);
+                       x86_xchg_reg_reg (code, X86_EAX, X86_EDX, sizeof (mgreg_t));
+               } else {
+                       code = mono_x86_emit_tls_get (code, X86_EDX, mono_thread_get_tls_offset ());
+               }
                /* load TID into EDX */
                x86_mov_reg_membase (code, X86_EDX, X86_EDX, G_STRUCT_OFFSET (MonoInternalThread, tid), 4);
 
@@ -994,7 +1002,15 @@ mono_arch_create_monitor_exit_trampoline (MonoTrampInfo **info, gboolean aot)
 
                /* next case: synchronization is not null */
                /* load MonoInternalThread* into EDX */
-               code = mono_x86_emit_tls_get (code, X86_EDX, mono_thread_get_tls_offset ());
+               if (aot) {
+                       /* load_aotconst () puts the result into EAX */
+                       x86_mov_reg_reg (code, X86_EDX, X86_EAX, sizeof (mgreg_t));
+                       code = mono_arch_emit_load_aotconst (buf, code, &ji, MONO_PATCH_INFO_TLS_OFFSET, GINT_TO_POINTER (TLS_KEY_THREAD));
+                       code = mono_x86_emit_tls_get_reg (code, X86_EAX, X86_EAX);
+                       x86_xchg_reg_reg (code, X86_EAX, X86_EDX, sizeof (mgreg_t));
+               } else {
+                       code = mono_x86_emit_tls_get (code, X86_EDX, mono_thread_get_tls_offset ());
+               }
                /* load TID into EDX */
                x86_mov_reg_membase (code, X86_EDX, X86_EDX, G_STRUCT_OFFSET (MonoInternalThread, tid), 4);
                /* is synchronization->owner == TID */
@@ -1081,48 +1097,57 @@ mono_arch_invalidate_method (MonoJitInfo *ji, void *func, gpointer func_arg)
        x86_call_code (code, (guint8*)func);
 }
 
-static void
-handler_block_trampoline_helper (gpointer *ptr)
+static gpointer
+handler_block_trampoline_helper (void)
 {
        MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
-       *ptr = jit_tls->handler_block_return_address;
+       return jit_tls->handler_block_return_address;
 }
 
 gpointer
-mono_arch_create_handler_block_trampoline (void)
+mono_arch_create_handler_block_trampoline (MonoTrampInfo **info, gboolean aot)
 {
        guint8 *tramp = mono_get_trampoline_code (MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD);
        guint8 *code, *buf;
        int tramp_size = 64;
+       MonoJumpInfo *ji = NULL;
+       GSList *unwind_ops = NULL;
+
+       g_assert (!aot);
+
        code = buf = mono_global_codeman_reserve (tramp_size);
 
        /*
        This trampoline restore the call chain of the handler block then jumps into the code that deals with it.
        */
 
+       /*
+        * We are in a method frame after the call emitted by OP_CALL_HANDLER.
+        */
+
        if (mono_get_jit_tls_offset () != -1) {
                code = mono_x86_emit_tls_get (code, X86_EAX, mono_get_jit_tls_offset ());
                x86_mov_reg_membase (code, X86_EAX, X86_EAX, G_STRUCT_OFFSET (MonoJitTlsData, handler_block_return_address), 4);
-               /*simulate a call*/
-               /*Fix stack alignment*/
-               x86_alu_reg_imm (code, X86_SUB, X86_ESP, 0x8);
-               x86_push_reg (code, X86_EAX);
-               x86_jump_code (code, tramp);
        } else {
                /*Slow path uses a c helper*/
-               x86_alu_reg_imm (code, X86_SUB, X86_ESP, 0x8);
-               x86_push_reg (code, X86_ESP);
-               x86_push_imm (code, tramp);
-               x86_jump_code (code, handler_block_trampoline_helper);
+               x86_call_code (code, handler_block_trampoline_helper);
        }
+       /* Simulate a call */
+       /*Fix stack alignment*/
+       x86_alu_reg_imm (code, X86_SUB, X86_ESP, 0x4);
+       /* This is the address the trampoline will return to */
+       x86_push_reg (code, X86_EAX);
+       /* Dummy trampoline argument, since we call the generic trampoline directly */
+       x86_push_imm (code, 0);
+       x86_jump_code (code, tramp);
 
        nacl_global_codeman_validate (&buf, tramp_size, &code);
 
        mono_arch_flush_icache (buf, code - buf);
        g_assert (code - buf <= tramp_size);
 
-       if (mono_jit_map_is_enabled ())
-               mono_emit_jit_tramp (buf, code - buf, "handler_block_trampoline");
+       if (info)
+               *info = mono_tramp_info_create ("handler_block_trampoline", buf, code - buf, ji, unwind_ops);
 
        return buf;
 }
@@ -1171,7 +1196,7 @@ mono_arch_get_gsharedvt_arg_trampoline (MonoDomain *domain, gpointer arg, gpoint
        return start;
 }
 
-#if defined(MONOTOUCH) || defined(MONO_EXTENSIONS)
+#if defined(ENABLE_GSHAREDVT)
 
 #include "../../../mono-extensions/mono/mini/tramp-x86-gsharedvt.c"