Merge pull request #249 from pcc/xgetinputfocus
[mono.git] / mono / mini / mini-amd64.c
index e7e76cdf603537deda3da5dd0829a4f04bb4b02d..3e926c59de292e1489303d02f9ff2d67a8cb753b 100644 (file)
@@ -4321,6 +4321,11 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
                                for (i = 0; i < breakpoint_size; ++i)
                                        x86_nop (code);
                        }
+                       /*
+                        * Add an additional nop so skipping the bp doesn't cause the ip to point
+                        * to another IL offset.
+                        */
+                       x86_nop (code);
                        break;
                }
                case OP_ADDCC:
@@ -6813,6 +6818,9 @@ mono_arch_emit_prolog (MonoCompile *cfg)
                                (cfg->rgctx_var->inst_basereg == AMD64_RBP || cfg->rgctx_var->inst_basereg == AMD64_RSP));
 
                amd64_mov_membase_reg (code, cfg->rgctx_var->inst_basereg, cfg->rgctx_var->inst_offset, MONO_ARCH_RGCTX_REG, sizeof(gpointer));
+
+               mono_add_var_location (cfg, cfg->rgctx_var, TRUE, MONO_ARCH_RGCTX_REG, 0, 0, code - cfg->native_code);
+               mono_add_var_location (cfg, cfg->rgctx_var, FALSE, cfg->rgctx_var->inst_basereg, cfg->rgctx_var->inst_offset, code - cfg->native_code, 0);
        }
 
        /* compute max_length in order to use short forward jumps */
@@ -6934,6 +6942,16 @@ mono_arch_emit_prolog (MonoCompile *cfg)
                                        size = 8;
                                */
                                amd64_mov_membase_reg (code, ins->inst_basereg, ins->inst_offset, ainfo->reg, size);
+
+                               /*
+                                * Save the original location of 'this',
+                                * get_generic_info_from_stack_frame () needs this to properly look up
+                                * the argument value during the handling of async exceptions.
+                                */
+                               if (ins == cfg->args [0]) {
+                                       mono_add_var_location (cfg, ins, TRUE, ainfo->reg, 0, 0, code - cfg->native_code);
+                                       mono_add_var_location (cfg, ins, FALSE, ins->inst_basereg, ins->inst_offset, code - cfg->native_code, 0);
+                               }
                                break;
                        }
                        case ArgInFloatSSEReg:
@@ -6980,61 +6998,11 @@ mono_arch_emit_prolog (MonoCompile *cfg)
                        default:
                                g_assert_not_reached ();
                        }
-               }
-       }
-
-       /* Might need to attach the thread to the JIT  or change the domain for the callback */
-       if (method->wrapper_type == MONO_WRAPPER_NATIVE_TO_MANAGED) {
-               guint64 domain = (guint64)cfg->domain;
-
-               args_clobbered = TRUE;
-
-               /* 
-                * The call might clobber argument registers, but they are already
-                * saved to the stack/global regs.
-                */
-               if (appdomain_tls_offset != -1 && lmf_tls_offset != -1) {
-                       guint8 *buf, *no_domain_branch;
 
-                       code = mono_amd64_emit_tls_get (code, AMD64_RAX, appdomain_tls_offset);
-                       if (cfg->compile_aot) {
-                               /* AOT code is only used in the root domain */
-                               amd64_mov_reg_imm (code, AMD64_ARG_REG1, 0);
-                       } else {
-                               if ((domain >> 32) == 0)
-                                       amd64_mov_reg_imm_size (code, AMD64_ARG_REG1, domain, 4);
-                               else
-                                       amd64_mov_reg_imm_size (code, AMD64_ARG_REG1, domain, 8);
-                       }
-                       amd64_alu_reg_reg (code, X86_CMP, AMD64_RAX, AMD64_ARG_REG1);
-                       no_domain_branch = code;
-                       x86_branch8 (code, X86_CC_NE, 0, 0);
-                       code = mono_amd64_emit_tls_get ( code, AMD64_RAX, lmf_addr_tls_offset);
-                       amd64_test_reg_reg (code, AMD64_RAX, AMD64_RAX);
-                       buf = code;
-                       x86_branch8 (code, X86_CC_NE, 0, 0);
-                       amd64_patch (no_domain_branch, code);
-                       code = emit_call (cfg, code, MONO_PATCH_INFO_INTERNAL_METHOD, 
-                                         (gpointer)"mono_jit_thread_attach", TRUE);
-                       amd64_patch (buf, code);
-#ifdef HOST_WIN32
-                       /* The TLS key actually contains a pointer to the MonoJitTlsData structure */
-                       /* FIXME: Add a separate key for LMF to avoid this */
-                       amd64_alu_reg_imm (code, X86_ADD, AMD64_RAX, G_STRUCT_OFFSET (MonoJitTlsData, lmf));
-#endif
-               } else {
-                       g_assert (!cfg->compile_aot);
-                       if (cfg->compile_aot) {
-                               /* AOT code is only used in the root domain */
-                               amd64_mov_reg_imm (code, AMD64_ARG_REG1, 0);
-                       } else {
-                               if ((domain >> 32) == 0)
-                                       amd64_mov_reg_imm_size (code, AMD64_ARG_REG1, domain, 4);
-                               else
-                                       amd64_mov_reg_imm_size (code, AMD64_ARG_REG1, domain, 8);
+                       if (ins == cfg->args [0]) {
+                               mono_add_var_location (cfg, ins, TRUE, ainfo->reg, 0, 0, code - cfg->native_code);
+                               mono_add_var_location (cfg, ins, TRUE, ins->dreg, 0, code - cfg->native_code, 0);
                        }
-                       code = emit_call (cfg, code, MONO_PATCH_INFO_INTERNAL_METHOD,
-                                         (gpointer)"mono_jit_thread_attach", TRUE);
                }
        }
 
@@ -8044,6 +8012,8 @@ mono_arch_finish_init (void)
                appdomain_tls_offset = -1;
        if (lmf_tls_offset >= 64)
                lmf_tls_offset = -1;
+       if (lmf_addr_tls_offset >= 64)
+               lmf_addr_tls_offset = -1;
 #else
 #ifdef MONO_XEN_OPT
        optimize_for_xen = access ("/proc/xen", F_OK) == 0;