ReactOS 0.4.16-dev-2332-g4cba65d
corruntimehost.c File Reference
#include <assert.h>
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "winnls.h"
#include "winreg.h"
#include "ole2.h"
#include "shellapi.h"
#include "shlwapi.h"
#include "cor.h"
#include "mscoree.h"
#include "metahost.h"
#include "corhdr.h"
#include "cordebug.h"
#include "wine/list.h"
#include "mscoree_private.h"
#include "wine/debug.h"
#include "initguid.h"
Include dependency graph for corruntimehost.c:

Go to the source code of this file.

Classes

struct  DomainEntry
 
struct  dll_fixup
 
struct  comclassredirect_data
 
struct  clrclass_data
 
struct  vtable_fixup_thunk
 

Macros

#define COBJMACROS
 
#define CAN_FIXUP_VTABLE   0
 
#define CHARS_IN_GUID   39
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (mscoree)
 
 DEFINE_GUID (IID__AppDomain, 0x05f696dc, 0x2b29, 0x3663, 0xad, 0x8b, 0xc4, 0x38, 0x9c, 0xf2, 0xa7, 0x13)
 
static MonoDomaindomain_attach (MonoDomain *domain)
 
static void domain_restore (MonoDomain *prev_domain)
 
static HRESULT RuntimeHost_GetDefaultDomain (RuntimeHost *This, const WCHAR *config_path, MonoDomain **result)
 
static BOOL RuntimeHost_GetMethod (MonoDomain *domain, const char *assemblyname, const char *namespace, const char *typename, const char *methodname, int arg_count, MonoMethod **method)
 
static HRESULT RuntimeHost_Invoke (RuntimeHost *This, MonoDomain *domain, const char *assemblyname, const char *namespace, const char *typename, const char *methodname, MonoObject *obj, void **args, int arg_count, MonoObject **result)
 
static HRESULT RuntimeHost_DoInvoke (RuntimeHost *This, MonoDomain *domain, const char *methodname, MonoMethod *method, MonoObject *obj, void **args, MonoObject **result)
 
static HRESULT RuntimeHost_VirtualInvoke (RuntimeHost *This, MonoDomain *domain, const char *assemblyname, const char *namespace, const char *typename, const char *methodname, MonoObject *obj, void **args, int arg_count, MonoObject **result)
 
static HRESULT RuntimeHost_GetObjectForIUnknown (RuntimeHost *This, MonoDomain *domain, IUnknown *unk, MonoObject **obj)
 
static HRESULT RuntimeHost_AddDomain (RuntimeHost *This, const WCHAR *name, IUnknown *setup, IUnknown *evidence, MonoDomain **result)
 
static HRESULT RuntimeHost_GetIUnknownForDomain (RuntimeHost *This, MonoDomain *domain, IUnknown **punk)
 
void RuntimeHost_ExitProcess (RuntimeHost *This, INT exitcode)
 
static RuntimeHostimpl_from_ICLRRuntimeHost (ICLRRuntimeHost *iface)
 
static RuntimeHostimpl_from_ICorRuntimeHost (ICorRuntimeHost *iface)
 
static HRESULT WINAPI corruntimehost_QueryInterface (ICorRuntimeHost *iface, REFIID riid, void **ppvObject)
 
static ULONG WINAPI corruntimehost_AddRef (ICorRuntimeHost *iface)
 
static ULONG WINAPI corruntimehost_Release (ICorRuntimeHost *iface)
 
static HRESULT WINAPI corruntimehost_CreateLogicalThreadState (ICorRuntimeHost *iface)
 
static HRESULT WINAPI corruntimehost_DeleteLogicalThreadState (ICorRuntimeHost *iface)
 
static HRESULT WINAPI corruntimehost_SwitchInLogicalThreadState (ICorRuntimeHost *iface, DWORD *fiberCookie)
 
static HRESULT WINAPI corruntimehost_SwitchOutLogicalThreadState (ICorRuntimeHost *iface, DWORD **fiberCookie)
 
static HRESULT WINAPI corruntimehost_LocksHeldByLogicalThread (ICorRuntimeHost *iface, DWORD *pCount)
 
static HRESULT WINAPI corruntimehost_MapFile (ICorRuntimeHost *iface, HANDLE hFile, HMODULE *mapAddress)
 
static HRESULT WINAPI corruntimehost_GetConfiguration (ICorRuntimeHost *iface, ICorConfiguration **pConfiguration)
 
static HRESULT WINAPI corruntimehost_Start (ICorRuntimeHost *iface)
 
static HRESULT WINAPI corruntimehost_Stop (ICorRuntimeHost *iface)
 
static HRESULT WINAPI corruntimehost_CreateDomain (ICorRuntimeHost *iface, LPCWSTR friendlyName, IUnknown *identityArray, IUnknown **appDomain)
 
static HRESULT WINAPI corruntimehost_GetDefaultDomain (ICorRuntimeHost *iface, IUnknown **pAppDomain)
 
static HRESULT WINAPI corruntimehost_EnumDomains (ICorRuntimeHost *iface, HDOMAINENUM *hEnum)
 
static HRESULT WINAPI corruntimehost_NextDomain (ICorRuntimeHost *iface, HDOMAINENUM hEnum, IUnknown **appDomain)
 
static HRESULT WINAPI corruntimehost_CloseEnum (ICorRuntimeHost *iface, HDOMAINENUM hEnum)
 
static HRESULT WINAPI corruntimehost_CreateDomainEx (ICorRuntimeHost *iface, LPCWSTR friendlyName, IUnknown *setup, IUnknown *evidence, IUnknown **appDomain)
 
static HRESULT WINAPI corruntimehost_CreateDomainSetup (ICorRuntimeHost *iface, IUnknown **appDomainSetup)
 
static HRESULT WINAPI corruntimehost_CreateEvidence (ICorRuntimeHost *iface, IUnknown **evidence)
 
static HRESULT WINAPI corruntimehost_UnloadDomain (ICorRuntimeHost *iface, IUnknown *appDomain)
 
static HRESULT WINAPI corruntimehost_CurrentDomain (ICorRuntimeHost *iface, IUnknown **appDomain)
 
static HRESULT WINAPI CLRRuntimeHost_QueryInterface (ICLRRuntimeHost *iface, REFIID riid, void **ppvObject)
 
static ULONG WINAPI CLRRuntimeHost_AddRef (ICLRRuntimeHost *iface)
 
static ULONG WINAPI CLRRuntimeHost_Release (ICLRRuntimeHost *iface)
 
static HRESULT WINAPI CLRRuntimeHost_Start (ICLRRuntimeHost *iface)
 
static HRESULT WINAPI CLRRuntimeHost_Stop (ICLRRuntimeHost *iface)
 
static HRESULT WINAPI CLRRuntimeHost_SetHostControl (ICLRRuntimeHost *iface, IHostControl *pHostControl)
 
static HRESULT WINAPI CLRRuntimeHost_GetCLRControl (ICLRRuntimeHost *iface, ICLRControl **pCLRControl)
 
static HRESULT WINAPI CLRRuntimeHost_UnloadAppDomain (ICLRRuntimeHost *iface, DWORD dwAppDomainId, BOOL fWaitUntilDone)
 
static HRESULT WINAPI CLRRuntimeHost_ExecuteInAppDomain (ICLRRuntimeHost *iface, DWORD dwAppDomainId, FExecuteInAppDomainCallback pCallback, void *cookie)
 
static HRESULT WINAPI CLRRuntimeHost_GetCurrentAppDomainId (ICLRRuntimeHost *iface, DWORD *pdwAppDomainId)
 
static HRESULT WINAPI CLRRuntimeHost_ExecuteApplication (ICLRRuntimeHost *iface, LPCWSTR pwzAppFullName, DWORD dwManifestPaths, LPCWSTR *ppwzManifestPaths, DWORD dwActivationData, LPCWSTR *ppwzActivationData, int *pReturnValue)
 
static HRESULT WINAPI CLRRuntimeHost_ExecuteInDefaultAppDomain (ICLRRuntimeHost *iface, LPCWSTR pwzAssemblyPath, LPCWSTR pwzTypeName, LPCWSTR pwzMethodName, LPCWSTR pwzArgument, DWORD *pReturnValue)
 
HRESULT RuntimeHost_CreateManagedInstance (RuntimeHost *This, LPCWSTR name, MonoDomain *domain, MonoObject **result)
 
HRESULT RuntimeHost_GetIUnknownForObject (RuntimeHost *This, MonoObject *obj, IUnknown **ppUnk)
 
static void get_utf8_args (int *argc, char ***argv)
 
DWORD WINAPI GetTokenForVTableEntry (HINSTANCE hinst, BYTE **ppVTEntry)
 
static void CDECL ReallyFixupVTable (struct dll_fixup *fixup)
 
static void FixupVTableEntry (HMODULE hmodule, VTableFixup *vtable_fixup)
 
static void FixupVTable_Assembly (HMODULE hmodule, ASSEMBLY *assembly)
 
static void FixupVTable (HMODULE hmodule)
 
__int32 WINAPI _CorExeMain (void)
 
BOOL WINAPI _CorDllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
 
void runtimehost_init (void)
 
void runtimehost_uninit (void)
 
HRESULT RuntimeHost_Construct (CLRRuntimeInfo *runtime_version, RuntimeHost **result)
 
HRESULT RuntimeHost_GetInterface (RuntimeHost *This, REFCLSID clsid, REFIID riid, void **ppv)
 
static BOOL try_create_registration_free_com (REFIID clsid, WCHAR *classname, UINT classname_size, WCHAR *filename, UINT filename_size)
 
HRESULT create_monodata (REFCLSID clsid, LPVOID *ppObj)
 

Variables

static HANDLE dll_fixup_heap
 
static CRITICAL_SECTION fixup_list_cs = { &fixup_list_cs_debug, -1, 0, 0, 0, 0 }
 
static CRITICAL_SECTION_DEBUG fixup_list_cs_debug
 
static struct list dll_fixups
 
WCHAR ** private_path = NULL
 
static const struct ICorRuntimeHostVtbl corruntimehost_vtbl
 
static const struct ICLRRuntimeHostVtbl CLRHostVtbl
 
static const struct vtable_fixup_thunk thunk_template = {0}
 

Macro Definition Documentation

◆ CAN_FIXUP_VTABLE

#define CAN_FIXUP_VTABLE   0

Definition at line 1217 of file corruntimehost.c.

◆ CHARS_IN_GUID

#define CHARS_IN_GUID   39

Definition at line 1730 of file corruntimehost.c.

◆ COBJMACROS

#define COBJMACROS

Definition at line 20 of file corruntimehost.c.

Function Documentation

◆ _CorDllMain()

BOOL WINAPI _CorDllMain ( HINSTANCE  hinstDLL,
DWORD  fdwReason,
LPVOID  lpvReserved 
)

Definition at line 1546 of file corruntimehost.c.

