Wed Oct 31 20:23:14 CET 2007 Paolo Molaro <lupus@ximian.com>
authorPaolo Molaro <lupus@oddwiz.org>
Wed, 31 Oct 2007 19:10:05 +0000 (19:10 -0000)
committerPaolo Molaro <lupus@oddwiz.org>
Wed, 31 Oct 2007 19:10:05 +0000 (19:10 -0000)
* mini.c, mini-x86.c: when getting back from unmanaged code
to managed via a marshaled delegate we also need to set the
right domain.

svn path=/trunk/mono/; revision=88602

mono/mini/mini-x86.c
mono/mini/mini.c

index 36ead85c60c8b7bf29af2719e18e033486142b2a..1c83859cce4de3171a36f225cbe00cc0ad9e747c 100644 (file)
@@ -3624,14 +3624,19 @@ mono_arch_emit_prolog (MonoCompile *cfg)
        pos = 0;
 
        if (method->wrapper_type == MONO_WRAPPER_NATIVE_TO_MANAGED) {
-               /* Might need to attach the thread to the JIT */
-               if (lmf_tls_offset != -1) {
-                       guint8 *buf;
+               /* 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 = 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 = 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);
index e4d6da472522842ba47adcf52d7e6fa4f8f81dbc..b3568eab4a16489dddaef4c9249f163ec954544f 100644 (file)
@@ -9010,6 +9010,8 @@ mono_jit_thread_attach (MonoDomain *domain)
        if (!TlsGetValue (mono_jit_tls_id))
                mono_thread_attach (domain);
 #endif
+       if (mono_domain_get () != domain)
+               mono_domain_set (domain, TRUE);
 }      
 
 /**