Vincent Povirk : mscoree: Always call mono_thread_attach before invoking managed code.

Alexandre Julliard julliard at winehq.org
Tue Apr 24 13:14:40 CDT 2012


Module: wine
Branch: master
Commit: 3b4d278026486d42d67190649ad3b86ae4b61a87
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=3b4d278026486d42d67190649ad3b86ae4b61a87

Author: Vincent Povirk <vincent at codeweavers.com>
Date:   Mon Apr 23 14:55:52 2012 -0500

mscoree: Always call mono_thread_attach before invoking managed code.

---

 dlls/mscoree/corruntimehost.c  |   12 +++++++++++-
 dlls/mscoree/metahost.c        |    1 +
 dlls/mscoree/mscoree_private.h |    2 ++
 3 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/dlls/mscoree/corruntimehost.c b/dlls/mscoree/corruntimehost.c
index ff789d4..1750f12 100644
--- a/dlls/mscoree/corruntimehost.c
+++ b/dlls/mscoree/corruntimehost.c
@@ -148,6 +148,8 @@ static HRESULT RuntimeHost_GetIUnknownForDomain(RuntimeHost *This, MonoDomain *d
     MonoObject *appdomain_object;
     IUnknown *unk;
 
+    This->mono->mono_thread_attach(domain);
+
     assembly = This->mono->mono_domain_assembly_open(domain, "mscorlib");
     if (!assembly)
     {
@@ -560,6 +562,8 @@ static HRESULT WINAPI CLRRuntimeHost_ExecuteInDefaultAppDomain(ICLRRuntimeHost*
 
     hr = E_FAIL;
 
+    This->mono->mono_thread_attach(domain);
+
     filenameA = WtoA(pwzAssemblyPath);
     assembly = This->mono->mono_domain_assembly_open(domain, filenameA);
     if (!assembly)
@@ -658,6 +662,8 @@ HRESULT RuntimeHost_CreateManagedInstance(RuntimeHost *This, LPCWSTR name,
 
     if (SUCCEEDED(hr))
     {
+        This->mono->mono_thread_attach(domain);
+
         type = This->mono->mono_reflection_type_from_name(nameA, NULL);
         if (!type)
         {
@@ -705,7 +711,9 @@ HRESULT RuntimeHost_CreateManagedInstance(RuntimeHost *This, LPCWSTR name,
  *
  * NOTE: The IUnknown* is created with a reference to the object.
  * Until they have a reference, objects must be in the stack to prevent the
- * garbage collector from freeing them. */
+ * garbage collector from freeing them.
+ *
+ * mono_thread_attach must have already been called for this thread. */
 HRESULT RuntimeHost_GetIUnknownForObject(RuntimeHost *This, MonoObject *obj,
     IUnknown **ppUnk)
 {
@@ -1025,6 +1033,8 @@ HRESULT create_monodata(REFIID riid, LPVOID *ppObj )
 
             hr = CLASS_E_CLASSNOTAVAILABLE;
 
+            host->mono->mono_thread_attach(domain);
+
             filenameA = WtoA(filename);
             assembly = host->mono->mono_domain_assembly_open(domain, filenameA);
             HeapFree(GetProcessHeap(), 0, filenameA);
diff --git a/dlls/mscoree/metahost.c b/dlls/mscoree/metahost.c
index f877b1e..1296e37 100644
--- a/dlls/mscoree/metahost.c
+++ b/dlls/mscoree/metahost.c
@@ -186,6 +186,7 @@ static HRESULT load_mono(CLRRuntimeInfo *This, loaded_mono **result)
         LOAD_MONO_FUNCTION(mono_set_dirs);
         LOAD_MONO_FUNCTION(mono_stringify_assembly_name);
         LOAD_MONO_FUNCTION(mono_string_new);
+        LOAD_MONO_FUNCTION(mono_thread_attach);
 
         /* GLib imports obsoleted by the 2.0 ABI */
         if (This->mono_abi_version == 1)
diff --git a/dlls/mscoree/mscoree_private.h b/dlls/mscoree/mscoree_private.h
index d033275..62cf240 100644
--- a/dlls/mscoree/mscoree_private.h
+++ b/dlls/mscoree/mscoree_private.h
@@ -44,6 +44,7 @@ typedef struct _MonoObject MonoObject;
 typedef struct _MonoString MonoString;
 typedef struct _MonoMethod MonoMethod;
 typedef struct _MonoProfiler MonoProfiler;
+typedef struct _MonoThread MonoThread;
 
 typedef struct loaded_mono loaded_mono;
 typedef struct RuntimeHost RuntimeHost;
@@ -163,6 +164,7 @@ struct loaded_mono
     void (CDECL *mono_thread_suspend_all_other_threads)(void);
     void (CDECL *mono_threads_set_shutting_down)(void);
     MonoString* (CDECL *mono_string_new)(MonoDomain *domain, const char *str);
+    MonoThread* (CDECL *mono_thread_attach)(MonoDomain *domain);
 };
 
 /* loaded runtime interfaces */




More information about the wine-cvs mailing list