1547{
1549 HRESULT hr;
1550
1551 TRACE("(%p, %ld, %p)\n", hinstDLL, fdwReason, lpvReserved);
1552
1553 hr = assembly_from_hmodule(&assembly, hinstDLL);
1554 if (SUCCEEDED(hr))
1555 {
1556 NativeEntryPointFunc NativeEntryPoint=NULL;
1557
1558 assembly_get_native_entrypoint(assembly, &NativeEntryPoint);
1560 {
1561 if (!NativeEntryPoint)
1562 DisableThreadLibraryCalls(hinstDLL);
1564 }
1566 /* FIXME: clean up the vtables on DLL_PROCESS_DETACH */
1567 if (NativeEntryPoint)
1568 return NativeEntryPoint(hinstDLL, fdwReason, lpvReserved);
1569 }
1570 else
1571 ERR("failed to read CLR headers, hr=%lx\n", hr);
1572
1573 return TRUE;
1574}
static DWORD const fdwReason
#define ERR(fmt,...)
Definition: precomp.h:57
static void FixupVTable_Assembly(HMODULE hmodule, ASSEMBLY *assembly)
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
HRESULT assembly_release(ASSEMBLY *assembly)
Definition: assembly.c:694
#define SUCCEEDED(hr)
Definition: intsafe.h:50
static IN DWORD IN LPVOID lpvReserved
HRESULT assembly_get_native_entrypoint(ASSEMBLY *assembly, NativeEntryPointFunc *func)
Definition: assembly.c:303
HRESULT assembly_from_hmodule(ASSEMBLY **out, HMODULE hmodule)
Definition: assembly.c:244
BOOL(WINAPI * NativeEntryPointFunc)(HINSTANCE, DWORD, LPVOID)
HRESULT hr
Definition: shlfolder.c:183
#define TRACE(s)
Definition: solgame.cpp:4

◆ _CorExeMain()

__int32 WINAPI _CorExeMain ( void  )

Definition at line 1423 of file corruntimehost.c.

1424{
1425 static const WCHAR dotconfig[] = {'.','c','o','n','f','i','g',0};
1426 static const WCHAR scW[] = {';',0};
1427 int exit_code;
1428 int argc;
1429 char **argv;
1434 WCHAR filename[MAX_PATH], config_file[MAX_PATH], *temp, **priv_path;
1435 SIZE_T config_file_dir_size;
1436 char *filenameA;
1437 ICLRRuntimeInfo *info;
1439 parsed_config_file parsed_config;
1440 HRESULT hr;
1441 int i, number_of_private_paths = 0;
1442
1444
1446
1447 TRACE("%s argc=%i\n", debugstr_w(filename), argc);
1448
1450 if (!filenameA)
1451 {
1452 free(argv);
1453 return -1;
1454 }
1455
1457
1458 wcscpy(config_file, filename);
1459 wcscat(config_file, dotconfig);
1460
1461 hr = parse_config_file(config_file, &parsed_config);
1462 if (SUCCEEDED(hr) && parsed_config.private_path && parsed_config.private_path[0])
1463 {
1464#ifndef __REACTOS__
1465 WCHAR *save;
1466#endif
1467 for(i = 0; parsed_config.private_path[i] != 0; i++)
1468 if (parsed_config.private_path[i] == ';') number_of_private_paths++;
1469 if (parsed_config.private_path[wcslen(parsed_config.private_path) - 1] != ';') number_of_private_paths++;
1470 config_file_dir_size = (wcsrchr(config_file, '\\') - config_file) + 1;
1471 priv_path = malloc((number_of_private_paths + 1) * sizeof(WCHAR *));
1472 /* wcstok ignores trailing semicolons */
1473#ifdef __REACTOS__
1474 temp = wcstok(parsed_config.private_path, scW);
1475#else
1476 temp = wcstok_s(parsed_config.private_path, scW, &save);
1477#endif
1478 for (i = 0; i < number_of_private_paths; i++)
1479 {
1480 priv_path[i] = malloc((config_file_dir_size + wcslen(temp) + 1) * sizeof(WCHAR));
1481 memcpy(priv_path[i], config_file, config_file_dir_size * sizeof(WCHAR));
1482 wcscpy(priv_path[i] + config_file_dir_size, temp);
1483#ifdef __REACTOS__
1484 temp = wcstok(NULL, scW);
1485#else
1486 temp = wcstok_s(NULL, scW, &save);
1487#endif
1488 }
1489 priv_path[number_of_private_paths] = NULL;
1490 if (InterlockedCompareExchangePointer((void **)&private_path, priv_path, NULL))
1491 ERR("private_path was already set\n");
1492 }
1493
1494 free_parsed_config_file(&parsed_config);
1495
1497
1498 if (SUCCEEDED(hr))
1499 {
1501
1502 if (SUCCEEDED(hr))
1503 hr = RuntimeHost_GetDefaultDomain(host, config_file, &domain);
1504
1505 if (SUCCEEDED(hr))
1506 {
1508 filenameA, 1, &status);
1509
1510 if (image)
1512
1513 if (assembly)
1514 {
1515 mono_callspec_set_assembly(assembly);
1516
1517 exit_code = mono_jit_exec(domain, assembly, argc, argv);
1518 }
1519 else
1520 {
1521 ERR("couldn't load %s, status=%d\n", debugstr_w(filename), status);
1522 exit_code = -1;
1523 }
1524 }
1525 else
1526 exit_code = -1;
1527
1528 ICLRRuntimeInfo_Release(info);
1529 }
1530 else
1531 exit_code = -1;
1532
1533 free(argv);
1534
1535 if (domain)
1536 {
1537 mono_thread_manage();
1538 mono_runtime_quit();
1539 }
1540
1542
1543 return exit_code;
1544}
static void FixupVTable(HMODULE hmodule)
static HRESULT RuntimeHost_GetDefaultDomain(RuntimeHost *This, const WCHAR *config_path, MonoDomain **result)
static void get_utf8_args(int *argc, char ***argv)
WCHAR ** private_path
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define FALSE
Definition: types.h:117
#define wcsrchr
Definition: compat.h:16
#define MAX_PATH
Definition: compat.h:34
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:600
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
VOID WINAPI ExitProcess(IN UINT uExitCode)
Definition: proc.c:1331
HRESULT parse_config_file(LPCWSTR filename, parsed_config_file *result)
Definition: config.c:678
void free_parsed_config_file(parsed_config_file *file)
Definition: config.c:696
HRESULT get_runtime_info(LPCWSTR exefile, LPCWSTR version, LPCWSTR config_file, IStream *config_stream, DWORD startup_flags, DWORD runtimeinfo_flags, BOOL legacy, ICLRRuntimeInfo **result)
Definition: metahost.c:1904
MonoImage *CDECL * mono_image_open_from_module_handle(HMODULE module_handle, char *fname, UINT has_entry_point, MonoImageOpenStatus *status)
MonoAssembly int argc
Definition: metahost.c:107
MonoAssembly *CDECL * mono_assembly_load_from(MonoImage *image, const char *fname, MonoImageOpenStatus *status)
HRESULT ICLRRuntimeInfo_GetRuntimeHost(ICLRRuntimeInfo *iface, RuntimeHost **result)
Definition: metahost.c:703
_ACRTIMP wchar_t *__cdecl wcstok_s(wchar_t *, const wchar_t *, wchar_t **)
Definition: wcs.c:2031
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2983
_ACRTIMP wchar_t *__cdecl wcstok(wchar_t *, const wchar_t *)
Definition: wcs.c:2065
GLeglImageOES image
Definition: gl.h:2204
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define InterlockedCompareExchangePointer
Definition: interlocked.h:144
const char * filename
Definition: ioapi.h:137
#define debugstr_w
Definition: kernel32.h:32
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static UINT exit_code
Definition: process.c:80
static CHAR filenameA[MAX_PATH]
Definition: storage32.c:35
#define argv
Definition: mplay32.c:18
char * WtoA(LPCWSTR wstr)
Definition: mscoree_main.c:63
struct _MonoAssembly MonoAssembly
struct _MonoImage MonoImage
MonoImageOpenStatus
struct _MonoDomain MonoDomain
static calc_node_t temp
Definition: rpn_ieee.c:38
wcscat
wcscpy
Definition: cookie.c:42
Definition: txthost.c:37
Definition: ps.c:97
ULONG_PTR SIZE_T
Definition: typedefs.h:80
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ CLRRuntimeHost_AddRef()

static ULONG WINAPI CLRRuntimeHost_AddRef ( ICLRRuntimeHost iface)
static

Definition at line 803 of file corruntimehost.c.

804{
806 return ICorRuntimeHost_AddRef(&This->ICorRuntimeHost_iface);
807}
static RuntimeHost * impl_from_ICLRRuntimeHost(ICLRRuntimeHost *iface)

◆ CLRRuntimeHost_ExecuteApplication()

static HRESULT WINAPI CLRRuntimeHost_ExecuteApplication ( ICLRRuntimeHost iface,
LPCWSTR  pwzAppFullName,
DWORD  dwManifestPaths,
LPCWSTR ppwzManifestPaths,
DWORD  dwActivationData,
LPCWSTR ppwzActivationData,
int pReturnValue 
)
static

Definition at line 866 of file corruntimehost.c.

869{
870 FIXME("(%p,%s,%lu,%lu)\n", iface, debugstr_w(pwzAppFullName), dwManifestPaths, dwActivationData);
871 return E_NOTIMPL;
872}
#define FIXME(fmt,...)
Definition: precomp.h:53
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ CLRRuntimeHost_ExecuteInAppDomain()

static HRESULT WINAPI CLRRuntimeHost_ExecuteInAppDomain ( ICLRRuntimeHost iface,
DWORD  dwAppDomainId,
FExecuteInAppDomainCallback  pCallback,
void cookie 
)
static

Definition at line 852 of file corruntimehost.c.

854{
855 FIXME("(%p,%lu,%p,%p)\n", iface, dwAppDomainId, pCallback, cookie);
856 return E_NOTIMPL;
857}
FxPnpStateCallbackInfo * pCallback
Definition: cookie.c:34

◆ CLRRuntimeHost_ExecuteInDefaultAppDomain()

static HRESULT WINAPI CLRRuntimeHost_ExecuteInDefaultAppDomain ( ICLRRuntimeHost iface,
LPCWSTR  pwzAssemblyPath,
LPCWSTR  pwzTypeName,
LPCWSTR  pwzMethodName,
LPCWSTR  pwzArgument,
DWORD pReturnValue 
)
static

Definition at line 874 of file corruntimehost.c.

877{
879 HRESULT hr;
880 MonoDomain *domain, *prev_domain;
883 char *filenameA = NULL, *classA = NULL, *methodA = NULL;
884 char *argsA = NULL, *ns;
885
886 TRACE("(%p,%s,%s,%s,%s)\n", iface, debugstr_w(pwzAssemblyPath),
887 debugstr_w(pwzTypeName), debugstr_w(pwzMethodName), debugstr_w(pwzArgument));
888
890
891 if (FAILED(hr))
892 return hr;
893
894 prev_domain = domain_attach(domain);
895
896 if (SUCCEEDED(hr))
897 {
898 filenameA = WtoA(pwzAssemblyPath);
899 if (!filenameA) hr = E_OUTOFMEMORY;
900 }
901
902 if (SUCCEEDED(hr))
903 {
904 classA = WtoA(pwzTypeName);
905 if (!classA) hr = E_OUTOFMEMORY;
906 }
907
908 if (SUCCEEDED(hr))
909 {
910 ns = strrchr(classA, '.');
911 if (ns)
912 *ns = '\0';
913 else
915 }
916
917 if (SUCCEEDED(hr))
918 {
919 methodA = WtoA(pwzMethodName);
920 if (!methodA) hr = E_OUTOFMEMORY;
921 }
922
923 /* The .NET function we are calling has the following declaration
924 * public static int functionName(String param)
925 */
926 if (SUCCEEDED(hr))
927 {
928 argsA = WtoA(pwzArgument);
929 if (!argsA) hr = E_OUTOFMEMORY;
930 }
931
932 if (SUCCEEDED(hr))
933 {
934 str = mono_string_new(domain, argsA);
935 if (!str) hr = E_OUTOFMEMORY;
936 }
937
938 if (SUCCEEDED(hr))
939 {
940 hr = RuntimeHost_Invoke(This, domain, filenameA, classA, ns+1, methodA,
941 NULL, (void**)&str, 1, &result);
942 }
943
944 if (SUCCEEDED(hr))
945 *pReturnValue = *(DWORD*)mono_object_unbox(result);
946
947 domain_restore(prev_domain);
948
950 free(classA);
951 free(argsA);
952 free(methodA);
953
954 return hr;
955}
static MonoDomain * domain_attach(MonoDomain *domain)
static void domain_restore(MonoDomain *prev_domain)
static HRESULT RuntimeHost_Invoke(RuntimeHost *This, MonoDomain *domain, const char *assemblyname, const char *namespace, const char *typename, const char *methodname, MonoObject *obj, void **args, int arg_count, MonoObject **result)
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
MonoString *CDECL * mono_string_new(MonoDomain *domain, const char *str)
void *CDECL * mono_object_unbox(MonoObject *obj)
_ACRTIMP char *__cdecl strrchr(const char *, int)
Definition: string.c:3298
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint64EXT * result
Definition: glext.h:11304
#define FAILED(hr)
Definition: intsafe.h:51
struct _MonoObject MonoObject
struct _MonoString MonoString
const WCHAR * str
Definition: mxnamespace.c:38

