- if (method->wrapper_type == MONO_WRAPPER_NATIVE_TO_MANAGED) {
- /* Might need to attach the thread to the JIT or change the domain for the callback */
- if (appdomain_tls_offset != -1 && lmf_tls_offset != -1) {
- guint8 *buf, *no_domain_branch;
-
- code = mono_x86_emit_tls_get (code, X86_EAX, appdomain_tls_offset);
- x86_alu_reg_imm (code, X86_CMP, X86_EAX, GPOINTER_TO_UINT (cfg->domain));
- no_domain_branch = code;
- x86_branch8 (code, X86_CC_NE, 0, 0);
- code = mono_x86_emit_tls_get ( code, X86_EAX, lmf_tls_offset);
- x86_test_reg_reg (code, X86_EAX, X86_EAX);
- buf = code;
- x86_branch8 (code, X86_CC_NE, 0, 0);
- x86_patch (no_domain_branch, code);
- x86_push_imm (code, cfg->domain);
- code = emit_call (cfg, code, MONO_PATCH_INFO_INTERNAL_METHOD, (gpointer)"mono_jit_thread_attach");
- x86_alu_reg_imm (code, X86_ADD, X86_ESP, 4);
- x86_patch (buf, code);
-#ifdef TARGET_WIN32
- /* The TLS key actually contains a pointer to the MonoJitTlsData structure */
- /* FIXME: Add a separate key for LMF to avoid this */
- x86_alu_reg_imm (code, X86_ADD, X86_EAX, G_STRUCT_OFFSET (MonoJitTlsData, lmf));
-#endif
- }
- else {
- x86_alu_reg_imm (code, X86_SUB, X86_ESP, 4);
- if (cfg->compile_aot) {
- /*
- * This goes before the saving of callee saved regs, so save the got reg
- * ourselves.
- */
- x86_push_reg (code, MONO_ARCH_GOT_REG);
- code = mono_arch_emit_load_got_addr (cfg->native_code, code, cfg, NULL);
- x86_push_imm (code, 0);
- } else {
- x86_push_imm (code, cfg->domain);
- }
- code = emit_call (cfg, code, MONO_PATCH_INFO_INTERNAL_METHOD, (gpointer)"mono_jit_thread_attach");
- x86_alu_reg_imm (code, X86_ADD, X86_ESP, 8);
- if (cfg->compile_aot)
- x86_pop_reg (code, MONO_ARCH_GOT_REG);
- }
- }
-