From 5466fbafd9a1d05d3ff2f7bb4dc738317c31bf05 Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Sun, 26 Sep 2010 15:54:13 -0500 Subject: [PATCH 04/19] mscoree: Implement ICLRRuntimeInfo_GetInterface. --- dlls/mscoree/corruntimehost.c | 78 ++++++++++++++++++++++++++++++++------- dlls/mscoree/metahost.c | 73 +++++++++++++++++++++++++++++++------ dlls/mscoree/mscoree_main.c | 1 + dlls/mscoree/mscoree_private.h | 29 +++++++++++++++ include/mscoree.idl | 2 + 5 files changed, 157 insertions(+), 26 deletions(-) diff --git a/dlls/mscoree/corruntimehost.c b/dlls/mscoree/corruntimehost.c index 9de9bf5..794f1c8 100644 --- a/dlls/mscoree/corruntimehost.c +++ b/dlls/mscoree/corruntimehost.c @@ -29,20 +29,24 @@ #include "cor.h" #include "mscoree.h" +#include "mscoree_private.h" #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL( mscoree ); -typedef struct _corruntimehost +struct RuntimeHost { const struct ICorRuntimeHostVtbl *lpVtbl; + const CLRRuntimeInfo *version; + const loaded_mono *mono; 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 ***/ @@ -50,7 +54,7 @@ static HRESULT WINAPI corruntimehost_QueryInterface(ICorRuntimeHost* iface, REFIID riid, void **ppvObject) { - corruntimehost *This = impl_from_ICorRuntimeHost( iface ); + RuntimeHost *This = impl_from_ICorRuntimeHost( iface ); TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject); if ( IsEqualGUID( riid, &IID_ICorRuntimeHost ) || @@ -71,19 +75,19 @@ static HRESULT WINAPI corruntimehost_QueryInterface(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 ); } static ULONG WINAPI corruntimehost_Release(ICorRuntimeHost* iface) { - corruntimehost *This = impl_from_ICorRuntimeHost( iface ); + RuntimeHost *This = impl_from_ICorRuntimeHost( iface ); ULONG ref; ref = InterlockedDecrement( &This->ref ); - if ( ref == 0 ) + if ( ref == 0 && This->legacy ) { - HeapFree( GetProcessHeap(), 0, This ); + RuntimeHost_Destroy(This); } return ref; @@ -271,18 +275,64 @@ static const struct ICorRuntimeHostVtbl corruntimehost_vtbl = 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 ); if ( !This ) - return NULL; + return E_OUTOFMEMORY; This->lpVtbl = &corruntimehost_vtbl; 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; } diff --git a/dlls/mscoree/metahost.c b/dlls/mscoree/metahost.c index 159258b..f32afed 100644 --- a/dlls/mscoree/metahost.c +++ b/dlls/mscoree/metahost.c @@ -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_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; #define NUM_RUNTIMES 3 @@ -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 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