◆ CLRRuntimeHost_GetCLRControl()

static HRESULT WINAPI CLRRuntimeHost_GetCLRControl ( ICLRRuntimeHost iface,
ICLRControl **  pCLRControl 
)
static

Definition at line 838 of file corruntimehost.c.

840{
841 FIXME("(%p,%p)\n", iface, pCLRControl);
842 return E_NOTIMPL;
843}

◆ CLRRuntimeHost_GetCurrentAppDomainId()

static HRESULT WINAPI CLRRuntimeHost_GetCurrentAppDomainId ( ICLRRuntimeHost iface,
DWORD pdwAppDomainId 
)
static

Definition at line 859 of file corruntimehost.c.

861{
862 FIXME("(%p,%p)\n", iface, pdwAppDomainId);
863 return E_NOTIMPL;
864}

◆ CLRRuntimeHost_QueryInterface()

static HRESULT WINAPI CLRRuntimeHost_QueryInterface ( ICLRRuntimeHost iface,
REFIID  riid,
void **  ppvObject 
)
static

Definition at line 780 of file corruntimehost.c.

783{
785 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
786
787 if ( IsEqualGUID( riid, &IID_ICLRRuntimeHost ) ||
789 {
790 *ppvObject = iface;
791 }
792 else
793 {
794 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
795 return E_NOINTERFACE;
796 }
797
798 ICLRRuntimeHost_AddRef( iface );
799
800 return S_OK;
801}
const GUID IID_IUnknown
REFIID riid
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
#define debugstr_guid
Definition: kernel32.h:35
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define E_NOINTERFACE
Definition: winerror.h:3479

◆ CLRRuntimeHost_Release()

static ULONG WINAPI CLRRuntimeHost_Release ( ICLRRuntimeHost iface)
static

Definition at line 809 of file corruntimehost.c.

810{
812 return ICorRuntimeHost_Release(&This->ICorRuntimeHost_iface);
813}

◆ CLRRuntimeHost_SetHostControl()

static HRESULT WINAPI CLRRuntimeHost_SetHostControl ( ICLRRuntimeHost iface,
IHostControl pHostControl 
)
static

Definition at line 831 of file corruntimehost.c.

833{
834 FIXME("(%p,%p)\n", iface, pHostControl);
835 return E_NOTIMPL;
836}

◆ CLRRuntimeHost_Start()

static HRESULT WINAPI CLRRuntimeHost_Start ( ICLRRuntimeHost iface)
static

Definition at line 815 of file corruntimehost.c.

816{
819
820 TRACE("%p\n", This);
821
823}

◆ CLRRuntimeHost_Stop()

static HRESULT WINAPI CLRRuntimeHost_Stop ( ICLRRuntimeHost iface)
static

Definition at line 825 of file corruntimehost.c.

826{
827 FIXME("(%p)\n", iface);
828 return E_NOTIMPL;
829}

◆ CLRRuntimeHost_UnloadAppDomain()

static HRESULT WINAPI CLRRuntimeHost_UnloadAppDomain ( ICLRRuntimeHost iface,
DWORD  dwAppDomainId,
BOOL  fWaitUntilDone 
)
static

Definition at line 845 of file corruntimehost.c.

847{
848 FIXME("(%p,%lu,%i)\n", iface, dwAppDomainId, fWaitUntilDone);
849 return E_NOTIMPL;
850}

◆ corruntimehost_AddRef()

static ULONG WINAPI corruntimehost_AddRef ( ICorRuntimeHost iface)
static

Definition at line 530 of file corruntimehost.c.

531{
533
534 return InterlockedIncrement( &This->ref );
535}
#define InterlockedIncrement
Definition: armddk.h:53
static RuntimeHost * impl_from_ICorRuntimeHost(ICorRuntimeHost *iface)

◆ corruntimehost_CloseEnum()

static HRESULT WINAPI corruntimehost_CloseEnum ( ICorRuntimeHost iface,
HDOMAINENUM  hEnum 
)
static

Definition at line 667 of file corruntimehost.c.

670{
671 FIXME("stub %p\n", iface);
672 return E_NOTIMPL;
673}

◆ corruntimehost_CreateDomain()

static HRESULT WINAPI corruntimehost_CreateDomain ( ICorRuntimeHost iface,
LPCWSTR  friendlyName,
IUnknown identityArray,
IUnknown **  appDomain 
)
static

Definition at line 621 of file corruntimehost.c.

626{
627 return ICorRuntimeHost_CreateDomainEx(iface, friendlyName, NULL, NULL, appDomain);
628}

◆ corruntimehost_CreateDomainEx()

static HRESULT WINAPI corruntimehost_CreateDomainEx ( ICorRuntimeHost iface,
LPCWSTR  friendlyName,
IUnknown setup,
IUnknown evidence,
IUnknown **  appDomain 
)
static

Definition at line 675 of file corruntimehost.c.

681{
683 HRESULT hr;
685
686 if (!friendlyName || !appDomain)
687 {
688 return E_POINTER;
689 }
690 if (!is_mono_started)
691 {
692 return E_FAIL;
693 }
694
695 TRACE("(%p)\n", iface);
696
697 hr = RuntimeHost_AddDomain(This, friendlyName, setup, evidence, &domain);
698
699 if (SUCCEEDED(hr))
700 {
702 }
703
704 return hr;
705}
static HRESULT RuntimeHost_GetIUnknownForDomain(RuntimeHost *This, MonoDomain *domain, IUnknown **punk)
static HRESULT RuntimeHost_AddDomain(RuntimeHost *This, const WCHAR *name, IUnknown *setup, IUnknown *evidence, MonoDomain **result)
#define E_FAIL
Definition: ddrawi.h:102
BOOL is_mono_started
Definition: metahost.c:80
static BOOL setup(void)
Definition: enum_files.c:97
#define E_POINTER
Definition: winerror.h:3480

◆ corruntimehost_CreateDomainSetup()

static HRESULT WINAPI corruntimehost_CreateDomainSetup ( ICorRuntimeHost iface,
IUnknown **  appDomainSetup 
)
static

Definition at line 707 of file corruntimehost.c.

710{
712 HRESULT hr;
715 static const WCHAR classnameW[] = {'S','y','s','t','e','m','.','A','p','p','D','o','m','a','i','n','S','e','t','u','p',',','m','s','c','o','r','l','i','b',0};
716
717 TRACE("(%p)\n", iface);
718
720
721 if (SUCCEEDED(hr))
723
724 if (SUCCEEDED(hr))
725 hr = RuntimeHost_GetIUnknownForObject(This, obj, appDomainSetup);
726
727 return hr;
728}
HRESULT RuntimeHost_CreateManagedInstance(RuntimeHost *This, LPCWSTR name, MonoDomain *domain, MonoObject **result)
HRESULT RuntimeHost_GetIUnknownForObject(RuntimeHost *This, MonoObject *obj, IUnknown **ppUnk)

◆ corruntimehost_CreateEvidence()

static HRESULT WINAPI corruntimehost_CreateEvidence ( ICorRuntimeHost iface,
IUnknown **  evidence 
)
static

Definition at line 730 of file corruntimehost.c.

733{
734 FIXME("stub %p\n", iface);
735 return E_NOTIMPL;
736}

◆ corruntimehost_CreateLogicalThreadState()

static HRESULT WINAPI corruntimehost_CreateLogicalThreadState ( ICorRuntimeHost iface)
static

Definition at line 548 of file corruntimehost.c.

550{
551 FIXME("stub %p\n", iface);
552 return E_NOTIMPL;
553}

◆ corruntimehost_CurrentDomain()

static HRESULT WINAPI corruntimehost_CurrentDomain ( ICorRuntimeHost iface,
IUnknown **  appDomain 
)
static

Definition at line 746 of file corruntimehost.c.

749{
750 FIXME("stub %p\n", iface);
751 return E_NOTIMPL;
752}

◆ corruntimehost_DeleteLogicalThreadState()

static HRESULT WINAPI corruntimehost_DeleteLogicalThreadState ( ICorRuntimeHost iface)
static

Definition at line 555 of file corruntimehost.c.

557{
558 FIXME("stub %p\n", iface);
559 return E_NOTIMPL;
560}

◆ corruntimehost_EnumDomains()

static HRESULT WINAPI corruntimehost_EnumDomains ( ICorRuntimeHost iface,
HDOMAINENUM hEnum 
)
static

Definition at line 650 of file corruntimehost.c.

653{
654 FIXME("stub %p\n", iface);
655 return E_NOTIMPL;
656}

◆ corruntimehost_GetConfiguration()

static HRESULT WINAPI corruntimehost_GetConfiguration ( ICorRuntimeHost iface,
ICorConfiguration **  pConfiguration 
)
static

Definition at line 595 of file corruntimehost.c.

598{
599 FIXME("stub %p\n", iface);
600 return E_NOTIMPL;
601}

◆ corruntimehost_GetDefaultDomain()

static HRESULT WINAPI corruntimehost_GetDefaultDomain ( ICorRuntimeHost iface,
IUnknown **  pAppDomain 
)
static

Definition at line 630 of file corruntimehost.c.

633{
635 HRESULT hr;
637
638 TRACE("(%p)\n", iface);
639
641
642 if (SUCCEEDED(hr))
643 {
645 }
646
647 return hr;
648}

◆ corruntimehost_LocksHeldByLogicalThread()

static HRESULT WINAPI corruntimehost_LocksHeldByLogicalThread ( ICorRuntimeHost iface,
DWORD pCount 
)
static

Definition at line 578 of file corruntimehost.c.

581{
582 FIXME("stub %p\n", iface);
583 return E_NOTIMPL;
584}

◆ corruntimehost_MapFile()

static HRESULT WINAPI corruntimehost_MapFile ( ICorRuntimeHost iface,
HANDLE  hFile,
HMODULE mapAddress 
)
static

Definition at line 586 of file corruntimehost.c.

590{
591 FIXME("stub %p\n", iface);
592 return E_NOTIMPL;
593}

◆ corruntimehost_NextDomain()

static HRESULT WINAPI corruntimehost_NextDomain ( ICorRuntimeHost iface,
HDOMAINENUM  hEnum,
IUnknown **  appDomain 
)
static

Definition at line 658 of file corruntimehost.c.

662{
663 FIXME("stub %p\n", iface);
664 return E_NOTIMPL;
665}

◆ corruntimehost_QueryInterface()

static HRESULT WINAPI corruntimehost_QueryInterface ( ICorRuntimeHost iface,
REFIID  riid,
void **  ppvObject 
)
static

Definition at line 507 of file corruntimehost.c.

510{
512 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
513
514 if ( IsEqualGUID( riid, &IID_ICorRuntimeHost ) ||
516 {
517 *ppvObject = iface;
518 }
519 else
520 {
521 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
522 return E_NOINTERFACE;
523 }
524
525 ICorRuntimeHost_AddRef( iface );
526
527 return S_OK;
528}

◆ corruntimehost_Release()

static ULONG WINAPI corruntimehost_Release ( ICorRuntimeHost iface)
static

Definition at line 537 of file corruntimehost.c.

538{
540 ULONG ref;
541
542 ref = InterlockedDecrement( &This->ref );
543
544 return ref;
545}
#define InterlockedDecrement
Definition: armddk.h:52
Definition: send.c:48
uint32_t ULONG
Definition: typedefs.h:59

◆ corruntimehost_Start()

static HRESULT WINAPI corruntimehost_Start ( ICorRuntimeHost iface)
static

Definition at line 603 of file corruntimehost.c.

605{
608
609 TRACE("%p\n", This);
610
612}

◆ corruntimehost_Stop()

static HRESULT WINAPI corruntimehost_Stop ( ICorRuntimeHost iface)
static

Definition at line 614 of file corruntimehost.c.

616{
617 FIXME("stub %p\n", iface);
618 return E_NOTIMPL;
619}

◆ corruntimehost_SwitchInLogicalThreadState()

static HRESULT WINAPI corruntimehost_SwitchInLogicalThreadState ( ICorRuntimeHost iface,
DWORD fiberCookie 
)
static

Definition at line 562 of file corruntimehost.c.

565{
566 FIXME("stub %p\n", iface);
567 return E_NOTIMPL;
568}

◆ corruntimehost_SwitchOutLogicalThreadState()

static HRESULT WINAPI corruntimehost_SwitchOutLogicalThreadState ( ICorRuntimeHost iface,
DWORD **  fiberCookie 
)
static

Definition at line 570 of file corruntimehost.c.

573{
574 FIXME("stub %p\n", iface);
575 return E_NOTIMPL;
576}

◆ corruntimehost_UnloadDomain()

static HRESULT WINAPI corruntimehost_UnloadDomain ( ICorRuntimeHost iface,
IUnknown appDomain 
)
static

Definition at line 738 of file corruntimehost.c.

741{
742 FIXME("stub %p\n", iface);
743 return E_NOTIMPL;
744}

◆ create_monodata()

HRESULT create_monodata ( REFCLSID  clsid,
LPVOID ppObj 
)

Definition at line 1732 of file corruntimehost.c.

1733{
1734 static const WCHAR wszFileSlash[] = L"file:///";
1735 static const WCHAR wszCLSIDSlash[] = L"CLSID\\";
1736 static const WCHAR wszInprocServer32[] = L"\\InprocServer32";
1737 WCHAR path[CHARS_IN_GUID + ARRAY_SIZE(wszCLSIDSlash) + ARRAY_SIZE(wszInprocServer32) - 1];
1740 ICLRRuntimeInfo *info = NULL;
1742 HRESULT hr;
1743 HKEY key, subkey;
1744 LONG res;
1745 int offset = 0;
1747 DWORD numKeys, keyLength;
1748 WCHAR codebase[MAX_PATH + 8];
1749 WCHAR classname[350], subkeyName[256];
1751 DWORD dwBufLen;
1752
1753 lstrcpyW(path, wszCLSIDSlash);
1754 StringFromGUID2(clsid, path + lstrlenW(wszCLSIDSlash), CHARS_IN_GUID);
1755 lstrcatW(path, wszInprocServer32);
1756
1757 TRACE("Registry key: %s\n", debugstr_w(path));
1758
1761 {
1762 res = RegOpenKeyExW( key, L"Server", 0, KEY_READ, &subkey );
1763 if (res == ERROR_SUCCESS)
1764 {
1765 /* Not a managed class, just chain through LoadLibraryShim */
1767 HRESULT (WINAPI *pDllGetClassObject)(REFCLSID,REFIID,LPVOID*);
1768 IClassFactory *classfactory;
1769
1770 dwBufLen = sizeof( filename );
1771 res = RegGetValueW( subkey, NULL, NULL, RRF_RT_REG_SZ, NULL, filename, &dwBufLen );
1772
1773 RegCloseKey( subkey );
1774
1775 if (res != ERROR_SUCCESS)
1776 {
1777 WARN("Can't read default value from Server subkey.\n");
1779 goto cleanup;
1780 }
1781
1782 hr = LoadLibraryShim( filename, L"v4.0.30319", NULL, &module);
1783 if (FAILED(hr))
1784 {
1785 WARN("Can't load %s.\n", debugstr_w(filename));
1786 goto cleanup;
1787 }
1788
1789 pDllGetClassObject = (void*)GetProcAddress( module, "DllGetClassObject" );
1790 if (!pDllGetClassObject)
1791 {
1792 WARN("Can't get DllGetClassObject from %s.\n", debugstr_w(filename));
1794 goto cleanup;
1795 }
1796
1797 hr = pDllGetClassObject( clsid, &IID_IClassFactory, (void**)&classfactory );
1798 if (SUCCEEDED(hr))
1799 {
1800 hr = IClassFactory_CreateInstance( classfactory, NULL, &IID_IUnknown, ppObj );
1801
1802 IClassFactory_Release( classfactory );
1803 }
1804
1805 goto cleanup;
1806 }
1807
1808 dwBufLen = sizeof( classname );
1809 res = RegGetValueW( key, NULL, L"Class", RRF_RT_REG_SZ, NULL, classname, &dwBufLen);
1810 if(res != ERROR_SUCCESS)
1811 {
1812 WARN("Class value cannot be found.\n");
1814 goto cleanup;
1815 }
1816
1817 TRACE("classname (%s)\n", debugstr_w(classname));
1818
1819 dwBufLen = sizeof( codebase );
1820 res = RegGetValueW( key, NULL, L"CodeBase", RRF_RT_REG_SZ, NULL, codebase, &dwBufLen);
1821 if(res == ERROR_SUCCESS)
1822 {
1823 /* Strip file:/// */
1824 if(wcsncmp(codebase, wszFileSlash, lstrlenW(wszFileSlash)) == 0)
1825 offset = lstrlenW(wszFileSlash);
1826
1827 lstrcpyW(filename, codebase + offset);
1828
1830 }
1831
1834 else
1835 {
1836 WCHAR assemblyname[MAX_PATH + 8];
1837
1839 WARN("CodeBase value cannot be found, trying Assembly.\n");
1840 /* get the last subkey of InprocServer32 */
1841 res = RegQueryInfoKeyW(key, 0, 0, 0, &numKeys, 0, 0, 0, 0, 0, 0, 0);
1842 if (res != ERROR_SUCCESS)
1843 goto cleanup;
1844 if (numKeys > 0)
1845 {
1846 numKeys--;
1847 keyLength = ARRAY_SIZE(subkeyName);
1848 res = RegEnumKeyExW(key, numKeys, subkeyName, &keyLength, 0, 0, 0, 0);
1849 if (res != ERROR_SUCCESS)
1850 goto cleanup;
1851 res = RegOpenKeyExW(key, subkeyName, 0, KEY_READ, &subkey);
1852 if (res != ERROR_SUCCESS)
1853 goto cleanup;
1854 dwBufLen = sizeof( assemblyname );
1855 res = RegGetValueW(subkey, NULL, L"Assembly", RRF_RT_REG_SZ, NULL, assemblyname, &dwBufLen);
1856 RegCloseKey(subkey);
1857 if (res != ERROR_SUCCESS)
1858 goto cleanup;
1859 }
1860 else
1861 {
1862 dwBufLen = sizeof( assemblyname );
1863 res = RegGetValueW(key, NULL, L"Assembly", RRF_RT_REG_SZ, NULL, assemblyname, &dwBufLen);
1864 if (res != ERROR_SUCCESS)
1865 goto cleanup;
1866 }
1867
1868 hr = get_file_from_strongname(assemblyname, filename, MAX_PATH);
1869 if (FAILED(hr))
1870 {
1871 /*
1872 * The registry doesn't have a CodeBase entry or the file isn't there, and it's not in the GAC.
1873 *
1874 * Use the Assembly Key to retrieve the filename.
1875 * Assembly : REG_SZ : AssemblyName, Version=X.X.X.X, Culture=neutral, PublicKeyToken=null
1876 */
1877 WCHAR *ns;
1878
1879 WARN("Attempt to load from the application directory.\n");
1881 ns = wcsrchr(filename, '\\');
1882 *(ns+1) = '\0';
1883
1884 ns = wcschr(assemblyname, ',');
1885 *(ns) = '\0';
1886 lstrcatW(filename, assemblyname);
1887 *(ns) = '.';
1888 lstrcatW(filename, L".dll");
1889 }
1890 }
1891 }
1892 else
1893 {
1896
1897 TRACE("classname (%s)\n", debugstr_w(classname));
1898 }
1899
1900 TRACE("filename (%s)\n", debugstr_w(filename));
1901
1902 *ppObj = NULL;
1903
1904
1906 if (SUCCEEDED(hr))
1907 {
1909
1910 if (SUCCEEDED(hr))
1912
1913 if (SUCCEEDED(hr))
1914 {
1916 MonoClass *klass;
1918 MonoDomain *prev_domain;
1920 IUnknown *unk = NULL;
1921 char *filenameA, *ns;
1922 char *classA;
1923
1925
1926 prev_domain = domain_attach(domain);
1927
1930 free(filenameA);
1931 if (!assembly)
1932 {
1933 ERR("Cannot open assembly %s, status=%i\n", debugstr_w(filename), status);
1934 domain_restore(prev_domain);
1935 goto cleanup;
1936 }
1937
1939 if (!image)
1940 {
1941 ERR("Couldn't get assembly image\n");
1942 domain_restore(prev_domain);
1943 goto cleanup;
1944 }
1945
1946 classA = WtoA(classname);
1947 ns = strrchr(classA, '.');
1948 *ns = '\0';
1949
1950 klass = mono_class_from_name(image, classA, ns+1);
1951 free(classA);
1952 if (!klass)
1953 {
1954 ERR("Couldn't get class from image\n");
1955 domain_restore(prev_domain);
1956 goto cleanup;
1957 }
1958
1959 /*
1960 * Use the default constructor for the .NET class.
1961 */
1962 result = mono_object_new(domain, klass);
1963 mono_runtime_object_init(result);
1964
1966 if (SUCCEEDED(hr))
1967 {
1968 hr = IUnknown_QueryInterface(unk, &IID_IUnknown, ppObj);
1969
1970 IUnknown_Release(unk);
1971 }
1972 else
1974
1975 domain_restore(prev_domain);
1976 }
1977 else
1979 }
1980 else
1982
1983cleanup:
1984 if(info)
1985 ICLRRuntimeInfo_Release(info);
1986
1988
1989 return hr;
1990}
#define ARRAY_SIZE(A)
Definition: main.h:20
#define WARN(fmt,...)
Definition: precomp.h:61
const GUID IID_IClassFactory
#define RegCloseKey(hKey)
Definition: registry.h:49
static BOOL try_create_registration_free_com(REFIID clsid, WCHAR *classname, UINT classname_size, WCHAR *filename, UINT filename_size)
#define CHARS_IN_GUID
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LSTATUS WINAPI RegGetValueW(HKEY hKey, LPCWSTR pszSubKey, LPCWSTR pszValue, DWORD dwFlags, LPDWORD pdwType, PVOID pvData, LPDWORD pcbData)
Definition: reg.c:1931
LONG WINAPI RegEnumKeyExW(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPWSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPWSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2504
LONG WINAPI RegQueryInfoKeyW(HKEY hKey, LPWSTR lpClass, LPDWORD lpcClass, LPDWORD lpReserved, LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen, LPDWORD lpcMaxClassLen, LPDWORD lpcValues, LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen, LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime)
Definition: reg.c:3662
INT WINAPI StringFromGUID2(REFGUID guid, LPOLESTR str, INT cmax)
Definition: combase.c:1525
#define CloseHandle
Definition: compat.h:739
#define wcschr
Definition: compat.h:17
#define OPEN_EXISTING
Definition: compat.h:775
#define GetProcAddress(x, y)
Definition: compat.h:753
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define CreateFileW
Definition: compat.h:741
#define lstrcpyW
Definition: compat.h:749
#define lstrlenW
Definition: compat.h:750
static void cleanup(void)
Definition: main.c:1335
MonoObject *CDECL * mono_object_new(MonoDomain *domain, MonoClass *klass)
MonoImage *CDECL * mono_assembly_get_image(MonoAssembly *assembly)
HRESULT get_file_from_strongname(WCHAR *stringnameW, WCHAR *assemblies_path, int path_length)
Definition: metahost.c:1687
MonoAssembly *CDECL * mono_assembly_open(const char *filename, MonoImageOpenStatus *status)
MonoClass *CDECL * mono_class_from_name(MonoImage *image, const char *name_space, const char *name)
_ACRTIMP int __cdecl wcsncmp(const wchar_t *, const wchar_t *, size_t)
Definition: wcs.c:518
#define L(x)
Definition: resources.c:13
GLuint res
Definition: glext.h:9613
GLintptr offset
Definition: glext.h:5920
LPWSTR WINAPI lstrcatW(LPWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:274
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
HRESULT WINAPI LoadLibraryShim(LPCWSTR szDllName, LPCWSTR szVersion, LPVOID pvReserved, HMODULE *phModDll)
Definition: mscoree_main.c:464
struct _MonoClass MonoClass
const CLSID * clsid
Definition: msctf.cpp:50
#define KEY_READ
Definition: nt_native.h:1026
long LONG
Definition: pedump.c:60
#define REFIID
Definition: guiddef.h:118
#define REFCLSID
Definition: guiddef.h:117
WCHAR classname[128]
Definition: startup.c:15
Definition: fci.c:127
Definition: copy.c:22
#define HRESULT
Definition: msvc.h:7
#define WINAPI
Definition: msvc.h:6
#define CLASS_E_CLASSNOTAVAILABLE
Definition: winerror.h:3772
#define RRF_RT_REG_SZ
Definition: winreg.h:58
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10

Referenced by DllGetClassObject().

◆ DEFINE_GUID()

DEFINE_GUID ( IID__AppDomain  ,
0x05f696dc  ,
0x2b29  ,
0x3663  ,
0xad  ,
0x8b  ,
0xc4  ,
0x38  ,
0x9c  ,
0xf2  ,
0xa7  ,
0x13   
)

◆ domain_attach()

static MonoDomain * domain_attach ( MonoDomain domain)
static

Definition at line 118 of file corruntimehost.c.

119{
120 MonoDomain *prev_domain = mono_domain_get();
121
122 if (prev_domain == domain)
123 /* Do not set or restore domain. */
124 return NULL;
125
127
128 return prev_domain;
129}
MonoThread *CDECL * mono_thread_attach(MonoDomain *domain)
MonoDomain *CDECL * mono_domain_get(void)

Referenced by CLRRuntimeHost_ExecuteInDefaultAppDomain(), create_monodata(), ReallyFixupVTable(), RuntimeHost_CreateManagedInstance(), RuntimeHost_Invoke(), and RuntimeHost_VirtualInvoke().

◆ domain_restore()

static void domain_restore ( MonoDomain prev_domain)
static

Definition at line 131 of file corruntimehost.c.

132{
133 if (prev_domain != NULL)
134 mono_domain_set(prev_domain, FALSE);
135}

Referenced by CLRRuntimeHost_ExecuteInDefaultAppDomain(), create_monodata(), ReallyFixupVTable(), RuntimeHost_CreateManagedInstance(), RuntimeHost_Invoke(), and RuntimeHost_VirtualInvoke().

◆ FixupVTable()

static void FixupVTable ( HMODULE  hmodule)
static

Definition at line 1408 of file corruntimehost.c.

1409{
1411 HRESULT hr;
1412
1414 if (SUCCEEDED(hr))
1415 {
1418 }
1419 else
1420 ERR("failed to read CLR headers, hr=%lx\n", hr);
1421}
static HMODULE hmodule
Definition: rasapi.c:29

Referenced by _CorExeMain().

◆ FixupVTable_Assembly()

static void FixupVTable_Assembly ( HMODULE  hmodule,
ASSEMBLY assembly 
)
static

Definition at line 1395 of file corruntimehost.c.

1396{
1397 VTableFixup *vtable_fixups;
1398 ULONG vtable_fixup_count, i;
1399
1400 assembly_get_vtable_fixups(assembly, &vtable_fixups, &vtable_fixup_count);
1401 if (CAN_FIXUP_VTABLE)
1402 for (i=0; i<vtable_fixup_count; i++)
1403 FixupVTableEntry(hmodule, &vtable_fixups[i]);
1404 else if (vtable_fixup_count)
1405 FIXME("cannot fixup vtable; expect a crash\n");
1406}
#define CAN_FIXUP_VTABLE
static void FixupVTableEntry(HMODULE hmodule, VTableFixup *vtable_fixup)
HRESULT assembly_get_vtable_fixups(ASSEMBLY *assembly, VTableFixup **fixups, DWORD *count)
Definition: assembly.c:293

Referenced by _CorDllMain(), and FixupVTable().

◆ FixupVTableEntry()

static void FixupVTableEntry ( HMODULE  hmodule,
VTableFixup vtable_fixup 
)
static

Definition at line 1341 of file corruntimehost.c.

1342{
1343 /* We can't actually generate code for the functions without loading mono,
1344 * and loading mono inside DllMain is a terrible idea. So we make thunks
1345 * that call ReallyFixupVTable, which will load the runtime and fill in the
1346 * vtable, then do an indirect jump using the (now filled in) vtable. Note
1347 * that we have to keep the thunks around forever, as one of them may get
1348 * called while we're filling in the table, and we can never be sure all
1349 * threads are clear. */
1350 struct dll_fixup *fixup;
1351
1352 fixup = malloc(sizeof(*fixup));
1353
1354 fixup->dll = hmodule;
1355 fixup->thunk_code = HeapAlloc(dll_fixup_heap, 0, sizeof(struct vtable_fixup_thunk) * vtable_fixup->count);
1356 fixup->fixup = vtable_fixup;
1357 fixup->vtable = (BYTE*)hmodule + vtable_fixup->rva;
1358 fixup->done = FALSE;
1359
1360#if __x86_64__
1361 if (vtable_fixup->type & COR_VTABLE_64BIT)
1362#else
1363 if (vtable_fixup->type & COR_VTABLE_32BIT)
1364#endif
1365 {
1366 void **vtable = fixup->vtable;
1368 int i;
1369 struct vtable_fixup_thunk *thunks = fixup->thunk_code;
1370
1371 tokens = fixup->tokens = malloc(sizeof(*tokens) * vtable_fixup->count);
1372 memcpy(tokens, vtable, sizeof(*tokens) * vtable_fixup->count);
1373 for (i=0; i<vtable_fixup->count; i++)
1374 {
1375 thunks[i] = thunk_template;
1376 thunks[i].fixup = fixup;
1377 thunks[i].function = ReallyFixupVTable;
1378 thunks[i].vtable_entry = &vtable[i];
1379 vtable[i] = &thunks[i];
1380 }
1381 }
1382 else
1383 {
1384 ERR("unsupported vtable fixup flags %x\n", vtable_fixup->type);
1385 HeapFree(dll_fixup_heap, 0, fixup->thunk_code);
1386 free(fixup);
1387 return;
1388 }
1389
1391 list_add_tail(&dll_fixups, &fixup->entry);
1393}
static void list_add_tail(struct list_entry *head, struct list_entry *entry)
Definition: list.h:83
static CRITICAL_SECTION fixup_list_cs
static HANDLE dll_fixup_heap
static struct list dll_fixups
static void CDECL ReallyFixupVTable(struct dll_fixup *fixup)
static const struct vtable_fixup_thunk thunk_template
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
if(dx< 0)
Definition: linetemp.h:194
static void * vtable[]
Definition: typelib.c:1231
VTableFixup * fixup
void * tokens
struct dll_fixup * fixup
uint32_t ULONG_PTR
Definition: typedefs.h:65
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
@ COR_VTABLE_32BIT
Definition: winnt_old.h:3520
@ COR_VTABLE_64BIT
Definition: winnt_old.h:3521
unsigned char BYTE
Definition: xxhash.c:193

Referenced by FixupVTable_Assembly().

◆ get_utf8_args()

static void get_utf8_args ( int argc,
char ***  argv 
)
static

Definition at line 1073 of file corruntimehost.c.

1074{
1075 WCHAR **argvw;
1076 int size=0, i;
1077 char *current_arg;
1078
1080
1081 for (i=0; i<*argc; i++)
1082 {
1083 size += sizeof(char*);
1084 size += WideCharToMultiByte(CP_UTF8, 0, argvw[i], -1, NULL, 0, NULL, NULL);
1085 }
1086 size += sizeof(char*);
1087
1088 *argv = malloc(size);
1089 current_arg = (char*)(*argv + *argc + 1);
1090
1091 for (i=0; i<*argc; i++)
1092 {
1093 (*argv)[i] = current_arg;
1095 }
1096
1097 (*argv)[*argc] = NULL;
1098
1099 LocalFree(argvw);
1100}
#define WideCharToMultiByte
Definition: compat.h:111
LPWSTR WINAPI GetCommandLineW(void)
Definition: process.c:1338
GLsizeiptr size
Definition: glext.h:5919
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
#define CP_UTF8
Definition: nls.h:20
LPWSTR *WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int *numargs)
Definition: shell32_main.c:79
static const var_t * current_arg
Definition: typegen.c:47

Referenced by _CorExeMain().

◆ GetTokenForVTableEntry()

DWORD WINAPI GetTokenForVTableEntry ( HINSTANCE  hinst,
BYTE **  ppVTEntry 
)

Definition at line 1230 of file corruntimehost.c.

1231{
1232 struct dll_fixup *fixup;
1233 DWORD result = 0;
1234 DWORD rva;
1235 int i;
1236
1237 TRACE("%p,%p\n", hinst, ppVTEntry);
1238
1239 rva = (BYTE*)ppVTEntry - (BYTE*)hinst;
1240
1243 {
1244 if (fixup->dll != hinst)
1245 continue;
1246 if (rva < fixup->fixup->rva || (rva - fixup->fixup->rva >= fixup->fixup->count * sizeof(ULONG_PTR)))
1247 continue;
1248 i = (rva - fixup->fixup->rva) / sizeof(ULONG_PTR);
1249 result = ((ULONG_PTR*)fixup->tokens)[i];
1250 break;
1251 }
1253
1254 TRACE("<-- %lx\n", result);
1255 return result;
1256}
uint32_t entry
Definition: isohybrid.c:63
static HINSTANCE hinst
Definition: edit.c:551
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198

◆ impl_from_ICLRRuntimeHost()

static RuntimeHost * impl_from_ICLRRuntimeHost ( ICLRRuntimeHost iface)
inlinestatic

Definition at line 496 of file corruntimehost.c.

497{
498 return CONTAINING_RECORD(iface, RuntimeHost, ICLRRuntimeHost_iface);
499}
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by CLRRuntimeHost_AddRef(), CLRRuntimeHost_ExecuteInDefaultAppDomain(), CLRRuntimeHost_QueryInterface(), CLRRuntimeHost_Release(), and CLRRuntimeHost_Start().

◆ impl_from_ICorRuntimeHost()

static RuntimeHost * impl_from_ICorRuntimeHost ( ICorRuntimeHost iface)
inlinestatic

◆ ReallyFixupVTable()

static void CDECL ReallyFixupVTable ( struct dll_fixup fixup)
static

Definition at line 1258 of file corruntimehost.c.

1259{
1260 HRESULT hr=S_OK;
1262 ICLRRuntimeInfo *info=NULL;
1264 char *filenameA;
1269
1270 if (fixup->done) return;
1271
1272 /* It's possible we'll have two threads doing this at once. This is
1273 * considered preferable to the potential deadlock if we use a mutex. */
1274
1276
1277 TRACE("%p,%p,%s\n", fixup, fixup->dll, debugstr_w(filename));
1278
1280 if (!filenameA)
1281 hr = E_OUTOFMEMORY;
1282
1283 if (SUCCEEDED(hr))
1285
1286 if (SUCCEEDED(hr))
1288
1289 if (SUCCEEDED(hr))
1291
1292 if (SUCCEEDED(hr))
1293 {
1294 MonoDomain *prev_domain;
1295
1296 prev_domain = domain_attach(domain);
1297
1299
1300 if (assembly)
1301 {
1302 int i;
1303
1304 /* Mono needs an image that belongs to an assembly. */
1306
1307#if __x86_64__
1308 if (fixup->fixup->type & COR_VTABLE_64BIT)
1309#else
1310 if (fixup->fixup->type & COR_VTABLE_32BIT)
1311#endif
1312 {
1313 void **vtable = fixup->vtable;
1314 ULONG_PTR *tokens = fixup->tokens;
1315 for (i=0; i<fixup->fixup->count; i++)
1316 {
1318 image, tokens[i], fixup->fixup->type);
1319 }
1320 }
1321
1322 fixup->done = TRUE;
1323 }
1324
1325 domain_restore(prev_domain);
1326 }
1327
1328 if (info != NULL)
1329 ICLRRuntimeInfo_Release(info);
1330
1331 free(filenameA);
1332
1333 if (!fixup->done)
1334 {
1335 ERR("unable to fixup vtable, hr=%lx, status=%d\n", hr, status);
1336 /* If we returned now, we'd get an infinite loop. */
1337 assert(0);
1338 }
1339}
void *CDECL * mono_marshal_get_vtfixup_ftnptr(MonoImage *image, DWORD token, WORD type)
#define assert(_expr)
Definition: assert.h:32
void * vtable
HMODULE dll

Referenced by FixupVTableEntry().

◆ RuntimeHost_AddDomain()

static HRESULT RuntimeHost_AddDomain ( RuntimeHost This,
const WCHAR name,
IUnknown setup,
IUnknown evidence,
MonoDomain **  result 
)
static

Definition at line 368 of file corruntimehost.c.

370{
371 HRESULT res;
372 char *nameA;
374 void *args[3];
375 MonoObject *new_domain, *id;
376
378 if (FAILED(res))
379 {
380 return res;
381 }
382
383 nameA = WtoA(name);
384 if (!nameA)
385 {
386 return E_OUTOFMEMORY;
387 }
388
389 args[0] = mono_string_new(domain, nameA);
390 free(nameA);
391
392 if (!args[0])
393 {
394 return E_OUTOFMEMORY;
395 }
396
397 if (evidence)
398 {
400 if (FAILED(res))
401 {
402 return res;
403 }
404 }
405 else
406 {
407 args[1] = NULL;
408 }
409
410 if (setup)
411 {
413 if (FAILED(res))
414 {
415 return res;
416 }
417 }
418 else
419 {
420 args[2] = NULL;
421 }
422
423 res = RuntimeHost_Invoke(This, domain, NULL, "System", "AppDomain", "CreateDomain",
424 NULL, args, 3, &new_domain);
425
426 if (FAILED(res))
427 {
428 return res;
429 }
430
431 /* new_domain is not the AppDomain itself, but a transparent proxy.
432 * So, we'll retrieve its ID, and use that to get the real domain object.
433 * We can't do a regular invoke, because that will bypass the proxy.
434 * Instead, do a vcall.
435 */
436
437 res = RuntimeHost_VirtualInvoke(This, domain, NULL, "System", "AppDomain", "get_Id",
438 new_domain, NULL, 0, &id);
439
440 if (FAILED(res))
441 {
442 return res;
443 }
444
445 TRACE("returning domain id %d\n", *(int *)mono_object_unbox(id));
446
448
449 return S_OK;
450}
static HRESULT RuntimeHost_GetObjectForIUnknown(RuntimeHost *This, MonoDomain *domain, IUnknown *unk, MonoObject **obj)
static HRESULT RuntimeHost_VirtualInvoke(RuntimeHost *This, MonoDomain *domain, const char *assemblyname, const char *namespace, const char *typename, const char *methodname, MonoObject *obj, void **args, int arg_count, MonoObject **result)
MonoDomain *CDECL * mono_domain_get_by_id(int id)
GLuint id
Definition: glext.h:5910
Definition: match.c:390
Definition: name.c:39

Referenced by corruntimehost_CreateDomainEx().

◆ RuntimeHost_Construct()

HRESULT RuntimeHost_Construct ( CLRRuntimeInfo runtime_version,
RuntimeHost **  result 
)

Definition at line 1596 of file corruntimehost.c.

1597{
1599
1600 This = malloc(sizeof *This);
1601 if ( !This )
1602 return E_OUTOFMEMORY;
1603
1604 This->ICorRuntimeHost_iface.lpVtbl = &corruntimehost_vtbl;
1605 This->ICLRRuntimeHost_iface.lpVtbl = &CLRHostVtbl;
1606
1607 This->ref = 1;
1608 This->version = runtime_version;
1610 This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": RuntimeHost.lock");
1611
1612 *result = This;
1613
1614 return S_OK;
1615}
static const struct ICorRuntimeHostVtbl corruntimehost_vtbl
static const struct ICLRRuntimeHostVtbl CLRHostVtbl
BOOL WINAPI InitializeCriticalSectionEx(OUT LPCRITICAL_SECTION lpCriticalSection, IN DWORD dwSpinCount, IN DWORD flags)
Definition: sync.c:107
#define DWORD_PTR
Definition: treelist.c:76
#define RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO
Definition: winnt_old.h:1156

Referenced by CLRRuntimeInfo_GetRuntimeHost().

◆ RuntimeHost_CreateManagedInstance()

HRESULT RuntimeHost_CreateManagedInstance ( RuntimeHost This,
LPCWSTR  name,
MonoDomain domain,
MonoObject **  result 
)

Definition at line 976 of file corruntimehost.c.

978{
980 char *nameA=NULL;
981 MonoType *type;
982 MonoClass *klass;
984 MonoDomain *prev_domain;
985
986 if (!domain)
988
989 if (FAILED(hr))
990 return hr;
991
992 prev_domain = domain_attach(domain);
993
994 if (SUCCEEDED(hr))
995 {
996 nameA = WtoA(name);
997 if (!nameA)
999 }
1000
1001 if (SUCCEEDED(hr))
1002 {
1004 if (!type)
1005 {
1006 ERR("Cannot find type %s\n", debugstr_w(name));
1007 hr = E_FAIL;
1008 }
1009 }
1010
1011 if (SUCCEEDED(hr))
1012 {
1014 if (!klass)
1015 {
1016 ERR("Cannot convert type %s to a class\n", debugstr_w(name));
1017 hr = E_FAIL;
1018 }
1019 }
1020
1021 if (SUCCEEDED(hr))
1022 {
1023 obj = mono_object_new(domain, klass);
1024 if (!obj)
1025 {
1026 ERR("Cannot allocate object of type %s\n", debugstr_w(name));
1027 hr = E_FAIL;
1028 }
1029 }
1030
1031 if (SUCCEEDED(hr))
1032 {
1033 /* FIXME: Detect exceptions from the constructor? */
1034 mono_runtime_object_init(obj);
1035 *result = obj;
1036 }
1037
1038 domain_restore(prev_domain);
1039
1040 free(nameA);
1041
1042 return hr;
1043}
MonoType *CDECL * mono_reflection_type_from_name(char *name, MonoImage *image)
MonoClass *CDECL * mono_class_from_mono_type(MonoType *type)
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
struct _MonoType MonoType

Referenced by ClrCreateManagedInstance(), and corruntimehost_CreateDomainSetup().

◆ RuntimeHost_DoInvoke()

static HRESULT RuntimeHost_DoInvoke ( RuntimeHost This,
MonoDomain domain,
const char methodname,
MonoMethod method,
MonoObject obj,
void **  args,
MonoObject **  result 
)
static

Definition at line 245 of file corruntimehost.c.

247{
248 MonoObject *exc;
249 static const char *get_hresult = "get_HResult";
250
252 if (exc)
253 {
254 HRESULT hr;
255 MonoObject *hr_object;
256
257 if (methodname != get_hresult)
258 {
259 /* Map the exception to an HRESULT. */
260 hr = RuntimeHost_Invoke(This, domain, NULL, "System", "Exception", get_hresult,
261 exc, NULL, 0, &hr_object);
262 if (SUCCEEDED(hr))
263 hr = *(HRESULT*)mono_object_unbox(hr_object);
264 if (SUCCEEDED(hr))
265 hr = E_FAIL;
266 }
267 else
268 hr = E_FAIL;
269 *result = NULL;
270 return hr;
271 }
272
273 return S_OK;
274}
MonoObject *CDECL * mono_runtime_invoke(MonoMethod *method, void *obj, void **params, MonoObject **exc)
method
Definition: dragdrop.c:54

Referenced by RuntimeHost_Invoke(), and RuntimeHost_VirtualInvoke().

◆ RuntimeHost_ExitProcess()

void RuntimeHost_ExitProcess ( RuntimeHost This,
INT  exitcode 
)

Definition at line 474 of file corruntimehost.c.

475{
476 HRESULT hr;
477 void *args[2];
480
482 if (FAILED(hr))
483 {
484 ERR("Cannot get domain, hr=%lx\n", hr);
485 return;
486 }
487
488 args[0] = &exitcode;
489 args[1] = NULL;
490 RuntimeHost_Invoke(This, domain, NULL, "System", "Environment", "Exit",
491 NULL, args, 1, &dummy);
492
493 ERR("Process should have exited\n");
494}

Referenced by CLRMetaHost_ExitProcess().

◆ RuntimeHost_GetDefaultDomain()

static HRESULT RuntimeHost_GetDefaultDomain ( RuntimeHost This,
const WCHAR config_path,
MonoDomain **  result 
)
static

Definition at line 137 of file corruntimehost.c.

138{
139 WCHAR exe_config[MAX_PATH];
141 char *base_dirA, *config_pathA, *slash;
143 static BOOL configured_domain;
144
146
148
149 if (configured_domain) goto end;
150
151 if (!config_path)
152 {
153 GetModuleFileNameW(NULL, exe_config, MAX_PATH);
154 lstrcatW(exe_config, L".config");
155
156 config_path = exe_config;
157 }
158
159 config_pathA = WtoA(config_path);
160 if (!config_pathA)
161 {
163 goto end;
164 }
165
167 base_dirA = WtoA(base_dir);
168 if (!base_dirA)
169 {
170 free(config_pathA);
172 goto end;
173 }
174
175 slash = strrchr(base_dirA, '\\');
176 if (slash)
177 *(slash + 1) = 0;
178
179 TRACE("setting base_dir: %s, config_path: %s\n", base_dirA, config_pathA);
180 mono_domain_set_config(*result, base_dirA, config_pathA);
181
182 free(config_pathA);
183 free(base_dirA);
184
185end:
186
187 configured_domain = TRUE;
188
190
191 return res;
192}
const char * base_dir
Definition: metahost.c:101
MonoDomain * get_root_domain(void)
Definition: metahost.c:366
unsigned int BOOL
Definition: ntddk_ex.h:94
GLuint GLuint end
Definition: gl.h:1545

Referenced by _CorExeMain(), CLRRuntimeHost_ExecuteInDefaultAppDomain(), CLRRuntimeHost_Start(), corruntimehost_CreateDomainSetup(), corruntimehost_GetDefaultDomain(), corruntimehost_Start(), create_monodata(), ReallyFixupVTable(), RuntimeHost_AddDomain(), RuntimeHost_CreateManagedInstance(), and RuntimeHost_ExitProcess().

◆ RuntimeHost_GetInterface()

HRESULT RuntimeHost_GetInterface ( RuntimeHost This,
REFCLSID  clsid,
REFIID  riid,
void **  ppv 
)

Definition at line 1617 of file corruntimehost.c.

1618{
1619 IUnknown *unk;
1620 HRESULT hr;
1621
1622 if (IsEqualGUID(clsid, &CLSID_CorRuntimeHost))
1623 {
1624 unk = (IUnknown*)&This->ICorRuntimeHost_iface;
1625 IUnknown_AddRef(unk);
1626 }
1627 else if (IsEqualGUID(clsid, &CLSID_CLRRuntimeHost))
1628 {
1629 unk = (IUnknown*)&This->ICLRRuntimeHost_iface;
1630 IUnknown_AddRef(unk);
1631 }
1632 else if (IsEqualGUID(clsid, &CLSID_CorMetaDataDispenser) ||
1633 IsEqualGUID(clsid, &CLSID_CorMetaDataDispenserRuntime))
1634 {
1636 if (FAILED(hr))
1637 return hr;
1638 }
1639 else if (IsEqualGUID(clsid, &CLSID_CLRDebuggingLegacy))
1640 {
1641 hr = CorDebug_Create(&This->ICLRRuntimeHost_iface, &unk);
1642 if (FAILED(hr))
1643 return hr;
1644 }
1645 else
1646 unk = NULL;
1647
1648 if (unk)
1649 {
1650 hr = IUnknown_QueryInterface(unk, riid, ppv);
1651
1652 IUnknown_Release(unk);
1653
1654 return hr;
1655 }
1656 else
1657 FIXME("not implemented for class %s\n", debugstr_guid(clsid));
1658
1660}
HRESULT CorDebug_Create(ICLRRuntimeHost *runtimehost, IUnknown **ppUnk)
Definition: cordebug.c:763
HRESULT MetaDataDispenser_CreateInstance(IUnknown **ppUnk)
Definition: metadata.c:189
REFIID LPVOID * ppv
Definition: atlbase.h:39

Referenced by CLRRuntimeInfo_GetInterface().

◆ RuntimeHost_GetIUnknownForDomain()

static HRESULT RuntimeHost_GetIUnknownForDomain ( RuntimeHost This,
MonoDomain domain,
IUnknown **  punk 
)
static

Definition at line 452 of file corruntimehost.c.

453{
454 HRESULT hr;
455 MonoObject *appdomain_object;
456 IUnknown *unk;
457
458 hr = RuntimeHost_Invoke(This, domain, NULL, "System", "AppDomain", "get_CurrentDomain",
459 NULL, NULL, 0, &appdomain_object);
460
461 if (SUCCEEDED(hr))
462 hr = RuntimeHost_GetIUnknownForObject(This, appdomain_object, &unk);
463
464 if (SUCCEEDED(hr))
465 {
466 hr = IUnknown_QueryInterface(unk, &IID__AppDomain, (void**)punk);
467
468 IUnknown_Release(unk);
469 }
470
471 return hr;
472}
_In_opt_ IUnknown * punk
Definition: shlwapi.h:158

Referenced by corruntimehost_CreateDomainEx(), and corruntimehost_GetDefaultDomain().

◆ RuntimeHost_GetIUnknownForObject()

HRESULT RuntimeHost_GetIUnknownForObject ( RuntimeHost This,
MonoObject obj,
IUnknown **  ppUnk 
)

Definition at line 1053 of file corruntimehost.c.

1055{
1058 HRESULT hr;
1059
1061
1062 hr = RuntimeHost_Invoke(This, domain, NULL, "System.Runtime.InteropServices", "Marshal", "GetIUnknownForObject",
1063 NULL, (void**)&obj, 1, &result);
1064
1065 if (SUCCEEDED(hr))
1066 *ppUnk = *(IUnknown**)mono_object_unbox(result);
1067 else
1068 *ppUnk = NULL;
1069
1070 return hr;
1071}
MonoDomain *CDECL * mono_object_get_domain(MonoObject *obj)

Referenced by ClrCreateManagedInstance(), corruntimehost_CreateDomainSetup(), create_monodata(), and RuntimeHost_GetIUnknownForDomain().

◆ RuntimeHost_GetMethod()

static BOOL RuntimeHost_GetMethod ( MonoDomain domain,
const char assemblyname,
const char namespace,
const char typename,
const char methodname,
int  arg_count,
MonoMethod **  method 
)
static

Definition at line 194 of file corruntimehost.c.

197{
200 MonoClass *klass;
201
202 if (!assemblyname)
203 {
205 }
206 else
207 {
209 assembly = mono_assembly_open(assemblyname, &status);
210 if (!assembly)
211 {
212 ERR("Cannot load assembly %s, status=%i\n", assemblyname, status);
213 return FALSE;
214 }
215
217 if (!image)
218 {
219 ERR("Couldn't get assembly image for %s\n", assemblyname);
220 return FALSE;
221 }
222 }
223
224 klass = mono_class_from_name(image, namespace, typename);
225 if (!klass)
226 {
227 ERR("Couldn't get class %s.%s from image\n", namespace, typename);
228 return FALSE;
229 }
230
231 *method = mono_class_get_method_from_name(klass, methodname, arg_count);
232 if (!*method)
233 {
234 ERR("Couldn't get method %s from class %s.%s\n", methodname, namespace, typename);
235 return FALSE;
236 }
237
238 return TRUE;
239}
MonoImage *CDECL * mono_get_corlib(void)
MonoMethod *CDECL * mono_class_get_method_from_name(MonoClass *klass, const char *name, int param_count)

Referenced by RuntimeHost_Invoke(), and RuntimeHost_VirtualInvoke().

◆ RuntimeHost_GetObjectForIUnknown()

static HRESULT RuntimeHost_GetObjectForIUnknown ( RuntimeHost This,
MonoDomain domain,
IUnknown unk,
MonoObject **  obj 
)
static

Definition at line 350 of file corruntimehost.c.

352{
353 HRESULT hr;
354 void *args[1];
356
357 args[0] = &unk;
358 hr = RuntimeHost_Invoke(This, domain, NULL, "System.Runtime.InteropServices", "Marshal", "GetObjectForIUnknown",
359 NULL, args, 1, &result);
360
361 if (SUCCEEDED(hr))
362 {
363 *obj = result;
364 }
365 return hr;
366}

Referenced by RuntimeHost_AddDomain().

◆ runtimehost_init()

void runtimehost_init ( void  )

Definition at line 1577 of file corruntimehost.c.

1578{
1581}
static void list_init(struct list_entry *head)
Definition: list.h:51
HANDLE WINAPI HeapCreate(DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize)
Definition: heapmem.c:45
#define HEAP_CREATE_ENABLE_EXECUTE
Definition: rtltypes.h:135

Referenced by DllMain().

◆ RuntimeHost_Invoke()

static HRESULT RuntimeHost_Invoke ( RuntimeHost This,
MonoDomain domain,
const char assemblyname,
const char namespace,
const char typename,
const char methodname,
MonoObject obj,
void **  args,
int  arg_count,
MonoObject **  result 
)
static

Definition at line 276 of file corruntimehost.c.

279{
281 MonoDomain *prev_domain;
282 HRESULT hr;
283
284 *result = NULL;
285
286 prev_domain = domain_attach(domain);
287
288 if (!RuntimeHost_GetMethod(domain, assemblyname, namespace, typename, methodname,
289 arg_count, &method))
290 {
291 domain_restore(prev_domain);
292 return E_FAIL;
293 }
294
296 if (FAILED(hr))
297 {
298 ERR("Method %s.%s:%s raised an exception, hr=%lx\n", namespace, typename, methodname, hr);
299 }
300
301 domain_restore(prev_domain);
302
303 return hr;
304}
static BOOL RuntimeHost_GetMethod(MonoDomain *domain, const char *assemblyname, const char *namespace, const char *typename, const char *methodname, int arg_count, MonoMethod **method)
static HRESULT RuntimeHost_DoInvoke(RuntimeHost *This, MonoDomain *domain, const char *methodname, MonoMethod *method, MonoObject *obj, void **args, MonoObject **result)
struct _MonoMethod MonoMethod

Referenced by CLRRuntimeHost_ExecuteInDefaultAppDomain(), RuntimeHost_AddDomain(), RuntimeHost_DoInvoke(), RuntimeHost_ExitProcess(), RuntimeHost_GetIUnknownForDomain(), RuntimeHost_GetIUnknownForObject(), and RuntimeHost_GetObjectForIUnknown().

◆ runtimehost_uninit()

void runtimehost_uninit ( void  )

Definition at line 1584 of file corruntimehost.c.

1585{
1586 struct dll_fixup *fixup, *fixup2;
1587
1590 {
1591 free(fixup->tokens);
1592 free(fixup);
1593 }
1594}
BOOL WINAPI HeapDestroy(HANDLE hHeap)
Definition: heapmem.c:85
#define LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, list, type, field)
Definition: list.h:204

Referenced by DllMain().

◆ RuntimeHost_VirtualInvoke()

static HRESULT RuntimeHost_VirtualInvoke ( RuntimeHost This,
MonoDomain domain,
const char assemblyname,
const char namespace,
const char typename,
const char methodname,
MonoObject obj,
void **  args,
int  arg_count,
MonoObject **  result 
)
static

Definition at line 306 of file corruntimehost.c.

309{
311 MonoDomain *prev_domain;
312 HRESULT hr;
313
314 *result = NULL;
315
316 if (!obj)
317 {
318 ERR("\"this\" object cannot be null\n");
319 return E_POINTER;
320 }
321
322 prev_domain = domain_attach(domain);
323
324 if (!RuntimeHost_GetMethod(domain, assemblyname, namespace, typename, methodname,
325 arg_count, &method))
326 {
327 domain_restore(prev_domain);
328 return E_FAIL;
329 }
330
332 if (!method)
333 {
334 ERR("Object %p does not support method %s.%s:%s\n", obj, namespace, typename, methodname);
335 domain_restore(prev_domain);
336 return E_FAIL;
337 }
338
340 if (FAILED(hr))
341 {
342 ERR("Method %s.%s:%s raised an exception, hr=%lx\n", namespace, typename, methodname, hr);
343 }
344
345 domain_restore(prev_domain);
346
347 return hr;
348}
MonoMethod *CDECL * mono_object_get_virtual_method(MonoObject *obj, MonoMethod *method)

Referenced by RuntimeHost_AddDomain().

◆ try_create_registration_free_com()

static BOOL try_create_registration_free_com ( REFIID  clsid,
WCHAR classname,
UINT  classname_size,
WCHAR filename,
UINT  filename_size 
)
static

Definition at line 1662 of file corruntimehost.c.

1663{
1664 ACTCTX_SECTION_KEYED_DATA guid_info = { sizeof(ACTCTX_SECTION_KEYED_DATA) };
1665 ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION *assembly_info = NULL;
1666 SIZE_T bytes_assembly_info;
1667 struct comclassredirect_data *redirect_data;
1668 struct clrclass_data *class_data;
1669 void *ptr_name;
1670 const WCHAR *ptr_path_start, *ptr_path_end;
1671 WCHAR path[MAX_PATH] = {0};
1672 WCHAR str_dll[] = {'.','d','l','l',0};
1673 BOOL ret = FALSE;
1674
1675 if (!FindActCtxSectionGuid(FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX, 0, ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION, clsid, &guid_info))
1676 {
1679 ERR("Failed to find guid: %ld\n", error);
1680 goto end;
1681 }
1682
1683 QueryActCtxW(0, guid_info.hActCtx, &guid_info.ulAssemblyRosterIndex, AssemblyDetailedInformationInActivationContext, NULL, 0, &bytes_assembly_info);
1684 assembly_info = malloc(bytes_assembly_info);
1685 if (!QueryActCtxW(0, guid_info.hActCtx, &guid_info.ulAssemblyRosterIndex,
1686 AssemblyDetailedInformationInActivationContext, assembly_info, bytes_assembly_info, &bytes_assembly_info))
1687 {
1688 ERR("QueryActCtxW failed: %ld!\n", GetLastError());
1689 goto end;
1690 }
1691
1692 redirect_data = guid_info.lpData;
1693 class_data = (void *)((char *)redirect_data + redirect_data->clrdata_offset);
1694
1695 ptr_name = (char *)class_data + class_data->name_offset;
1696 if (lstrlenW(ptr_name) + 1 > classname_size) /* Include null-terminator */
1697 {
1698 ERR("Buffer is too small\n");
1699 goto end;
1700 }
1701 lstrcpyW(classname, ptr_name);
1702
1703 ptr_path_start = assembly_info->lpAssemblyEncodedAssemblyIdentity;
1704 ptr_path_end = wcschr(ptr_path_start, ',');
1705 memcpy(path, ptr_path_start, (char*)ptr_path_end - (char*)ptr_path_start);
1706
1707 GetModuleFileNameW(NULL, filename, filename_size);
1709
1710 if (lstrlenW(filename) + lstrlenW(path) + ARRAY_SIZE(str_dll) + 1 > filename_size) /* Include blackslash */
1711 {
1712 ERR("Buffer is too small\n");
1713 goto end;
1714 }
1715
1717 lstrcatW(filename, str_dll);
1718
1719 ret = TRUE;
1720
1721end:
1722 free(assembly_info);
1723
1724 if (guid_info.hActCtx)
1725 ReleaseActCtx(guid_info.hActCtx);
1726
1727 return ret;
1728}
VOID WINAPI ReleaseActCtx(IN HANDLE hActCtx)
Definition: actctx.c:208
BOOL WINAPI QueryActCtxW(IN DWORD dwFlags, IN HANDLE hActCtx, IN PVOID pvSubInstance, IN ULONG ulInfoClass, IN PVOID pvBuffer, IN SIZE_T cbBuffer, IN OUT SIZE_T *pcbWrittenOrRequired OPTIONAL)
Definition: actctx.c:328
BOOL WINAPI FindActCtxSectionGuid(DWORD dwFlags, const GUID *lpExtGuid, ULONG ulId, const GUID *lpSearchGuid, PACTCTX_SECTION_KEYED_DATA pInfo)
Definition: actctx.c:265
BOOL WINAPI PathRemoveFileSpecW(WCHAR *path)
Definition: path.c:1145
return ret
Definition: mutex.c:146
#define error(str)
Definition: mkdosfs.c:1605
#define PathAppendW
Definition: pathcch.h:310
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define ERROR_SXS_KEY_NOT_FOUND
Definition: winerror.h:3101

Referenced by create_monodata().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( mscoree  )

Variable Documentation

◆ CLRHostVtbl

const struct ICLRRuntimeHostVtbl CLRHostVtbl
static
Initial value:
=
{
}
static HRESULT WINAPI CLRRuntimeHost_ExecuteInAppDomain(ICLRRuntimeHost *iface, DWORD dwAppDomainId, FExecuteInAppDomainCallback pCallback, void *cookie)
static HRESULT WINAPI CLRRuntimeHost_UnloadAppDomain(ICLRRuntimeHost *iface, DWORD dwAppDomainId, BOOL fWaitUntilDone)
static HRESULT WINAPI CLRRuntimeHost_SetHostControl(ICLRRuntimeHost *iface, IHostControl *pHostControl)
static HRESULT WINAPI CLRRuntimeHost_Start(ICLRRuntimeHost *iface)
static ULONG WINAPI CLRRuntimeHost_Release(ICLRRuntimeHost *iface)
static ULONG WINAPI CLRRuntimeHost_AddRef(ICLRRuntimeHost *iface)
static HRESULT WINAPI CLRRuntimeHost_ExecuteInDefaultAppDomain(ICLRRuntimeHost *iface, LPCWSTR pwzAssemblyPath, LPCWSTR pwzTypeName, LPCWSTR pwzMethodName, LPCWSTR pwzArgument, DWORD *pReturnValue)
static HRESULT WINAPI CLRRuntimeHost_GetCLRControl(ICLRRuntimeHost *iface, ICLRControl **pCLRControl)
static HRESULT WINAPI CLRRuntimeHost_GetCurrentAppDomainId(ICLRRuntimeHost *iface, DWORD *pdwAppDomainId)
static HRESULT WINAPI CLRRuntimeHost_QueryInterface(ICLRRuntimeHost *iface, REFIID riid, void **ppvObject)
static HRESULT WINAPI CLRRuntimeHost_Stop(ICLRRuntimeHost *iface)
static HRESULT WINAPI CLRRuntimeHost_ExecuteApplication(ICLRRuntimeHost *iface, LPCWSTR pwzAppFullName, DWORD dwManifestPaths, LPCWSTR *ppwzManifestPaths, DWORD dwActivationData, LPCWSTR *ppwzActivationData, int *pReturnValue)

Definition at line 957 of file corruntimehost.c.

Referenced by RuntimeHost_Construct().

◆ corruntimehost_vtbl

const struct ICorRuntimeHostVtbl corruntimehost_vtbl
static
Initial value:
=
{
}
static ULONG WINAPI corruntimehost_AddRef(ICorRuntimeHost *iface)
static HRESULT WINAPI corruntimehost_Start(ICorRuntimeHost *iface)
static HRESULT WINAPI corruntimehost_SwitchOutLogicalThreadState(ICorRuntimeHost *iface, DWORD **fiberCookie)
static HRESULT WINAPI corruntimehost_QueryInterface(ICorRuntimeHost *iface, REFIID riid, void **ppvObject)
static HRESULT WINAPI corruntimehost_CurrentDomain(ICorRuntimeHost *iface, IUnknown **appDomain)
static HRESULT WINAPI corruntimehost_GetConfiguration(ICorRuntimeHost *iface, ICorConfiguration **pConfiguration)
static HRESULT WINAPI corruntimehost_UnloadDomain(ICorRuntimeHost *iface, IUnknown *appDomain)
static HRESULT WINAPI corruntimehost_CreateLogicalThreadState(ICorRuntimeHost *iface)
static HRESULT WINAPI corruntimehost_GetDefaultDomain(ICorRuntimeHost *iface, IUnknown **pAppDomain)
static HRESULT WINAPI corruntimehost_Stop(ICorRuntimeHost *iface)
static HRESULT WINAPI corruntimehost_CreateDomainEx(ICorRuntimeHost *iface, LPCWSTR friendlyName, IUnknown *setup, IUnknown *evidence, IUnknown **appDomain)
static HRESULT WINAPI corruntimehost_SwitchInLogicalThreadState(ICorRuntimeHost *iface, DWORD *fiberCookie)
static HRESULT WINAPI corruntimehost_EnumDomains(ICorRuntimeHost *iface, HDOMAINENUM *hEnum)
static HRESULT WINAPI corruntimehost_CreateDomain(ICorRuntimeHost *iface, LPCWSTR friendlyName, IUnknown *identityArray, IUnknown **appDomain)
static HRESULT WINAPI corruntimehost_MapFile(ICorRuntimeHost *iface, HANDLE hFile, HMODULE *mapAddress)
static HRESULT WINAPI corruntimehost_DeleteLogicalThreadState(ICorRuntimeHost *iface)
static HRESULT WINAPI corruntimehost_CloseEnum(ICorRuntimeHost *iface, HDOMAINENUM hEnum)
static ULONG WINAPI corruntimehost_Release(ICorRuntimeHost *iface)
static HRESULT WINAPI corruntimehost_CreateDomainSetup(ICorRuntimeHost *iface, IUnknown **appDomainSetup)
static HRESULT WINAPI corruntimehost_NextDomain(ICorRuntimeHost *iface, HDOMAINENUM hEnum, IUnknown **appDomain)
static HRESULT WINAPI corruntimehost_CreateEvidence(ICorRuntimeHost *iface, IUnknown **evidence)
static HRESULT WINAPI corruntimehost_LocksHeldByLogicalThread(ICorRuntimeHost *iface, DWORD *pCount)

Definition at line 754 of file corruntimehost.c.

Referenced by RuntimeHost_Construct().

◆ dll_fixup_heap

HANDLE dll_fixup_heap
static

Definition at line 56 of file corruntimehost.c.

Referenced by FixupVTableEntry(), runtimehost_init(), and runtimehost_uninit().

◆ dll_fixups

struct list dll_fixups
static

◆ fixup_list_cs

static CRITICAL_SECTION fixup_list_cs = { &fixup_list_cs_debug, -1, 0, 0, 0, 0 }
static

Definition at line 58 of file corruntimehost.c.

Referenced by FixupVTableEntry(), and GetTokenForVTableEntry().

◆ fixup_list_cs_debug

CRITICAL_SECTION_DEBUG fixup_list_cs_debug
static
Initial value:
=
{
0, 0, &fixup_list_cs,
0, 0, { (DWORD_PTR)(__FILE__ ": fixup_list_cs") }
}
static CRITICAL_SECTION_DEBUG fixup_list_cs_debug

Definition at line 59 of file corruntimehost.c.

◆ private_path

WCHAR** private_path = NULL

Definition at line 70 of file corruntimehost.c.

Referenced by _CorExeMain(), and wine_mono_assembly_preload_hook_v2_fn().

◆ thunk_template

const struct vtable_fixup_thunk thunk_template = {0}
static

Definition at line 1226 of file corruntimehost.c.

Referenced by FixupVTableEntry().