Commit d54b8007 authored by Vincent Povirk's avatar Vincent Povirk Committed by Alexandre Julliard

mscoree: Implement ICLRRuntimeInfo_GetInterface.

parent 0d1c6875
...@@ -29,20 +29,24 @@ ...@@ -29,20 +29,24 @@
#include "cor.h" #include "cor.h"
#include "mscoree.h" #include "mscoree.h"
#include "mscoree_private.h"
#include "wine/debug.h" #include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL( mscoree ); WINE_DEFAULT_DEBUG_CHANNEL( mscoree );
typedef struct _corruntimehost struct RuntimeHost
{ {
const struct ICorRuntimeHostVtbl *lpVtbl; const struct ICorRuntimeHostVtbl *lpVtbl;
const CLRRuntimeInfo *version;
const loaded_mono *mono;
LONG ref; LONG ref;
} corruntimehost; BOOL legacy; /* if True, this was created by create_corruntimehost, and Release frees it */
};
static inline corruntimehost *impl_from_ICorRuntimeHost( ICorRuntimeHost *iface ) static inline RuntimeHost *impl_from_ICorRuntimeHost( ICorRuntimeHost *iface )
{ {
return (corruntimehost *)((char*)iface - FIELD_OFFSET(corruntimehost, lpVtbl)); return (RuntimeHost *)((char*)iface - FIELD_OFFSET(RuntimeHost, lpVtbl));
} }
/*** IUnknown methods ***/ /*** IUnknown methods ***/
...@@ -50,7 +54,7 @@ static HRESULT WINAPI corruntimehost_QueryInterface(ICorRuntimeHost* iface, ...@@ -50,7 +54,7 @@ static HRESULT WINAPI corruntimehost_QueryInterface(ICorRuntimeHost* iface,
REFIID riid, REFIID riid,
void **ppvObject) void **ppvObject)
{ {
corruntimehost *This = impl_from_ICorRuntimeHost( iface ); RuntimeHost *This = impl_from_ICorRuntimeHost( iface );
TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject); TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
if ( IsEqualGUID( riid, &IID_ICorRuntimeHost ) || if ( IsEqualGUID( riid, &IID_ICorRuntimeHost ) ||
...@@ -71,19 +75,19 @@ static HRESULT WINAPI corruntimehost_QueryInterface(ICorRuntimeHost* iface, ...@@ -71,19 +75,19 @@ static HRESULT WINAPI corruntimehost_QueryInterface(ICorRuntimeHost* iface,
static ULONG WINAPI corruntimehost_AddRef(ICorRuntimeHost* iface) static ULONG WINAPI corruntimehost_AddRef(ICorRuntimeHost* iface)
{ {
corruntimehost *This = impl_from_ICorRuntimeHost( iface ); RuntimeHost *This = impl_from_ICorRuntimeHost( iface );
return InterlockedIncrement( &This->ref ); return InterlockedIncrement( &This->ref );
} }
static ULONG WINAPI corruntimehost_Release(ICorRuntimeHost* iface) static ULONG WINAPI corruntimehost_Release(ICorRuntimeHost* iface)
{ {
corruntimehost *This = impl_from_ICorRuntimeHost( iface ); RuntimeHost *This = impl_from_ICorRuntimeHost( iface );
ULONG ref; ULONG ref;
ref = InterlockedDecrement( &This->ref ); ref = InterlockedDecrement( &This->ref );
if ( ref == 0 ) if ( ref == 0 && This->legacy )
{ {
HeapFree( GetProcessHeap(), 0, This ); RuntimeHost_Destroy(This);
} }
return ref; return ref;
...@@ -271,18 +275,64 @@ static const struct ICorRuntimeHostVtbl corruntimehost_vtbl = ...@@ -271,18 +275,64 @@ static const struct ICorRuntimeHostVtbl corruntimehost_vtbl =
corruntimehost_CurrentDomain corruntimehost_CurrentDomain
}; };
IUnknown* create_corruntimehost(void) HRESULT RuntimeHost_Construct(const CLRRuntimeInfo *runtime_version,
const loaded_mono *loaded_mono, RuntimeHost** result)
{ {
corruntimehost *This; RuntimeHost *This;
This = HeapAlloc( GetProcessHeap(), 0, sizeof *This ); This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
if ( !This ) if ( !This )
return NULL; return E_OUTOFMEMORY;
This->lpVtbl = &corruntimehost_vtbl; This->lpVtbl = &corruntimehost_vtbl;
This->ref = 1; This->ref = 1;
This->version = runtime_version;
This->mono = loaded_mono;
This->legacy = FALSE;
return S_OK;
}
HRESULT RuntimeHost_GetInterface(RuntimeHost *This, REFCLSID clsid, REFIID riid, void **ppv)
{
IUnknown *unk;
if (IsEqualGUID(clsid, &CLSID_CorRuntimeHost))
unk = (IUnknown*)&This->lpVtbl;
else
unk = NULL;
if (unk)
return IUnknown_QueryInterface(unk, riid, ppv);
else
FIXME("not implemented for class %s\n", debugstr_guid(clsid));
return CLASS_E_CLASSNOTAVAILABLE;
}
HRESULT RuntimeHost_Destroy(RuntimeHost *This)
{
HeapFree( GetProcessHeap(), 0, This );
return S_OK;
}
IUnknown* create_corruntimehost(void)
{
RuntimeHost *This;
IUnknown *result;
if (FAILED(RuntimeHost_Construct(NULL, NULL, &This)))
return NULL;
This->legacy = TRUE;
if (FAILED(RuntimeHost_GetInterface(This, &CLSID_CorRuntimeHost, &IID_IUnknown, (void**)&result)))
{
RuntimeHost_Destroy(This);
return NULL;
}
FIXME("return iface %p\n", This); FIXME("return iface %p\n", result);
return (IUnknown*) &This->lpVtbl; return result;
} }
...@@ -43,16 +43,6 @@ static const WCHAR net_11_subdir[] = {'1','.','0',0}; ...@@ -43,16 +43,6 @@ static const WCHAR net_11_subdir[] = {'1','.','0',0};
static const WCHAR net_20_subdir[] = {'2','.','0',0}; static const WCHAR net_20_subdir[] = {'2','.','0',0};
static const WCHAR net_40_subdir[] = {'4','.','0',0}; static const WCHAR net_40_subdir[] = {'4','.','0',0};
struct CLRRuntimeInfo
{
const struct ICLRRuntimeInfoVtbl *ICLRRuntimeInfo_vtbl;
LPCWSTR mono_libdir;
DWORD major;
DWORD minor;
DWORD build;
int mono_abi_version;
};
const struct ICLRRuntimeInfoVtbl CLRRuntimeInfoVtbl; const struct ICLRRuntimeInfoVtbl CLRRuntimeInfoVtbl;
#define NUM_RUNTIMES 3 #define NUM_RUNTIMES 3
...@@ -75,6 +65,53 @@ static CRITICAL_SECTION_DEBUG runtime_list_cs_debug = ...@@ -75,6 +65,53 @@ static CRITICAL_SECTION_DEBUG runtime_list_cs_debug =
}; };
static CRITICAL_SECTION runtime_list_cs = { &runtime_list_cs_debug, -1, 0, 0, 0, 0 }; static CRITICAL_SECTION runtime_list_cs = { &runtime_list_cs_debug, -1, 0, 0, 0, 0 };
static HRESULT load_mono(CLRRuntimeInfo *This, loaded_mono **result)
{
/* FIXME: stub */
*result = NULL;
return S_OK;
}
static HRESULT CLRRuntimeInfo_GetRuntimeHost(CLRRuntimeInfo *This, RuntimeHost **result)
{
HRESULT hr = S_OK;
loaded_mono *ploaded_mono;
if (This->loaded_runtime)
{
*result = This->loaded_runtime;
return hr;
}
EnterCriticalSection(&runtime_list_cs);
if (!This->loaded_runtime)
goto end;
hr = load_mono(This, &ploaded_mono);
if (SUCCEEDED(hr))
hr = RuntimeHost_Construct(This, ploaded_mono, &This->loaded_runtime);
end:
LeaveCriticalSection(&runtime_list_cs);
if (SUCCEEDED(hr))
*result = This->loaded_runtime;
return hr;
}
void unload_all_runtimes(void)
{
int i;
for (i=0; i<NUM_RUNTIMES; i++)
if (runtimes[i].loaded_runtime)
RuntimeHost_Destroy(runtimes[i].loaded_runtime);
}
static HRESULT WINAPI CLRRuntimeInfo_QueryInterface(ICLRRuntimeInfo* iface, static HRESULT WINAPI CLRRuntimeInfo_QueryInterface(ICLRRuntimeInfo* iface,
REFIID riid, REFIID riid,
void **ppvObject) void **ppvObject)
...@@ -178,9 +215,18 @@ static HRESULT WINAPI CLRRuntimeInfo_GetProcAddress(ICLRRuntimeInfo* iface, ...@@ -178,9 +215,18 @@ static HRESULT WINAPI CLRRuntimeInfo_GetProcAddress(ICLRRuntimeInfo* iface,
static HRESULT WINAPI CLRRuntimeInfo_GetInterface(ICLRRuntimeInfo* iface, static HRESULT WINAPI CLRRuntimeInfo_GetInterface(ICLRRuntimeInfo* iface,
REFCLSID rclsid, REFIID riid, LPVOID *ppUnk) REFCLSID rclsid, REFIID riid, LPVOID *ppUnk)
{ {
FIXME("%p %s %s %p\n", iface, debugstr_guid(rclsid), debugstr_guid(riid), ppUnk); struct CLRRuntimeInfo *This = (struct CLRRuntimeInfo*)iface;
RuntimeHost *host;
HRESULT hr;
return E_NOTIMPL; TRACE("%p %s %s %p\n", iface, debugstr_guid(rclsid), debugstr_guid(riid), ppUnk);
hr = CLRRuntimeInfo_GetRuntimeHost(This, &host);
if (SUCCEEDED(hr))
hr = RuntimeHost_GetInterface(host, rclsid, riid, ppUnk);
return hr;
} }
static HRESULT WINAPI CLRRuntimeInfo_IsLoadable(ICLRRuntimeInfo* iface, static HRESULT WINAPI CLRRuntimeInfo_IsLoadable(ICLRRuntimeInfo* iface,
...@@ -404,6 +450,9 @@ static void find_runtimes(void) ...@@ -404,6 +450,9 @@ static void find_runtimes(void)
{ {
runtimes[i].mono_abi_version = abi_version; runtimes[i].mono_abi_version = abi_version;
strcpyW(runtimes[i].mono_path, mono_path);
strcpyW(runtimes[i].mscorlib_path, lib_path);
any_runtimes_found = TRUE; any_runtimes_found = TRUE;
} }
} }
......
...@@ -343,6 +343,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) ...@@ -343,6 +343,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
DisableThreadLibraryCalls(hinstDLL); DisableThreadLibraryCalls(hinstDLL);
break; break;
case DLL_PROCESS_DETACH: case DLL_PROCESS_DETACH:
unload_all_runtimes();
break; break;
} }
return TRUE; return TRUE;
......
...@@ -30,6 +30,21 @@ HRESULT assembly_create(ASSEMBLY **out, LPCWSTR file); ...@@ -30,6 +30,21 @@ HRESULT assembly_create(ASSEMBLY **out, LPCWSTR file);
HRESULT assembly_release(ASSEMBLY *assembly); HRESULT assembly_release(ASSEMBLY *assembly);
HRESULT assembly_get_runtime_version(ASSEMBLY *assembly, LPSTR *version); HRESULT assembly_get_runtime_version(ASSEMBLY *assembly, LPSTR *version);
typedef struct RuntimeHost RuntimeHost;
typedef struct CLRRuntimeInfo
{
const struct ICLRRuntimeInfoVtbl *ICLRRuntimeInfo_vtbl;
LPCWSTR mono_libdir;
DWORD major;
DWORD minor;
DWORD build;
int mono_abi_version;
WCHAR mono_path[MAX_PATH];
WCHAR mscorlib_path[MAX_PATH];
struct RuntimeHost *loaded_runtime;
} CLRRuntimeInfo;
/* Mono 2.6 embedding */ /* Mono 2.6 embedding */
typedef struct _MonoDomain MonoDomain; typedef struct _MonoDomain MonoDomain;
typedef struct _MonoAssembly MonoAssembly; typedef struct _MonoAssembly MonoAssembly;
...@@ -44,4 +59,18 @@ extern MonoDomain* (*mono_jit_init)(const char *file); ...@@ -44,4 +59,18 @@ extern MonoDomain* (*mono_jit_init)(const char *file);
extern int (*mono_jit_set_trace_options)(const char* options); extern int (*mono_jit_set_trace_options)(const char* options);
extern void (*mono_set_dirs)(const char *assembly_dir, const char *config_dir); extern void (*mono_set_dirs)(const char *assembly_dir, const char *config_dir);
typedef struct loaded_mono
{
} loaded_mono;
/* loaded runtime interfaces */
extern void unload_all_runtimes(void);
extern HRESULT RuntimeHost_Construct(const CLRRuntimeInfo *runtime_version,
const loaded_mono *loaded_mono, RuntimeHost** result);
extern HRESULT RuntimeHost_GetInterface(RuntimeHost *This, REFCLSID clsid, REFIID riid, void **ppv);
extern HRESULT RuntimeHost_Destroy(RuntimeHost *This);
#endif /* __MSCOREE_PRIVATE__ */ #endif /* __MSCOREE_PRIVATE__ */
...@@ -131,6 +131,8 @@ interface IHostControl : IUnknown ...@@ -131,6 +131,8 @@ interface IHostControl : IUnknown
[in] IUnknown* appDomainManager); [in] IUnknown* appDomainManager);
} }
cpp_quote("DEFINE_GUID(CLSID_CorRuntimeHost, 0xcb2f6723,0xab3a,0x11d2,0x9c,0x40,0x00,0xc0,0x4f,0xa3,0x0a,0x3e);")
[ [
uuid(CB2F6722-AB3A-11d2-9C40-00C04FA30A3E), uuid(CB2F6722-AB3A-11d2-9C40-00C04FA30A3E),
version(1.0), version(1.0),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment