2010-09-22 21:09:04 +02:00
|
|
|
/*
|
|
|
|
* ICLRMetaHost - discovery and management of available .NET runtimes
|
|
|
|
*
|
|
|
|
* Copyright 2010 Vincent Povirk for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2010-09-23 00:24:56 +02:00
|
|
|
#include <stdio.h>
|
2010-09-22 21:09:04 +02:00
|
|
|
#include <stdarg.h>
|
2010-09-23 00:24:56 +02:00
|
|
|
#include <assert.h>
|
2010-09-22 21:09:04 +02:00
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2010-09-23 00:24:56 +02:00
|
|
|
#include "winreg.h"
|
2019-04-02 16:51:53 +02:00
|
|
|
#include "winternl.h"
|
2010-09-22 21:09:04 +02:00
|
|
|
#include "ole2.h"
|
|
|
|
|
2010-09-29 00:53:14 +02:00
|
|
|
#include "corerror.h"
|
2011-09-27 01:06:18 +02:00
|
|
|
#include "cor.h"
|
2010-09-22 21:09:04 +02:00
|
|
|
#include "mscoree.h"
|
2011-09-27 01:06:18 +02:00
|
|
|
#include "corhdr.h"
|
|
|
|
#include "cordebug.h"
|
2010-09-22 21:09:04 +02:00
|
|
|
#include "metahost.h"
|
2011-09-27 01:06:18 +02:00
|
|
|
#include "fusion.h"
|
2010-10-05 00:37:00 +02:00
|
|
|
#include "wine/list.h"
|
2019-03-08 22:40:41 +01:00
|
|
|
#include "wine/heap.h"
|
2010-09-22 21:09:04 +02:00
|
|
|
#include "mscoree_private.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL( mscoree );
|
|
|
|
|
2011-05-13 17:31:09 +02:00
|
|
|
static const struct ICLRRuntimeInfoVtbl CLRRuntimeInfoVtbl;
|
2010-09-23 00:24:56 +02:00
|
|
|
|
2013-08-14 06:08:31 +02:00
|
|
|
#define NUM_RUNTIMES 4
|
2010-09-23 00:24:56 +02:00
|
|
|
|
|
|
|
static struct CLRRuntimeInfo runtimes[NUM_RUNTIMES] = {
|
2015-02-20 19:59:53 +01:00
|
|
|
{{&CLRRuntimeInfoVtbl}, 1, 0, 3705, 0},
|
|
|
|
{{&CLRRuntimeInfoVtbl}, 1, 1, 4322, 0},
|
|
|
|
{{&CLRRuntimeInfoVtbl}, 2, 0, 50727, 0},
|
|
|
|
{{&CLRRuntimeInfoVtbl}, 4, 0, 30319, 0}
|
2010-09-23 00:24:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static CRITICAL_SECTION runtime_list_cs;
|
|
|
|
static CRITICAL_SECTION_DEBUG runtime_list_cs_debug =
|
|
|
|
{
|
|
|
|
0, 0, &runtime_list_cs,
|
|
|
|
{ &runtime_list_cs_debug.ProcessLocksList,
|
|
|
|
&runtime_list_cs_debug.ProcessLocksList },
|
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": runtime_list_cs") }
|
|
|
|
};
|
|
|
|
static CRITICAL_SECTION runtime_list_cs = { &runtime_list_cs_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
2017-08-01 18:51:22 +02:00
|
|
|
struct CLRMetaHost
|
|
|
|
{
|
|
|
|
ICLRMetaHost ICLRMetaHost_iface;
|
|
|
|
|
|
|
|
RuntimeLoadedCallbackFnPtr callback;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct CLRMetaHost GlobalCLRMetaHost;
|
|
|
|
|
2013-10-24 21:34:24 +02:00
|
|
|
static HMODULE mono_handle;
|
|
|
|
|
|
|
|
BOOL is_mono_started;
|
|
|
|
static BOOL is_mono_shutdown;
|
|
|
|
|
2017-07-24 20:22:15 +02:00
|
|
|
typedef struct _MonoProfilerDesc *MonoProfilerHandle;
|
|
|
|
|
|
|
|
typedef void (CDECL *MonoProfilerRuntimeShutdownBeginCallback) (MonoProfiler *prof);
|
|
|
|
|
2013-10-24 21:34:24 +02:00
|
|
|
MonoImage* (CDECL *mono_assembly_get_image)(MonoAssembly *assembly);
|
|
|
|
MonoAssembly* (CDECL *mono_assembly_load_from)(MonoImage *image, const char *fname, MonoImageOpenStatus *status);
|
2019-03-08 22:40:41 +01:00
|
|
|
const char* (CDECL *mono_assembly_name_get_name)(MonoAssemblyName *aname);
|
2013-10-24 21:34:24 +02:00
|
|
|
MonoAssembly* (CDECL *mono_assembly_open)(const char *filename, MonoImageOpenStatus *status);
|
2017-10-05 18:49:34 +02:00
|
|
|
void (CDECL *mono_callspec_set_assembly)(MonoAssembly *assembly);
|
2013-10-24 21:34:24 +02:00
|
|
|
MonoClass* (CDECL *mono_class_from_mono_type)(MonoType *type);
|
|
|
|
MonoClass* (CDECL *mono_class_from_name)(MonoImage *image, const char* name_space, const char *name);
|
|
|
|
MonoMethod* (CDECL *mono_class_get_method_from_name)(MonoClass *klass, const char *name, int param_count);
|
|
|
|
static void (CDECL *mono_config_parse)(const char *filename);
|
2016-03-08 22:49:26 +01:00
|
|
|
MonoDomain* (CDECL *mono_domain_get)(void);
|
2016-02-17 02:14:19 +01:00
|
|
|
MonoDomain* (CDECL *mono_domain_get_by_id)(int id);
|
2016-03-08 22:49:26 +01:00
|
|
|
BOOL (CDECL *mono_domain_set)(MonoDomain *domain,BOOL force);
|
2016-01-12 15:36:07 +01:00
|
|
|
void (CDECL *mono_domain_set_config)(MonoDomain *domain,const char *base_dir,const char *config_file_name);
|
2013-10-24 21:34:24 +02:00
|
|
|
static void (CDECL *mono_free)(void *);
|
2020-04-19 05:01:15 +02:00
|
|
|
MonoImage* (CDECL *mono_get_corlib)(void);
|
2013-10-24 21:34:24 +02:00
|
|
|
static MonoImage* (CDECL *mono_image_open)(const char *fname, MonoImageOpenStatus *status);
|
|
|
|
MonoImage* (CDECL *mono_image_open_from_module_handle)(HMODULE module_handle, char* fname, UINT has_entry_point, MonoImageOpenStatus* status);
|
|
|
|
static void (CDECL *mono_install_assembly_preload_hook)(MonoAssemblyPreLoadFunc func, void *user_data);
|
|
|
|
int (CDECL *mono_jit_exec)(MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[]);
|
2015-02-20 19:59:53 +01:00
|
|
|
MonoDomain* (CDECL *mono_jit_init_version)(const char *domain_name, const char *runtime_version);
|
2013-10-24 21:34:24 +02:00
|
|
|
static int (CDECL *mono_jit_set_trace_options)(const char* options);
|
|
|
|
void* (CDECL *mono_marshal_get_vtfixup_ftnptr)(MonoImage *image, DWORD token, WORD type);
|
|
|
|
MonoDomain* (CDECL *mono_object_get_domain)(MonoObject *obj);
|
2016-02-17 02:14:19 +01:00
|
|
|
MonoMethod* (CDECL *mono_object_get_virtual_method)(MonoObject *obj, MonoMethod *method);
|
2013-10-24 21:34:24 +02:00
|
|
|
MonoObject* (CDECL *mono_object_new)(MonoDomain *domain, MonoClass *klass);
|
|
|
|
void* (CDECL *mono_object_unbox)(MonoObject *obj);
|
2017-07-24 20:22:15 +02:00
|
|
|
static MonoProfilerHandle (CDECL *mono_profiler_create)(MonoProfiler *prof);
|
2013-10-24 21:34:24 +02:00
|
|
|
static void (CDECL *mono_profiler_install)(MonoProfiler *prof, MonoProfileFunc shutdown_callback);
|
2017-07-24 20:22:15 +02:00
|
|
|
static void (CDECL *mono_profiler_set_runtime_shutdown_begin_callback)(MonoProfilerHandle handle, MonoProfilerRuntimeShutdownBeginCallback cb);
|
2013-10-24 21:34:24 +02:00
|
|
|
MonoType* (CDECL *mono_reflection_type_from_name)(char *name, MonoImage *image);
|
|
|
|
MonoObject* (CDECL *mono_runtime_invoke)(MonoMethod *method, void *obj, void **params, MonoObject **exc);
|
|
|
|
void (CDECL *mono_runtime_object_init)(MonoObject *this_obj);
|
2014-10-15 23:26:09 +02:00
|
|
|
void (CDECL *mono_runtime_quit)(void);
|
2016-03-30 19:17:34 +02:00
|
|
|
static void (CDECL *mono_set_crash_chaining)(BOOL chain_signals);
|
2013-10-24 21:34:24 +02:00
|
|
|
static void (CDECL *mono_set_dirs)(const char *assembly_dir, const char *config_dir);
|
|
|
|
static void (CDECL *mono_set_verbose_level)(DWORD level);
|
|
|
|
MonoString* (CDECL *mono_string_new)(MonoDomain *domain, const char *str);
|
|
|
|
static char* (CDECL *mono_stringify_assembly_name)(MonoAssemblyName *aname);
|
|
|
|
MonoThread* (CDECL *mono_thread_attach)(MonoDomain *domain);
|
2013-10-24 22:17:24 +02:00
|
|
|
void (CDECL *mono_thread_manage)(void);
|
2015-09-04 21:05:00 +02:00
|
|
|
void (CDECL *mono_trace_set_print_handler)(MonoPrintCallback callback);
|
|
|
|
void (CDECL *mono_trace_set_printerr_handler)(MonoPrintCallback callback);
|
2013-10-24 21:34:24 +02:00
|
|
|
|
|
|
|
static BOOL find_mono_dll(LPCWSTR path, LPWSTR dll_path);
|
2010-10-03 18:44:32 +02:00
|
|
|
|
2016-01-20 16:03:40 +01:00
|
|
|
static MonoAssembly* CDECL mono_assembly_preload_hook_fn(MonoAssemblyName *aname, char **assemblies_path, void *user_data);
|
2010-10-05 22:50:01 +02:00
|
|
|
|
2016-01-20 16:03:40 +01:00
|
|
|
static void CDECL mono_shutdown_callback_fn(MonoProfiler *prof);
|
2011-02-21 21:22:02 +01:00
|
|
|
|
2016-01-20 16:03:40 +01:00
|
|
|
static void CDECL mono_print_handler_fn(const char *string, INT is_stdout);
|
2015-09-04 21:05:00 +02:00
|
|
|
|
2013-10-24 21:34:24 +02:00
|
|
|
static MonoImage* CDECL image_open_module_handle_dummy(HMODULE module_handle,
|
2012-05-17 16:47:46 +02:00
|
|
|
char* fname, UINT has_entry_point, MonoImageOpenStatus* status)
|
|
|
|
{
|
2013-10-24 21:34:24 +02:00
|
|
|
return mono_image_open(fname, status);
|
2012-05-17 16:47:46 +02:00
|
|
|
}
|
|
|
|
|
2016-03-30 19:17:34 +02:00
|
|
|
static void CDECL set_crash_chaining_dummy(BOOL crash_chaining)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-09-04 21:05:00 +02:00
|
|
|
static void CDECL set_print_handler_dummy(MonoPrintCallback callback)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-02-20 19:59:53 +01:00
|
|
|
static HRESULT load_mono(LPCWSTR mono_path)
|
2010-09-26 22:54:13 +02:00
|
|
|
{
|
2010-10-03 18:44:32 +02:00
|
|
|
static const WCHAR lib[] = {'\\','l','i','b',0};
|
|
|
|
static const WCHAR etc[] = {'\\','e','t','c',0};
|
2015-09-03 22:44:24 +02:00
|
|
|
WCHAR mono_dll_path[MAX_PATH+16];
|
2010-10-03 18:44:32 +02:00
|
|
|
WCHAR mono_lib_path[MAX_PATH+4], mono_etc_path[MAX_PATH+4];
|
|
|
|
char mono_lib_path_a[MAX_PATH], mono_etc_path_a[MAX_PATH];
|
|
|
|
int trace_size;
|
|
|
|
char trace_setting[256];
|
2013-02-27 16:46:43 +01:00
|
|
|
int verbose_size;
|
|
|
|
char verbose_setting[256];
|
2010-10-03 18:44:32 +02:00
|
|
|
|
2013-10-24 21:34:24 +02:00
|
|
|
if (is_mono_shutdown)
|
2011-02-21 21:22:02 +01:00
|
|
|
{
|
2011-03-05 11:50:29 +01:00
|
|
|
ERR("Cannot load Mono after it has been shut down.\n");
|
2011-02-21 21:22:02 +01:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2013-10-24 21:34:24 +02:00
|
|
|
if (!mono_handle)
|
2010-10-03 18:44:32 +02:00
|
|
|
{
|
2019-07-05 12:55:54 +02:00
|
|
|
lstrcpyW(mono_lib_path, mono_path);
|
|
|
|
lstrcatW(mono_lib_path, lib);
|
2010-10-03 18:44:32 +02:00
|
|
|
WideCharToMultiByte(CP_UTF8, 0, mono_lib_path, -1, mono_lib_path_a, MAX_PATH, NULL, NULL);
|
|
|
|
|
2019-07-05 12:55:54 +02:00
|
|
|
lstrcpyW(mono_etc_path, mono_path);
|
|
|
|
lstrcatW(mono_etc_path, etc);
|
2010-10-03 18:44:32 +02:00
|
|
|
WideCharToMultiByte(CP_UTF8, 0, mono_etc_path, -1, mono_etc_path_a, MAX_PATH, NULL, NULL);
|
|
|
|
|
2015-02-20 19:59:53 +01:00
|
|
|
if (!find_mono_dll(mono_path, mono_dll_path)) goto fail;
|
2010-10-03 18:44:32 +02:00
|
|
|
|
2013-10-24 21:34:24 +02:00
|
|
|
mono_handle = LoadLibraryW(mono_dll_path);
|
2010-10-03 18:44:32 +02:00
|
|
|
|
2013-10-24 21:34:24 +02:00
|
|
|
if (!mono_handle) goto fail;
|
2010-10-03 18:44:32 +02:00
|
|
|
|
|
|
|
#define LOAD_MONO_FUNCTION(x) do { \
|
2013-10-24 21:34:24 +02:00
|
|
|
x = (void*)GetProcAddress(mono_handle, #x); \
|
|
|
|
if (!x) { \
|
2010-10-03 18:44:32 +02:00
|
|
|
goto fail; \
|
|
|
|
} \
|
|
|
|
} while (0);
|
|
|
|
|
2010-10-06 00:15:08 +02:00
|
|
|
LOAD_MONO_FUNCTION(mono_assembly_get_image);
|
2012-05-02 20:04:36 +02:00
|
|
|
LOAD_MONO_FUNCTION(mono_assembly_load_from);
|
2019-03-08 22:40:41 +01:00
|
|
|
LOAD_MONO_FUNCTION(mono_assembly_name_get_name);
|
2010-10-05 22:50:01 +02:00
|
|
|
LOAD_MONO_FUNCTION(mono_assembly_open);
|
2010-10-03 18:44:32 +02:00
|
|
|
LOAD_MONO_FUNCTION(mono_config_parse);
|
2010-10-06 00:15:08 +02:00
|
|
|
LOAD_MONO_FUNCTION(mono_class_from_mono_type);
|
|
|
|
LOAD_MONO_FUNCTION(mono_class_from_name);
|
|
|
|
LOAD_MONO_FUNCTION(mono_class_get_method_from_name);
|
2016-03-08 22:49:26 +01:00
|
|
|
LOAD_MONO_FUNCTION(mono_domain_get);
|
2016-02-17 02:14:19 +01:00
|
|
|
LOAD_MONO_FUNCTION(mono_domain_get_by_id);
|
2016-03-08 22:49:26 +01:00
|
|
|
LOAD_MONO_FUNCTION(mono_domain_set);
|
2016-01-12 15:36:07 +01:00
|
|
|
LOAD_MONO_FUNCTION(mono_domain_set_config);
|
2013-10-24 21:34:24 +02:00
|
|
|
LOAD_MONO_FUNCTION(mono_free);
|
2020-04-19 05:01:15 +02:00
|
|
|
LOAD_MONO_FUNCTION(mono_get_corlib);
|
2012-05-17 16:47:46 +02:00
|
|
|
LOAD_MONO_FUNCTION(mono_image_open);
|
2010-10-05 22:50:01 +02:00
|
|
|
LOAD_MONO_FUNCTION(mono_install_assembly_preload_hook);
|
2010-10-03 18:44:32 +02:00
|
|
|
LOAD_MONO_FUNCTION(mono_jit_exec);
|
2015-02-20 19:59:53 +01:00
|
|
|
LOAD_MONO_FUNCTION(mono_jit_init_version);
|
2010-10-03 18:44:32 +02:00
|
|
|
LOAD_MONO_FUNCTION(mono_jit_set_trace_options);
|
2012-05-07 17:48:33 +02:00
|
|
|
LOAD_MONO_FUNCTION(mono_marshal_get_vtfixup_ftnptr);
|
2010-10-06 00:15:08 +02:00
|
|
|
LOAD_MONO_FUNCTION(mono_object_get_domain);
|
2016-02-17 02:14:19 +01:00
|
|
|
LOAD_MONO_FUNCTION(mono_object_get_virtual_method);
|
2010-10-06 00:15:08 +02:00
|
|
|
LOAD_MONO_FUNCTION(mono_object_new);
|
|
|
|
LOAD_MONO_FUNCTION(mono_object_unbox);
|
|
|
|
LOAD_MONO_FUNCTION(mono_reflection_type_from_name);
|
|
|
|
LOAD_MONO_FUNCTION(mono_runtime_invoke);
|
|
|
|
LOAD_MONO_FUNCTION(mono_runtime_object_init);
|
2014-10-15 23:26:09 +02:00
|
|
|
LOAD_MONO_FUNCTION(mono_runtime_quit);
|
2010-10-03 18:44:32 +02:00
|
|
|
LOAD_MONO_FUNCTION(mono_set_dirs);
|
2013-02-27 16:46:43 +01:00
|
|
|
LOAD_MONO_FUNCTION(mono_set_verbose_level);
|
2010-10-05 22:50:01 +02:00
|
|
|
LOAD_MONO_FUNCTION(mono_stringify_assembly_name);
|
2011-12-15 23:15:11 +01:00
|
|
|
LOAD_MONO_FUNCTION(mono_string_new);
|
2012-04-23 21:55:52 +02:00
|
|
|
LOAD_MONO_FUNCTION(mono_thread_attach);
|
2013-10-24 22:17:24 +02:00
|
|
|
LOAD_MONO_FUNCTION(mono_thread_manage);
|
2010-10-05 22:50:01 +02:00
|
|
|
|
2010-10-03 18:44:32 +02:00
|
|
|
#undef LOAD_MONO_FUNCTION
|
|
|
|
|
2012-05-17 16:47:46 +02:00
|
|
|
#define LOAD_OPT_MONO_FUNCTION(x, default) do { \
|
2013-10-24 21:34:24 +02:00
|
|
|
x = (void*)GetProcAddress(mono_handle, #x); \
|
|
|
|
if (!x) { \
|
|
|
|
x = default; \
|
2011-02-21 21:22:02 +01:00
|
|
|
} \
|
|
|
|
} while (0);
|
|
|
|
|
2017-10-05 18:49:34 +02:00
|
|
|
LOAD_OPT_MONO_FUNCTION(mono_callspec_set_assembly, NULL);
|
2013-10-24 21:34:24 +02:00
|
|
|
LOAD_OPT_MONO_FUNCTION(mono_image_open_from_module_handle, image_open_module_handle_dummy);
|
2017-07-24 20:22:15 +02:00
|
|
|
LOAD_OPT_MONO_FUNCTION(mono_profiler_create, NULL);
|
|
|
|
LOAD_OPT_MONO_FUNCTION(mono_profiler_install, NULL);
|
|
|
|
LOAD_OPT_MONO_FUNCTION(mono_profiler_set_runtime_shutdown_begin_callback, NULL);
|
2016-03-30 19:17:34 +02:00
|
|
|
LOAD_OPT_MONO_FUNCTION(mono_set_crash_chaining, set_crash_chaining_dummy);
|
2015-09-04 21:05:00 +02:00
|
|
|
LOAD_OPT_MONO_FUNCTION(mono_trace_set_print_handler, set_print_handler_dummy);
|
|
|
|
LOAD_OPT_MONO_FUNCTION(mono_trace_set_printerr_handler, set_print_handler_dummy);
|
2011-02-21 21:22:02 +01:00
|
|
|
|
2012-05-17 16:47:46 +02:00
|
|
|
#undef LOAD_OPT_MONO_FUNCTION
|
2011-02-21 21:22:02 +01:00
|
|
|
|
2017-10-05 18:49:34 +02:00
|
|
|
if (mono_callspec_set_assembly == NULL)
|
|
|
|
{
|
|
|
|
mono_callspec_set_assembly = (void*)GetProcAddress(mono_handle, "mono_trace_set_assembly");
|
|
|
|
if (!mono_callspec_set_assembly) goto fail;
|
|
|
|
}
|
|
|
|
|
2017-07-24 20:22:15 +02:00
|
|
|
if (mono_profiler_create != NULL)
|
|
|
|
{
|
|
|
|
/* Profiler API v2 */
|
|
|
|
MonoProfilerHandle handle = mono_profiler_create(NULL);
|
|
|
|
mono_profiler_set_runtime_shutdown_begin_callback(handle, mono_shutdown_callback_fn);
|
|
|
|
}
|
|
|
|
else if (mono_profiler_install != NULL)
|
|
|
|
{
|
|
|
|
/* Profiler API v1 */
|
|
|
|
mono_profiler_install(NULL, mono_shutdown_callback_fn);
|
|
|
|
}
|
2011-02-21 21:22:02 +01:00
|
|
|
|
2016-03-30 19:17:34 +02:00
|
|
|
mono_set_crash_chaining(TRUE);
|
|
|
|
|
2015-09-04 21:05:00 +02:00
|
|
|
mono_trace_set_print_handler(mono_print_handler_fn);
|
|
|
|
mono_trace_set_printerr_handler(mono_print_handler_fn);
|
|
|
|
|
2013-10-24 21:34:24 +02:00
|
|
|
mono_set_dirs(mono_lib_path_a, mono_etc_path_a);
|
2010-10-03 18:44:32 +02:00
|
|
|
|
2013-10-24 21:34:24 +02:00
|
|
|
mono_config_parse(NULL);
|
2010-10-03 18:44:32 +02:00
|
|
|
|
2013-10-29 22:14:49 +01:00
|
|
|
mono_install_assembly_preload_hook(mono_assembly_preload_hook_fn, NULL);
|
2010-10-05 22:50:01 +02:00
|
|
|
|
2010-10-03 18:44:32 +02:00
|
|
|
trace_size = GetEnvironmentVariableA("WINE_MONO_TRACE", trace_setting, sizeof(trace_setting));
|
|
|
|
|
|
|
|
if (trace_size)
|
|
|
|
{
|
2013-10-24 21:34:24 +02:00
|
|
|
mono_jit_set_trace_options(trace_setting);
|
2010-10-03 18:44:32 +02:00
|
|
|
}
|
2013-02-27 16:46:43 +01:00
|
|
|
|
|
|
|
verbose_size = GetEnvironmentVariableA("WINE_MONO_VERBOSE", verbose_setting, sizeof(verbose_setting));
|
|
|
|
|
|
|
|
if (verbose_size)
|
|
|
|
{
|
2013-10-24 21:34:24 +02:00
|
|
|
mono_set_verbose_level(verbose_setting[0] - '0');
|
2013-02-27 16:46:43 +01:00
|
|
|
}
|
2010-10-03 18:44:32 +02:00
|
|
|
}
|
2010-09-26 22:54:13 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2010-10-03 18:44:32 +02:00
|
|
|
|
|
|
|
fail:
|
|
|
|
ERR("Could not load Mono into this process\n");
|
2013-10-24 21:34:24 +02:00
|
|
|
FreeLibrary(mono_handle);
|
|
|
|
mono_handle = NULL;
|
2010-10-03 18:44:32 +02:00
|
|
|
return E_FAIL;
|
2010-09-26 22:54:13 +02:00
|
|
|
}
|
|
|
|
|
2020-02-19 17:11:05 +01:00
|
|
|
MonoDomain* get_root_domain(void)
|
|
|
|
{
|
|
|
|
static MonoDomain* root_domain;
|
|
|
|
|
|
|
|
if (root_domain != NULL)
|
|
|
|
return root_domain;
|
|
|
|
|
|
|
|
EnterCriticalSection(&runtime_list_cs);
|
|
|
|
|
|
|
|
if (root_domain == NULL)
|
|
|
|
{
|
|
|
|
/* FIXME: Use exe filename to name the domain? */
|
|
|
|
root_domain = mono_jit_init_version("mscorlib.dll", "v4.0.30319");
|
|
|
|
|
|
|
|
is_mono_started = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&runtime_list_cs);
|
|
|
|
|
|
|
|
return root_domain;
|
|
|
|
}
|
|
|
|
|
2016-01-20 16:03:40 +01:00
|
|
|
static void CDECL mono_shutdown_callback_fn(MonoProfiler *prof)
|
2011-02-21 21:22:02 +01:00
|
|
|
{
|
2013-10-24 21:34:24 +02:00
|
|
|
is_mono_shutdown = TRUE;
|
2011-02-21 21:22:02 +01:00
|
|
|
}
|
|
|
|
|
2016-01-20 16:03:40 +01:00
|
|
|
static void CDECL mono_print_handler_fn(const char *string, INT is_stdout)
|
2015-09-04 21:05:00 +02:00
|
|
|
{
|
2016-04-29 17:55:43 +02:00
|
|
|
const char *p;
|
|
|
|
for (; *string; string = p)
|
|
|
|
{
|
|
|
|
if ((p = strstr(string, "\n"))) p++;
|
|
|
|
else p = string + strlen(string);
|
|
|
|
wine_dbg_printf("%.*s", (int)(p - string), string);
|
|
|
|
}
|
2015-09-04 21:05:00 +02:00
|
|
|
}
|
|
|
|
|
2017-08-01 18:51:22 +02:00
|
|
|
static HRESULT WINAPI thread_set_fn(void)
|
|
|
|
{
|
|
|
|
WARN("stub\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI thread_unset_fn(void)
|
|
|
|
{
|
|
|
|
WARN("stub\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-26 22:54:13 +02:00
|
|
|
static HRESULT CLRRuntimeInfo_GetRuntimeHost(CLRRuntimeInfo *This, RuntimeHost **result)
|
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
2015-02-20 19:59:53 +01:00
|
|
|
WCHAR mono_path[MAX_PATH];
|
2010-09-26 22:54:13 +02:00
|
|
|
|
|
|
|
if (This->loaded_runtime)
|
|
|
|
{
|
|
|
|
*result = This->loaded_runtime;
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2019-04-13 18:27:33 +02:00
|
|
|
if (!get_mono_path(mono_path, FALSE))
|
2015-02-20 19:59:53 +01:00
|
|
|
{
|
2016-01-09 23:16:24 +01:00
|
|
|
ERR("Wine Mono is not installed\n");
|
2015-02-20 19:59:53 +01:00
|
|
|
return CLR_E_SHIM_RUNTIME;
|
|
|
|
}
|
|
|
|
|
2010-09-26 22:54:13 +02:00
|
|
|
EnterCriticalSection(&runtime_list_cs);
|
|
|
|
|
2017-08-01 18:51:22 +02:00
|
|
|
if (This->loaded_runtime)
|
|
|
|
{
|
|
|
|
*result = This->loaded_runtime;
|
2017-08-02 18:24:15 +02:00
|
|
|
LeaveCriticalSection(&runtime_list_cs);
|
2017-08-01 18:51:22 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GlobalCLRMetaHost.callback)
|
|
|
|
{
|
|
|
|
GlobalCLRMetaHost.callback(&This->ICLRRuntimeInfo_iface, thread_set_fn, thread_unset_fn);
|
|
|
|
}
|
|
|
|
|
2015-02-20 19:59:53 +01:00
|
|
|
hr = load_mono(mono_path);
|
2010-09-26 22:54:13 +02:00
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
2013-10-24 21:34:24 +02:00
|
|
|
hr = RuntimeHost_Construct(This, &This->loaded_runtime);
|
2010-09-26 22:54:13 +02:00
|
|
|
|
|
|
|
LeaveCriticalSection(&runtime_list_cs);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
*result = This->loaded_runtime;
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2011-02-21 21:22:02 +01:00
|
|
|
void expect_no_runtimes(void)
|
|
|
|
{
|
2013-10-24 21:34:24 +02:00
|
|
|
if (mono_handle && is_mono_started && !is_mono_shutdown)
|
2011-02-21 21:22:02 +01:00
|
|
|
{
|
2013-10-24 21:34:24 +02:00
|
|
|
ERR("Process exited with a Mono runtime loaded.\n");
|
|
|
|
return;
|
2011-02-21 21:22:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-19 00:43:17 +02:00
|
|
|
static inline CLRRuntimeInfo *impl_from_ICLRRuntimeInfo(ICLRRuntimeInfo *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, CLRRuntimeInfo, ICLRRuntimeInfo_iface);
|
|
|
|
}
|
|
|
|
|
2010-09-23 00:24:56 +02:00
|
|
|
static HRESULT WINAPI CLRRuntimeInfo_QueryInterface(ICLRRuntimeInfo* iface,
|
|
|
|
REFIID riid,
|
|
|
|
void **ppvObject)
|
|
|
|
{
|
|
|
|
TRACE("%p %s %p\n", iface, debugstr_guid(riid), ppvObject);
|
|
|
|
|
|
|
|
if ( IsEqualGUID( riid, &IID_ICLRRuntimeInfo ) ||
|
|
|
|
IsEqualGUID( riid, &IID_IUnknown ) )
|
|
|
|
{
|
|
|
|
*ppvObject = iface;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("Unsupported interface %s\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ICLRRuntimeInfo_AddRef( iface );
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI CLRRuntimeInfo_AddRef(ICLRRuntimeInfo* iface)
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI CLRRuntimeInfo_Release(ICLRRuntimeInfo* iface)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI CLRRuntimeInfo_GetVersionString(ICLRRuntimeInfo* iface,
|
|
|
|
LPWSTR pwzBuffer, DWORD *pcchBuffer)
|
|
|
|
{
|
2011-08-19 00:43:17 +02:00
|
|
|
struct CLRRuntimeInfo *This = impl_from_ICLRRuntimeInfo(iface);
|
2010-09-23 00:24:56 +02:00
|
|
|
DWORD buffer_size = *pcchBuffer;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
char version[11];
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
TRACE("%p %p %p\n", iface, pwzBuffer, pcchBuffer);
|
|
|
|
|
|
|
|
size = snprintf(version, sizeof(version), "v%u.%u.%u", This->major, This->minor, This->build);
|
|
|
|
|
|
|
|
assert(size <= sizeof(version));
|
|
|
|
|
|
|
|
*pcchBuffer = MultiByteToWideChar(CP_UTF8, 0, version, -1, NULL, 0);
|
|
|
|
|
|
|
|
if (pwzBuffer)
|
|
|
|
{
|
|
|
|
if (buffer_size >= *pcchBuffer)
|
|
|
|
MultiByteToWideChar(CP_UTF8, 0, version, -1, pwzBuffer, buffer_size);
|
|
|
|
else
|
2014-10-15 22:00:23 +02:00
|
|
|
hr = E_NOT_SUFFICIENT_BUFFER;
|
2010-09-23 00:24:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2010-10-05 20:35:47 +02:00
|
|
|
static BOOL get_install_root(LPWSTR install_dir)
|
|
|
|
{
|
2018-11-30 08:14:10 +01:00
|
|
|
static const WCHAR dotnet_key[] = {'S','O','F','T','W','A','R','E','\\','M','i','c','r','o','s','o','f','t','\\','.','N','E','T','F','r','a','m','e','w','o','r','k','\\',0};
|
|
|
|
static const WCHAR install_root[] = {'I','n','s','t','a','l','l','R','o','o','t',0};
|
2010-10-05 20:35:47 +02:00
|
|
|
|
|
|
|
DWORD len;
|
|
|
|
HKEY key;
|
|
|
|
|
|
|
|
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, dotnet_key, 0, KEY_READ, &key))
|
|
|
|
return FALSE;
|
|
|
|
|
2020-05-28 04:30:37 +02:00
|
|
|
len = MAX_PATH * sizeof(WCHAR);
|
2010-10-05 20:35:47 +02:00
|
|
|
if (RegQueryValueExW(key, install_root, 0, NULL, (LPBYTE)install_dir, &len))
|
|
|
|
{
|
|
|
|
RegCloseKey(key);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
RegCloseKey(key);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-09-23 00:24:56 +02:00
|
|
|
static HRESULT WINAPI CLRRuntimeInfo_GetRuntimeDirectory(ICLRRuntimeInfo* iface,
|
|
|
|
LPWSTR pwzBuffer, DWORD *pcchBuffer)
|
|
|
|
{
|
2010-10-05 20:35:47 +02:00
|
|
|
static const WCHAR slash[] = {'\\',0};
|
|
|
|
DWORD buffer_size = *pcchBuffer;
|
|
|
|
WCHAR system_dir[MAX_PATH];
|
|
|
|
WCHAR version[MAX_PATH];
|
|
|
|
DWORD version_size, size;
|
|
|
|
HRESULT hr = S_OK;
|
2010-09-23 00:24:56 +02:00
|
|
|
|
2010-10-05 20:35:47 +02:00
|
|
|
TRACE("%p %p %p\n", iface, pwzBuffer, pcchBuffer);
|
|
|
|
|
|
|
|
if (!get_install_root(system_dir))
|
|
|
|
{
|
|
|
|
ERR("error reading registry key for installroot\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
version_size = MAX_PATH;
|
|
|
|
ICLRRuntimeInfo_GetVersionString(iface, version, &version_size);
|
|
|
|
lstrcatW(system_dir, version);
|
|
|
|
lstrcatW(system_dir, slash);
|
|
|
|
size = lstrlenW(system_dir) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pcchBuffer = size;
|
|
|
|
|
|
|
|
if (pwzBuffer)
|
|
|
|
{
|
|
|
|
if (buffer_size >= size)
|
2019-07-05 12:55:54 +02:00
|
|
|
lstrcpyW(pwzBuffer, system_dir);
|
2010-10-05 20:35:47 +02:00
|
|
|
else
|
2014-10-15 22:00:23 +02:00
|
|
|
hr = E_NOT_SUFFICIENT_BUFFER;
|
2010-10-05 20:35:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2010-09-23 00:24:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI CLRRuntimeInfo_IsLoaded(ICLRRuntimeInfo* iface,
|
|
|
|
HANDLE hndProcess, BOOL *pbLoaded)
|
|
|
|
{
|
|
|
|
FIXME("%p %p %p\n", iface, hndProcess, pbLoaded);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI CLRRuntimeInfo_LoadErrorString(ICLRRuntimeInfo* iface,
|
|
|
|
UINT iResourceID, LPWSTR pwzBuffer, DWORD *pcchBuffer, LONG iLocaleid)
|
|
|
|
{
|
|
|
|
FIXME("%p %u %p %p %x\n", iface, iResourceID, pwzBuffer, pcchBuffer, iLocaleid);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI CLRRuntimeInfo_LoadLibrary(ICLRRuntimeInfo* iface,
|
|
|
|
LPCWSTR pwzDllName, HMODULE *phndModule)
|
|
|
|
{
|
2010-10-27 17:51:19 +02:00
|
|
|
WCHAR version[MAX_PATH];
|
|
|
|
HRESULT hr;
|
|
|
|
DWORD cchBuffer;
|
2010-09-23 00:24:56 +02:00
|
|
|
|
2010-10-27 17:51:19 +02:00
|
|
|
TRACE("%p %s %p\n", iface, debugstr_w(pwzDllName), phndModule);
|
|
|
|
|
|
|
|
cchBuffer = MAX_PATH;
|
|
|
|
hr = ICLRRuntimeInfo_GetVersionString(iface, version, &cchBuffer);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
return LoadLibraryShim(pwzDllName, version, NULL, phndModule);
|
2010-09-23 00:24:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI CLRRuntimeInfo_GetProcAddress(ICLRRuntimeInfo* iface,
|
|
|
|
LPCSTR pszProcName, LPVOID *ppProc)
|
|
|
|
{
|
|
|
|
FIXME("%p %s %p\n", iface, debugstr_a(pszProcName), ppProc);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI CLRRuntimeInfo_GetInterface(ICLRRuntimeInfo* iface,
|
|
|
|
REFCLSID rclsid, REFIID riid, LPVOID *ppUnk)
|
|
|
|
{
|
2011-08-19 00:43:17 +02:00
|
|
|
struct CLRRuntimeInfo *This = impl_from_ICLRRuntimeInfo(iface);
|
2010-09-26 22:54:13 +02:00
|
|
|
RuntimeHost *host;
|
|
|
|
HRESULT hr;
|
2010-09-23 00:24:56 +02:00
|
|
|
|
2010-09-26 22:54:13 +02:00
|
|
|
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;
|
2010-09-23 00:24:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI CLRRuntimeInfo_IsLoadable(ICLRRuntimeInfo* iface,
|
|
|
|
BOOL *pbLoadable)
|
|
|
|
{
|
|
|
|
FIXME("%p %p\n", iface, pbLoadable);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI CLRRuntimeInfo_SetDefaultStartupFlags(ICLRRuntimeInfo* iface,
|
|
|
|
DWORD dwStartupFlags, LPCWSTR pwzHostConfigFile)
|
|
|
|
{
|
|
|
|
FIXME("%p %x %s\n", iface, dwStartupFlags, debugstr_w(pwzHostConfigFile));
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI CLRRuntimeInfo_GetDefaultStartupFlags(ICLRRuntimeInfo* iface,
|
|
|
|
DWORD *pdwStartupFlags, LPWSTR pwzHostConfigFile, DWORD *pcchHostConfigFile)
|
|
|
|
{
|
|
|
|
FIXME("%p %p %p %p\n", iface, pdwStartupFlags, pwzHostConfigFile, pcchHostConfigFile);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI CLRRuntimeInfo_BindAsLegacyV2Runtime(ICLRRuntimeInfo* iface)
|
|
|
|
{
|
|
|
|
FIXME("%p\n", iface);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI CLRRuntimeInfo_IsStarted(ICLRRuntimeInfo* iface,
|
|
|
|
BOOL *pbStarted, DWORD *pdwStartupFlags)
|
|
|
|
{
|
|
|
|
FIXME("%p %p %p\n", iface, pbStarted, pdwStartupFlags);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2011-05-13 17:31:09 +02:00
|
|
|
static const struct ICLRRuntimeInfoVtbl CLRRuntimeInfoVtbl = {
|
2010-09-23 00:24:56 +02:00
|
|
|
CLRRuntimeInfo_QueryInterface,
|
|
|
|
CLRRuntimeInfo_AddRef,
|
|
|
|
CLRRuntimeInfo_Release,
|
|
|
|
CLRRuntimeInfo_GetVersionString,
|
|
|
|
CLRRuntimeInfo_GetRuntimeDirectory,
|
|
|
|
CLRRuntimeInfo_IsLoaded,
|
|
|
|
CLRRuntimeInfo_LoadErrorString,
|
|
|
|
CLRRuntimeInfo_LoadLibrary,
|
|
|
|
CLRRuntimeInfo_GetProcAddress,
|
|
|
|
CLRRuntimeInfo_GetInterface,
|
|
|
|
CLRRuntimeInfo_IsLoadable,
|
|
|
|
CLRRuntimeInfo_SetDefaultStartupFlags,
|
|
|
|
CLRRuntimeInfo_GetDefaultStartupFlags,
|
|
|
|
CLRRuntimeInfo_BindAsLegacyV2Runtime,
|
|
|
|
CLRRuntimeInfo_IsStarted
|
|
|
|
};
|
|
|
|
|
2010-10-03 20:24:01 +02:00
|
|
|
HRESULT ICLRRuntimeInfo_GetRuntimeHost(ICLRRuntimeInfo *iface, RuntimeHost **result)
|
|
|
|
{
|
2011-08-19 00:43:17 +02:00
|
|
|
struct CLRRuntimeInfo *This = impl_from_ICLRRuntimeInfo(iface);
|
2010-10-03 20:24:01 +02:00
|
|
|
|
2011-08-19 00:43:17 +02:00
|
|
|
assert(This->ICLRRuntimeInfo_iface.lpVtbl == &CLRRuntimeInfoVtbl);
|
2010-10-03 20:24:01 +02:00
|
|
|
|
|
|
|
return CLRRuntimeInfo_GetRuntimeHost(This, result);
|
|
|
|
}
|
|
|
|
|
2012-03-19 18:54:55 +01:00
|
|
|
#ifdef __i386__
|
|
|
|
static const WCHAR libmono2_arch_dll[] = {'\\','b','i','n','\\','l','i','b','m','o','n','o','-','2','.','0','-','x','8','6','.','d','l','l',0};
|
|
|
|
#elif defined(__x86_64__)
|
|
|
|
static const WCHAR libmono2_arch_dll[] = {'\\','b','i','n','\\','l','i','b','m','o','n','o','-','2','.','0','-','x','8','6','_','6','4','.','d','l','l',0};
|
|
|
|
#else
|
|
|
|
static const WCHAR libmono2_arch_dll[] = {'\\','b','i','n','\\','l','i','b','m','o','n','o','-','2','.','0','.','d','l','l',0};
|
|
|
|
#endif
|
|
|
|
|
2013-10-24 21:34:24 +02:00
|
|
|
static BOOL find_mono_dll(LPCWSTR path, LPWSTR dll_path)
|
2010-09-23 00:24:56 +02:00
|
|
|
{
|
2010-10-03 21:36:02 +02:00
|
|
|
static const WCHAR mono2_dll[] = {'\\','b','i','n','\\','m','o','n','o','-','2','.','0','.','d','l','l',0};
|
|
|
|
static const WCHAR libmono2_dll[] = {'\\','b','i','n','\\','l','i','b','m','o','n','o','-','2','.','0','.','d','l','l',0};
|
2010-09-23 00:24:56 +02:00
|
|
|
DWORD attributes=INVALID_FILE_ATTRIBUTES;
|
|
|
|
|
2019-07-05 12:55:54 +02:00
|
|
|
lstrcpyW(dll_path, path);
|
|
|
|
lstrcatW(dll_path, libmono2_arch_dll);
|
2013-10-24 21:34:24 +02:00
|
|
|
attributes = GetFileAttributesW(dll_path);
|
|
|
|
|
|
|
|
if (attributes == INVALID_FILE_ATTRIBUTES)
|
2010-09-23 00:24:56 +02:00
|
|
|
{
|
2019-07-05 12:55:54 +02:00
|
|
|
lstrcpyW(dll_path, path);
|
|
|
|
lstrcatW(dll_path, mono2_dll);
|
2010-09-23 00:24:56 +02:00
|
|
|
attributes = GetFileAttributesW(dll_path);
|
|
|
|
}
|
2013-10-24 21:34:24 +02:00
|
|
|
|
|
|
|
if (attributes == INVALID_FILE_ATTRIBUTES)
|
2010-10-03 21:36:02 +02:00
|
|
|
{
|
2019-07-05 12:55:54 +02:00
|
|
|
lstrcpyW(dll_path, path);
|
|
|
|
lstrcatW(dll_path, libmono2_dll);
|
2010-10-03 21:36:02 +02:00
|
|
|
attributes = GetFileAttributesW(dll_path);
|
|
|
|
}
|
2010-09-23 00:24:56 +02:00
|
|
|
|
|
|
|
return (attributes != INVALID_FILE_ATTRIBUTES);
|
|
|
|
}
|
|
|
|
|
2019-04-04 17:05:30 +02:00
|
|
|
static BOOL get_mono_path_local(LPWSTR path)
|
2010-09-23 00:24:56 +02:00
|
|
|
{
|
2016-01-09 23:16:23 +01:00
|
|
|
static const WCHAR subdir_mono[] = {'\\','m','o','n','o','\\','m','o','n','o','-','2','.','0', 0};
|
|
|
|
WCHAR base_path[MAX_PATH], mono_dll_path[MAX_PATH];
|
2010-09-23 00:24:56 +02:00
|
|
|
|
2016-01-09 23:16:23 +01:00
|
|
|
/* c:\windows\mono\mono-2.0 */
|
2010-09-23 00:24:56 +02:00
|
|
|
GetWindowsDirectoryW(base_path, MAX_PATH);
|
2019-07-05 12:55:54 +02:00
|
|
|
lstrcatW(base_path, subdir_mono);
|
2010-09-23 00:24:56 +02:00
|
|
|
|
2016-01-09 23:16:23 +01:00
|
|
|
if (find_mono_dll(base_path, mono_dll_path))
|
2010-09-23 00:24:56 +02:00
|
|
|
{
|
2019-07-05 12:55:54 +02:00
|
|
|
lstrcpyW(path, base_path);
|
2016-01-09 23:16:23 +01:00
|
|
|
return TRUE;
|
2010-09-23 00:24:56 +02:00
|
|
|
}
|
|
|
|
|
2016-01-09 23:16:23 +01:00
|
|
|
return FALSE;
|
2010-09-23 00:24:56 +02:00
|
|
|
}
|
|
|
|
|
2019-04-04 17:05:30 +02:00
|
|
|
static BOOL get_mono_path_registry(LPWSTR path)
|
|
|
|
{
|
|
|
|
static const WCHAR keyname[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\','M','o','n','o',0};
|
|
|
|
static const WCHAR valuename[] = {'R','u','n','t','i','m','e','P','a','t','h',0};
|
|
|
|
WCHAR base_path[MAX_PATH], mono_dll_path[MAX_PATH];
|
|
|
|
HKEY hkey;
|
|
|
|
DWORD res, valuesize;
|
|
|
|
BOOL ret=FALSE;
|
|
|
|
|
|
|
|
/* @@ Wine registry key: HKCU\Software\Wine\Mono */
|
|
|
|
res = RegOpenKeyW(HKEY_CURRENT_USER, keyname, &hkey);
|
|
|
|
if (res != ERROR_SUCCESS)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
valuesize = sizeof(base_path);
|
|
|
|
res = RegGetValueW(hkey, NULL, valuename, RRF_RT_REG_SZ, NULL, base_path, &valuesize);
|
|
|
|
if (res == ERROR_SUCCESS && find_mono_dll(base_path, mono_dll_path))
|
|
|
|
{
|
2019-07-05 12:55:54 +02:00
|
|
|
lstrcpyW(path, base_path);
|
2019-04-04 17:05:30 +02:00
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(hkey);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-07-05 12:55:54 +02:00
|
|
|
static BOOL get_mono_path_dos(const WCHAR *dir, LPWSTR path)
|
2019-04-04 17:05:31 +02:00
|
|
|
{
|
2019-04-08 18:03:56 +02:00
|
|
|
static const WCHAR unix_prefix[] = {'\\','\\','?','\\','u','n','i','x','\\'};
|
2019-11-17 16:09:37 +01:00
|
|
|
static const WCHAR basedir[] = L"\\wine-mono-" WINE_MONO_VERSION;
|
2019-04-04 17:05:31 +02:00
|
|
|
LPWSTR dos_dir;
|
|
|
|
WCHAR mono_dll_path[MAX_PATH];
|
2019-07-05 12:55:54 +02:00
|
|
|
DWORD len;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (memcmp(dir, unix_prefix, sizeof(unix_prefix)) == 0)
|
|
|
|
return FALSE; /* No drive letter for this directory */
|
|
|
|
|
2019-11-17 16:09:37 +01:00
|
|
|
len = lstrlenW( dir ) + lstrlenW( basedir ) + 1;
|
2019-07-05 12:55:54 +02:00
|
|
|
if (!(dos_dir = heap_alloc( len * sizeof(WCHAR) ))) return FALSE;
|
|
|
|
lstrcpyW( dos_dir, dir );
|
2019-11-17 16:09:37 +01:00
|
|
|
lstrcatW( dos_dir, basedir );
|
2019-07-05 12:55:54 +02:00
|
|
|
|
|
|
|
ret = find_mono_dll(dos_dir, mono_dll_path);
|
|
|
|
if (ret)
|
|
|
|
lstrcpyW(path, dos_dir);
|
|
|
|
|
|
|
|
heap_free(dos_dir);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL get_mono_path_unix(const char *unix_dir, LPWSTR path)
|
|
|
|
{
|
|
|
|
static WCHAR * (CDECL *p_wine_get_dos_file_name)(const char*);
|
|
|
|
LPWSTR dos_dir;
|
2019-04-04 17:05:31 +02:00
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (!p_wine_get_dos_file_name)
|
|
|
|
{
|
|
|
|
p_wine_get_dos_file_name = (void*)GetProcAddress(GetModuleHandleA("kernel32"), "wine_get_dos_file_name");
|
|
|
|
if (!p_wine_get_dos_file_name)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
dos_dir = p_wine_get_dos_file_name(unix_dir);
|
|
|
|
if (!dos_dir)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-07-05 12:55:54 +02:00
|
|
|
ret = get_mono_path_dos( dos_dir, path);
|
2019-04-04 17:05:31 +02:00
|
|
|
|
|
|
|
heap_free(dos_dir);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL get_mono_path_datadir(LPWSTR path)
|
|
|
|
{
|
2019-07-05 12:55:54 +02:00
|
|
|
static const WCHAR winedatadirW[] = {'W','I','N','E','D','A','T','A','D','I','R',0};
|
|
|
|
static const WCHAR winebuilddirW[] = {'W','I','N','E','B','U','I','L','D','D','I','R',0};
|
|
|
|
static const WCHAR unix_prefix[] = {'\\','?','?','\\','u','n','i','x','\\'};
|
|
|
|
static const WCHAR monoW[] = {'\\','m','o','n','o',0};
|
2020-03-23 14:32:22 +01:00
|
|
|
static const WCHAR dotdotmonoW[] = {'\\','.','.','\\','m','o','n','o',0};
|
2019-07-05 12:55:54 +02:00
|
|
|
const WCHAR *data_dir, *suffix;
|
|
|
|
WCHAR *package_dir;
|
2019-04-04 17:05:31 +02:00
|
|
|
BOOL ret;
|
|
|
|
|
2019-07-05 12:55:54 +02:00
|
|
|
if ((data_dir = _wgetenv( winedatadirW )))
|
|
|
|
suffix = monoW;
|
|
|
|
else if ((data_dir = _wgetenv( winebuilddirW )))
|
2020-03-23 14:32:22 +01:00
|
|
|
suffix = dotdotmonoW;
|
2019-04-04 17:05:31 +02:00
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
|
2019-07-05 12:55:54 +02:00
|
|
|
if (!wcsncmp( data_dir, unix_prefix, wcslen(unix_prefix) )) return FALSE;
|
|
|
|
data_dir += 4; /* skip \??\ prefix */
|
|
|
|
package_dir = heap_alloc( (lstrlenW(data_dir) + lstrlenW(suffix) + 1) * sizeof(WCHAR));
|
|
|
|
lstrcpyW( package_dir, data_dir );
|
|
|
|
lstrcatW( package_dir, suffix );
|
|
|
|
|
|
|
|
ret = get_mono_path_dos(package_dir, path);
|
2019-04-04 17:05:31 +02:00
|
|
|
|
|
|
|
heap_free(package_dir);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-04-13 18:27:33 +02:00
|
|
|
BOOL get_mono_path(LPWSTR path, BOOL skip_local)
|
2019-04-04 17:05:30 +02:00
|
|
|
{
|
2019-04-13 18:27:33 +02:00
|
|
|
return (!skip_local && get_mono_path_local(path)) ||
|
2019-04-04 17:05:31 +02:00
|
|
|
get_mono_path_registry(path) ||
|
|
|
|
get_mono_path_datadir(path) ||
|
2019-07-05 12:55:54 +02:00
|
|
|
get_mono_path_unix(INSTALL_DATADIR "/wine/mono", path) ||
|
2019-04-04 17:05:31 +02:00
|
|
|
(strcmp(INSTALL_DATADIR, "/usr/share") &&
|
2019-07-05 12:55:54 +02:00
|
|
|
get_mono_path_unix("/usr/share/wine/mono", path)) ||
|
|
|
|
get_mono_path_unix("/opt/wine/mono", path);
|
2019-04-04 17:05:30 +02:00
|
|
|
}
|
|
|
|
|
2010-09-23 00:24:56 +02:00
|
|
|
struct InstalledRuntimeEnum
|
|
|
|
{
|
2011-03-14 10:23:01 +01:00
|
|
|
IEnumUnknown IEnumUnknown_iface;
|
2010-09-23 00:24:56 +02:00
|
|
|
LONG ref;
|
|
|
|
ULONG pos;
|
|
|
|
};
|
|
|
|
|
2011-05-13 17:31:09 +02:00
|
|
|
static const struct IEnumUnknownVtbl InstalledRuntimeEnum_Vtbl;
|
2010-09-23 00:24:56 +02:00
|
|
|
|
2011-03-14 10:23:01 +01:00
|
|
|
static inline struct InstalledRuntimeEnum *impl_from_IEnumUnknown(IEnumUnknown *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct InstalledRuntimeEnum, IEnumUnknown_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI InstalledRuntimeEnum_QueryInterface(IEnumUnknown* iface, REFIID riid,
|
2010-09-23 00:24:56 +02:00
|
|
|
void **ppvObject)
|
|
|
|
{
|
|
|
|
TRACE("%p %s %p\n", iface, debugstr_guid(riid), ppvObject);
|
|
|
|
|
|
|
|
if ( IsEqualGUID( riid, &IID_IEnumUnknown ) ||
|
|
|
|
IsEqualGUID( riid, &IID_IUnknown ) )
|
|
|
|
{
|
|
|
|
*ppvObject = iface;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("Unsupported interface %s\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IEnumUnknown_AddRef( iface );
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI InstalledRuntimeEnum_AddRef(IEnumUnknown* iface)
|
|
|
|
{
|
2011-03-14 10:23:01 +01:00
|
|
|
struct InstalledRuntimeEnum *This = impl_from_IEnumUnknown(iface);
|
2010-09-23 00:24:56 +02:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) refcount=%u\n", iface, ref);
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI InstalledRuntimeEnum_Release(IEnumUnknown* iface)
|
|
|
|
{
|
2011-03-14 10:23:01 +01:00
|
|
|
struct InstalledRuntimeEnum *This = impl_from_IEnumUnknown(iface);
|
2010-09-23 00:24:56 +02:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) refcount=%u\n", iface, ref);
|
|
|
|
|
|
|
|
if (ref == 0)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI InstalledRuntimeEnum_Next(IEnumUnknown *iface, ULONG celt,
|
|
|
|
IUnknown **rgelt, ULONG *pceltFetched)
|
|
|
|
{
|
2011-03-14 10:23:01 +01:00
|
|
|
struct InstalledRuntimeEnum *This = impl_from_IEnumUnknown(iface);
|
2013-02-12 23:20:14 +01:00
|
|
|
ULONG num_fetched = 0;
|
2010-09-23 00:24:56 +02:00
|
|
|
HRESULT hr=S_OK;
|
|
|
|
IUnknown *item;
|
|
|
|
|
|
|
|
TRACE("(%p,%u,%p,%p)\n", iface, celt, rgelt, pceltFetched);
|
|
|
|
|
|
|
|
while (num_fetched < celt)
|
|
|
|
{
|
|
|
|
if (This->pos >= NUM_RUNTIMES)
|
|
|
|
{
|
|
|
|
hr = S_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2015-02-20 19:59:53 +01:00
|
|
|
item = (IUnknown*)&runtimes[This->pos].ICLRRuntimeInfo_iface;
|
|
|
|
IUnknown_AddRef(item);
|
|
|
|
rgelt[num_fetched] = item;
|
|
|
|
num_fetched++;
|
2010-09-23 00:24:56 +02:00
|
|
|
This->pos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pceltFetched)
|
|
|
|
*pceltFetched = num_fetched;
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI InstalledRuntimeEnum_Skip(IEnumUnknown *iface, ULONG celt)
|
|
|
|
{
|
2011-03-14 10:23:01 +01:00
|
|
|
struct InstalledRuntimeEnum *This = impl_from_IEnumUnknown(iface);
|
2013-02-12 23:20:14 +01:00
|
|
|
ULONG num_fetched = 0;
|
2010-09-23 00:24:56 +02:00
|
|
|
HRESULT hr=S_OK;
|
|
|
|
|
|
|
|
TRACE("(%p,%u)\n", iface, celt);
|
|
|
|
|
|
|
|
while (num_fetched < celt)
|
|
|
|
{
|
|
|
|
if (This->pos >= NUM_RUNTIMES)
|
|
|
|
{
|
|
|
|
hr = S_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2015-02-20 19:59:53 +01:00
|
|
|
num_fetched++;
|
2010-09-23 00:24:56 +02:00
|
|
|
This->pos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI InstalledRuntimeEnum_Reset(IEnumUnknown *iface)
|
|
|
|
{
|
2011-03-14 10:23:01 +01:00
|
|
|
struct InstalledRuntimeEnum *This = impl_from_IEnumUnknown(iface);
|
2010-09-23 00:24:56 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", iface);
|
|
|
|
|
|
|
|
This->pos = 0;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI InstalledRuntimeEnum_Clone(IEnumUnknown *iface, IEnumUnknown **ppenum)
|
|
|
|
{
|
2011-03-14 10:23:01 +01:00
|
|
|
struct InstalledRuntimeEnum *This = impl_from_IEnumUnknown(iface);
|
2010-09-23 00:24:56 +02:00
|
|
|
struct InstalledRuntimeEnum *new_enum;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", iface);
|
|
|
|
|
|
|
|
new_enum = HeapAlloc(GetProcessHeap(), 0, sizeof(*new_enum));
|
|
|
|
if (!new_enum)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2011-03-14 10:23:01 +01:00
|
|
|
new_enum->IEnumUnknown_iface.lpVtbl = &InstalledRuntimeEnum_Vtbl;
|
2010-09-23 00:24:56 +02:00
|
|
|
new_enum->ref = 1;
|
|
|
|
new_enum->pos = This->pos;
|
|
|
|
|
2011-03-14 10:23:01 +01:00
|
|
|
*ppenum = &new_enum->IEnumUnknown_iface;
|
2010-09-23 00:24:56 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-13 17:31:09 +02:00
|
|
|
static const struct IEnumUnknownVtbl InstalledRuntimeEnum_Vtbl = {
|
2010-09-23 00:24:56 +02:00
|
|
|
InstalledRuntimeEnum_QueryInterface,
|
|
|
|
InstalledRuntimeEnum_AddRef,
|
|
|
|
InstalledRuntimeEnum_Release,
|
|
|
|
InstalledRuntimeEnum_Next,
|
|
|
|
InstalledRuntimeEnum_Skip,
|
|
|
|
InstalledRuntimeEnum_Reset,
|
|
|
|
InstalledRuntimeEnum_Clone
|
|
|
|
};
|
|
|
|
|
2010-09-22 21:09:04 +02:00
|
|
|
static HRESULT WINAPI CLRMetaHost_QueryInterface(ICLRMetaHost* iface,
|
|
|
|
REFIID riid,
|
|
|
|
void **ppvObject)
|
|
|
|
{
|
|
|
|
TRACE("%s %p\n", debugstr_guid(riid), ppvObject);
|
|
|
|
|
|
|
|
if ( IsEqualGUID( riid, &IID_ICLRMetaHost ) ||
|
|
|
|
IsEqualGUID( riid, &IID_IUnknown ) )
|
|
|
|
{
|
|
|
|
*ppvObject = iface;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("Unsupported interface %s\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ICLRMetaHost_AddRef( iface );
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI CLRMetaHost_AddRef(ICLRMetaHost* iface)
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI CLRMetaHost_Release(ICLRMetaHost* iface)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-05-16 17:00:13 +02:00
|
|
|
static inline BOOL isDigit(WCHAR c)
|
|
|
|
{
|
|
|
|
return c >= '0' && c <= '9';
|
|
|
|
}
|
|
|
|
|
2010-09-29 00:53:14 +02:00
|
|
|
static BOOL parse_runtime_version(LPCWSTR version, DWORD *major, DWORD *minor, DWORD *build)
|
|
|
|
{
|
|
|
|
*major = 0;
|
|
|
|
*minor = 0;
|
|
|
|
*build = 0;
|
|
|
|
|
2012-03-15 12:40:25 +01:00
|
|
|
if (version[0] == 'v' || version[0] == 'V')
|
2010-09-29 00:53:14 +02:00
|
|
|
{
|
|
|
|
version++;
|
2017-05-16 17:00:13 +02:00
|
|
|
if (!isDigit(*version))
|
2010-09-29 00:53:14 +02:00
|
|
|
return FALSE;
|
|
|
|
|
2017-05-16 17:00:13 +02:00
|
|
|
while (isDigit(*version))
|
2010-09-29 00:53:14 +02:00
|
|
|
*major = *major * 10 + (*version++ - '0');
|
|
|
|
|
|
|
|
if (*version == 0)
|
|
|
|
return TRUE;
|
|
|
|
|
2017-05-16 17:00:13 +02:00
|
|
|
if (*version++ != '.' || !isDigit(*version))
|
2010-09-29 00:53:14 +02:00
|
|
|
return FALSE;
|
|
|
|
|
2017-05-16 17:00:13 +02:00
|
|
|
while (isDigit(*version))
|
2010-09-29 00:53:14 +02:00
|
|
|
*minor = *minor * 10 + (*version++ - '0');
|
|
|
|
|
|
|
|
if (*version == 0)
|
|
|
|
return TRUE;
|
|
|
|
|
2017-05-16 17:00:13 +02:00
|
|
|
if (*version++ != '.' || !isDigit(*version))
|
2010-09-29 00:53:14 +02:00
|
|
|
return FALSE;
|
|
|
|
|
2017-05-16 17:00:13 +02:00
|
|
|
while (isDigit(*version))
|
2010-09-29 00:53:14 +02:00
|
|
|
*build = *build * 10 + (*version++ - '0');
|
|
|
|
|
|
|
|
return *version == 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-07-14 22:55:18 +02:00
|
|
|
static HRESULT get_runtime(LPCWSTR pwzVersion, BOOL allow_short,
|
|
|
|
REFIID iid, LPVOID *ppRuntime)
|
2010-09-22 21:09:04 +02:00
|
|
|
{
|
2010-09-29 00:53:14 +02:00
|
|
|
int i;
|
|
|
|
DWORD major, minor, build;
|
2010-09-22 21:09:04 +02:00
|
|
|
|
2010-09-29 00:53:14 +02:00
|
|
|
if (!pwzVersion)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
if (!parse_runtime_version(pwzVersion, &major, &minor, &build))
|
|
|
|
{
|
|
|
|
ERR("Cannot parse %s\n", debugstr_w(pwzVersion));
|
|
|
|
return CLR_E_SHIM_RUNTIME;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; i<NUM_RUNTIMES; i++)
|
|
|
|
{
|
|
|
|
if (runtimes[i].major == major && runtimes[i].minor == minor &&
|
2014-07-14 22:55:18 +02:00
|
|
|
(runtimes[i].build == build || (allow_short && major >= 4 && build == 0)))
|
2010-09-29 00:53:14 +02:00
|
|
|
{
|
2015-02-20 19:59:53 +01:00
|
|
|
return ICLRRuntimeInfo_QueryInterface(&runtimes[i].ICLRRuntimeInfo_iface, iid,
|
|
|
|
ppRuntime);
|
2010-09-29 00:53:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME("Unrecognized version %s\n", debugstr_w(pwzVersion));
|
|
|
|
return CLR_E_SHIM_RUNTIME;
|
2010-09-22 21:09:04 +02:00
|
|
|
}
|
|
|
|
|
2014-07-14 22:55:18 +02:00
|
|
|
HRESULT WINAPI CLRMetaHost_GetRuntime(ICLRMetaHost* iface,
|
|
|
|
LPCWSTR pwzVersion, REFIID iid, LPVOID *ppRuntime)
|
|
|
|
{
|
|
|
|
TRACE("%s %s %p\n", debugstr_w(pwzVersion), debugstr_guid(iid), ppRuntime);
|
|
|
|
|
|
|
|
return get_runtime(pwzVersion, FALSE, iid, ppRuntime);
|
|
|
|
}
|
|
|
|
|
2011-01-27 23:05:34 +01:00
|
|
|
HRESULT WINAPI CLRMetaHost_GetVersionFromFile(ICLRMetaHost* iface,
|
2010-09-22 21:09:04 +02:00
|
|
|
LPCWSTR pwzFilePath, LPWSTR pwzBuffer, DWORD *pcchBuffer)
|
|
|
|
{
|
2010-09-22 22:27:52 +02:00
|
|
|
ASSEMBLY *assembly;
|
|
|
|
HRESULT hr;
|
|
|
|
LPSTR version;
|
|
|
|
ULONG buffer_size=*pcchBuffer;
|
2010-09-22 21:09:04 +02:00
|
|
|
|
2010-09-22 22:27:52 +02:00
|
|
|
TRACE("%s %p %p\n", debugstr_w(pwzFilePath), pwzBuffer, pcchBuffer);
|
|
|
|
|
|
|
|
hr = assembly_create(&assembly, pwzFilePath);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = assembly_get_runtime_version(assembly, &version);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
*pcchBuffer = MultiByteToWideChar(CP_UTF8, 0, version, -1, NULL, 0);
|
|
|
|
|
|
|
|
if (pwzBuffer)
|
|
|
|
{
|
|
|
|
if (buffer_size >= *pcchBuffer)
|
|
|
|
MultiByteToWideChar(CP_UTF8, 0, version, -1, pwzBuffer, buffer_size);
|
|
|
|
else
|
2014-10-15 22:00:23 +02:00
|
|
|
hr = E_NOT_SUFFICIENT_BUFFER;
|
2010-09-22 22:27:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assembly_release(assembly);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2010-09-22 21:09:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI CLRMetaHost_EnumerateInstalledRuntimes(ICLRMetaHost* iface,
|
|
|
|
IEnumUnknown **ppEnumerator)
|
|
|
|
{
|
2010-09-23 00:24:56 +02:00
|
|
|
struct InstalledRuntimeEnum *new_enum;
|
2010-09-22 21:09:04 +02:00
|
|
|
|
2010-09-23 00:24:56 +02:00
|
|
|
TRACE("%p\n", ppEnumerator);
|
|
|
|
|
|
|
|
new_enum = HeapAlloc(GetProcessHeap(), 0, sizeof(*new_enum));
|
|
|
|
if (!new_enum)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2011-03-14 10:23:01 +01:00
|
|
|
new_enum->IEnumUnknown_iface.lpVtbl = &InstalledRuntimeEnum_Vtbl;
|
2010-09-23 00:24:56 +02:00
|
|
|
new_enum->ref = 1;
|
|
|
|
new_enum->pos = 0;
|
|
|
|
|
2011-03-14 10:23:01 +01:00
|
|
|
*ppEnumerator = &new_enum->IEnumUnknown_iface;
|
2010-09-23 00:24:56 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2010-09-22 21:09:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI CLRMetaHost_EnumerateLoadedRuntimes(ICLRMetaHost* iface,
|
|
|
|
HANDLE hndProcess, IEnumUnknown **ppEnumerator)
|
|
|
|
{
|
|
|
|
FIXME("%p %p\n", hndProcess, ppEnumerator);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI CLRMetaHost_RequestRuntimeLoadedNotification(ICLRMetaHost* iface,
|
|
|
|
RuntimeLoadedCallbackFnPtr pCallbackFunction)
|
|
|
|
{
|
2013-10-02 04:13:54 +02:00
|
|
|
TRACE("%p\n", pCallbackFunction);
|
2010-09-22 21:09:04 +02:00
|
|
|
|
2013-10-02 04:13:54 +02:00
|
|
|
if(!pCallbackFunction)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2017-08-01 18:51:22 +02:00
|
|
|
if (GlobalCLRMetaHost.callback)
|
|
|
|
return HOST_E_INVALIDOPERATION;
|
2013-10-02 04:13:54 +02:00
|
|
|
|
|
|
|
GlobalCLRMetaHost.callback = pCallbackFunction;
|
|
|
|
|
|
|
|
return S_OK;
|
2010-09-22 21:09:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI CLRMetaHost_QueryLegacyV2RuntimeBinding(ICLRMetaHost* iface,
|
|
|
|
REFIID riid, LPVOID *ppUnk)
|
|
|
|
{
|
|
|
|
FIXME("%s %p\n", debugstr_guid(riid), ppUnk);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2013-10-24 23:01:11 +02:00
|
|
|
HRESULT WINAPI CLRMetaHost_ExitProcess(ICLRMetaHost* iface, INT32 iExitCode)
|
2010-09-22 21:09:04 +02:00
|
|
|
{
|
2013-10-24 23:01:11 +02:00
|
|
|
TRACE("%i\n", iExitCode);
|
|
|
|
|
|
|
|
EnterCriticalSection(&runtime_list_cs);
|
|
|
|
|
|
|
|
if (is_mono_started && !is_mono_shutdown)
|
|
|
|
{
|
|
|
|
/* search for a runtime and call System.Environment.Exit() */
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<NUM_RUNTIMES; i++)
|
|
|
|
if (runtimes[i].loaded_runtime)
|
|
|
|
RuntimeHost_ExitProcess(runtimes[i].loaded_runtime, iExitCode);
|
|
|
|
}
|
2010-09-22 21:09:04 +02:00
|
|
|
|
|
|
|
ExitProcess(iExitCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct ICLRMetaHostVtbl CLRMetaHost_vtbl =
|
|
|
|
{
|
|
|
|
CLRMetaHost_QueryInterface,
|
|
|
|
CLRMetaHost_AddRef,
|
|
|
|
CLRMetaHost_Release,
|
|
|
|
CLRMetaHost_GetRuntime,
|
|
|
|
CLRMetaHost_GetVersionFromFile,
|
|
|
|
CLRMetaHost_EnumerateInstalledRuntimes,
|
|
|
|
CLRMetaHost_EnumerateLoadedRuntimes,
|
|
|
|
CLRMetaHost_RequestRuntimeLoadedNotification,
|
|
|
|
CLRMetaHost_QueryLegacyV2RuntimeBinding,
|
|
|
|
CLRMetaHost_ExitProcess
|
|
|
|
};
|
|
|
|
|
2011-03-14 10:23:01 +01:00
|
|
|
static struct CLRMetaHost GlobalCLRMetaHost = {
|
|
|
|
{ &CLRMetaHost_vtbl }
|
2010-09-22 21:09:04 +02:00
|
|
|
};
|
|
|
|
|
2011-08-27 19:33:33 +02:00
|
|
|
HRESULT CLRMetaHost_CreateInstance(REFIID riid, void **ppobj)
|
2010-09-22 21:09:04 +02:00
|
|
|
{
|
2011-03-14 10:23:01 +01:00
|
|
|
return ICLRMetaHost_QueryInterface(&GlobalCLRMetaHost.ICLRMetaHost_iface, riid, ppobj);
|
2010-09-22 21:09:04 +02:00
|
|
|
}
|
2010-10-01 21:11:09 +02:00
|
|
|
|
2013-10-02 07:48:32 +02:00
|
|
|
struct CLRMetaHostPolicy
|
|
|
|
{
|
|
|
|
ICLRMetaHostPolicy ICLRMetaHostPolicy_iface;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct CLRMetaHostPolicy GlobalCLRMetaHostPolicy;
|
|
|
|
|
|
|
|
static HRESULT WINAPI metahostpolicy_QueryInterface(ICLRMetaHostPolicy *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
TRACE("%s %p\n", debugstr_guid(riid), obj);
|
|
|
|
|
|
|
|
if ( IsEqualGUID( riid, &IID_ICLRMetaHostPolicy ) ||
|
|
|
|
IsEqualGUID( riid, &IID_IUnknown ) )
|
|
|
|
{
|
|
|
|
ICLRMetaHostPolicy_AddRef( iface );
|
|
|
|
*obj = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME("Unsupported interface %s\n", debugstr_guid(riid));
|
|
|
|
|
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI metahostpolicy_AddRef(ICLRMetaHostPolicy *iface)
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI metahostpolicy_Release(ICLRMetaHostPolicy *iface)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI metahostpolicy_GetRequestedRuntime(ICLRMetaHostPolicy *iface, METAHOST_POLICY_FLAGS dwPolicyFlags,
|
|
|
|
LPCWSTR pwzBinary, IStream *pCfgStream, LPWSTR pwzVersion, DWORD *pcchVersion,
|
|
|
|
LPWSTR pwzImageVersion, DWORD *pcchImageVersion, DWORD *pdwConfigFlags, REFIID riid,
|
|
|
|
LPVOID *ppRuntime)
|
|
|
|
{
|
2013-11-05 05:13:34 +01:00
|
|
|
ICLRRuntimeInfo *result;
|
|
|
|
HRESULT hr;
|
|
|
|
WCHAR filename[MAX_PATH];
|
|
|
|
const WCHAR *path = NULL;
|
|
|
|
int flags = 0;
|
|
|
|
|
|
|
|
TRACE("%d %p %p %p %p %p %p %p %s %p\n", dwPolicyFlags, pwzBinary, pCfgStream,
|
2013-10-02 07:48:32 +02:00
|
|
|
pwzVersion, pcchVersion, pwzImageVersion, pcchImageVersion, pdwConfigFlags,
|
|
|
|
debugstr_guid(riid), ppRuntime);
|
|
|
|
|
2019-02-24 16:12:24 +01:00
|
|
|
if (pdwConfigFlags) {
|
2013-11-05 05:13:34 +01:00
|
|
|
FIXME("ignoring config flags\n");
|
2019-02-24 16:12:24 +01:00
|
|
|
*pdwConfigFlags = 0;
|
|
|
|
}
|
2013-11-05 05:13:34 +01:00
|
|
|
|
|
|
|
if(dwPolicyFlags & METAHOST_POLICY_USE_PROCESS_IMAGE_PATH)
|
|
|
|
{
|
|
|
|
GetModuleFileNameW(0, filename, MAX_PATH);
|
|
|
|
path = filename;
|
|
|
|
}
|
|
|
|
else if(pwzBinary)
|
|
|
|
{
|
|
|
|
path = pwzBinary;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(dwPolicyFlags & METAHOST_POLICY_APPLY_UPGRADE_POLICY)
|
|
|
|
flags |= RUNTIME_INFO_UPGRADE_VERSION;
|
|
|
|
|
2019-02-24 16:12:24 +01:00
|
|
|
hr = get_runtime_info(path, pwzImageVersion, NULL, pCfgStream, 0, flags, FALSE, &result);
|
2013-11-05 05:13:34 +01:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
if (pwzImageVersion)
|
|
|
|
{
|
|
|
|
/* Ignoring errors on purpose */
|
|
|
|
ICLRRuntimeInfo_GetVersionString(result, pwzImageVersion, pcchImageVersion);
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = ICLRRuntimeInfo_QueryInterface(result, riid, ppRuntime);
|
|
|
|
|
|
|
|
ICLRRuntimeInfo_Release(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("<- 0x%08x\n", hr);
|
|
|
|
|
|
|
|
return hr;
|
2013-10-02 07:48:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct ICLRMetaHostPolicyVtbl CLRMetaHostPolicy_vtbl =
|
|
|
|
{
|
|
|
|
metahostpolicy_QueryInterface,
|
|
|
|
metahostpolicy_AddRef,
|
|
|
|
metahostpolicy_Release,
|
|
|
|
metahostpolicy_GetRequestedRuntime
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct CLRMetaHostPolicy GlobalCLRMetaHostPolicy = {
|
|
|
|
{ &CLRMetaHostPolicy_vtbl }
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT CLRMetaHostPolicy_CreateInstance(REFIID riid, void **ppobj)
|
|
|
|
{
|
|
|
|
return ICLRMetaHostPolicy_QueryInterface(&GlobalCLRMetaHostPolicy.ICLRMetaHostPolicy_iface, riid, ppobj);
|
|
|
|
}
|
|
|
|
|
2019-03-08 22:40:41 +01:00
|
|
|
/*
|
|
|
|
* Assembly search override settings:
|
|
|
|
*
|
|
|
|
* WINE_MONO_OVERRIDES=*,Gac=n
|
|
|
|
* Never search the GAC for libraries.
|
|
|
|
*
|
|
|
|
* WINE_MONO_OVERRIDES=Microsoft.Xna.Framework,Gac=n
|
|
|
|
* Never search the GAC for Microsoft.Xna.Framework
|
|
|
|
*
|
|
|
|
* WINE_MONO_OVERRIDES=Microsoft.Xna.Framework.*,Gac=n;Microsoft.Xna.Framework.GamerServices,Gac=y
|
|
|
|
* Never search the GAC for Microsoft.Xna.Framework, or any library starting
|
|
|
|
* with Microsoft.Xna.Framework, except for Microsoft.Xna.Framework.GamerServices
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* assembly search override flags */
|
|
|
|
#define ASSEMBLY_SEARCH_GAC 1
|
|
|
|
#define ASSEMBLY_SEARCH_UNDEFINED 2
|
|
|
|
#define ASSEMBLY_SEARCH_DEFAULT ASSEMBLY_SEARCH_GAC
|
|
|
|
|
|
|
|
typedef struct override_entry {
|
|
|
|
char *name;
|
|
|
|
DWORD flags;
|
|
|
|
struct list entry;
|
|
|
|
} override_entry;
|
|
|
|
|
|
|
|
static struct list env_overrides = LIST_INIT(env_overrides);
|
|
|
|
|
|
|
|
#define IS_OPTION_TRUE(ch) \
|
|
|
|
((ch) == 'y' || (ch) == 'Y' || (ch) == 't' || (ch) == 'T' || (ch) == '1')
|
|
|
|
#define IS_OPTION_FALSE(ch) \
|
|
|
|
((ch) == 'n' || (ch) == 'N' || (ch) == 'f' || (ch) == 'F' || (ch) == '0')
|
|
|
|
|
|
|
|
static void parse_override_entry(override_entry *entry, const char *string, int string_len)
|
|
|
|
{
|
|
|
|
const char *next_key, *equals, *value;
|
|
|
|
UINT kvp_len, key_len;
|
|
|
|
|
|
|
|
entry->flags = ASSEMBLY_SEARCH_DEFAULT;
|
|
|
|
|
|
|
|
while (string && string_len > 0)
|
|
|
|
{
|
|
|
|
next_key = memchr(string, ',', string_len);
|
|
|
|
|
|
|
|
if (next_key)
|
|
|
|
{
|
|
|
|
kvp_len = next_key - string;
|
|
|
|
next_key++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
kvp_len = string_len;
|
|
|
|
|
|
|
|
equals = memchr(string, '=', kvp_len);
|
|
|
|
|
|
|
|
if (equals)
|
|
|
|
{
|
|
|
|
key_len = equals - string;
|
|
|
|
value = equals + 1;
|
|
|
|
switch (key_len) {
|
|
|
|
case 3:
|
2019-04-02 16:51:53 +02:00
|
|
|
if (!_strnicmp(string, "gac", 3)) {
|
2019-03-08 22:40:41 +01:00
|
|
|
if (IS_OPTION_TRUE(*value))
|
|
|
|
entry->flags |= ASSEMBLY_SEARCH_GAC;
|
|
|
|
else if (IS_OPTION_FALSE(*value))
|
|
|
|
entry->flags &= ~ASSEMBLY_SEARCH_GAC;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
string = next_key;
|
|
|
|
string_len -= kvp_len + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL WINAPI parse_env_overrides(INIT_ONCE *once, void *param, void **context)
|
|
|
|
{
|
|
|
|
const char *override_string = getenv("WINE_MONO_OVERRIDES");
|
|
|
|
struct override_entry *entry;
|
|
|
|
|
|
|
|
if (override_string)
|
|
|
|
{
|
|
|
|
const char *entry_start;
|
|
|
|
|
|
|
|
entry_start = override_string;
|
|
|
|
|
|
|
|
while (entry_start && *entry_start)
|
|
|
|
{
|
|
|
|
const char *next_entry, *basename_end;
|
|
|
|
UINT entry_len;
|
|
|
|
|
|
|
|
next_entry = strchr(entry_start, ';');
|
|
|
|
|
|
|
|
if (next_entry)
|
|
|
|
{
|
|
|
|
entry_len = next_entry - entry_start;
|
|
|
|
next_entry++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
entry_len = strlen(entry_start);
|
|
|
|
|
|
|
|
basename_end = memchr(entry_start, ',', entry_len);
|
|
|
|
|
|
|
|
if (!basename_end)
|
|
|
|
{
|
|
|
|
entry_start = next_entry;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
entry = heap_alloc_zero(sizeof(*entry));
|
|
|
|
if (!entry)
|
|
|
|
{
|
|
|
|
ERR("out of memory\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
entry->name = heap_alloc_zero(basename_end - entry_start + 1);
|
|
|
|
if (!entry->name)
|
|
|
|
{
|
|
|
|
ERR("out of memory\n");
|
|
|
|
heap_free(entry);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(entry->name, entry_start, basename_end - entry_start);
|
|
|
|
|
|
|
|
entry_len -= basename_end - entry_start + 1;
|
|
|
|
entry_start = basename_end + 1;
|
|
|
|
|
|
|
|
parse_override_entry(entry, entry_start, entry_len);
|
|
|
|
|
|
|
|
list_add_tail(&env_overrides, &entry->entry);
|
|
|
|
|
|
|
|
entry_start = next_entry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD get_basename_search_flags(const char *basename, MonoAssemblyName *aname, HKEY userkey, HKEY appkey)
|
|
|
|
{
|
|
|
|
struct override_entry *entry;
|
|
|
|
char buffer[256];
|
|
|
|
DWORD buffer_size;
|
|
|
|
static INIT_ONCE init_once = INIT_ONCE_STATIC_INIT;
|
|
|
|
|
|
|
|
InitOnceExecuteOnce(&init_once, parse_env_overrides, NULL, NULL);
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(entry, &env_overrides, override_entry, entry)
|
|
|
|
{
|
|
|
|
if (strcmp(basename, entry->name) == 0)
|
|
|
|
{
|
|
|
|
return entry->flags;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer_size = sizeof(buffer);
|
|
|
|
if (appkey && !RegQueryValueExA(appkey, basename, 0, NULL, (LPBYTE)buffer, &buffer_size))
|
|
|
|
{
|
|
|
|
override_entry reg_entry;
|
|
|
|
|
|
|
|
memset(®_entry, 0, sizeof(reg_entry));
|
|
|
|
|
|
|
|
parse_override_entry(®_entry, buffer, strlen(buffer));
|
|
|
|
|
|
|
|
return reg_entry.flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer_size = sizeof(buffer);
|
|
|
|
if (userkey && !RegQueryValueExA(userkey, basename, 0, NULL, (LPBYTE)buffer, &buffer_size))
|
|
|
|
{
|
|
|
|
override_entry reg_entry;
|
|
|
|
|
|
|
|
memset(®_entry, 0, sizeof(reg_entry));
|
|
|
|
|
|
|
|
parse_override_entry(®_entry, buffer, strlen(buffer));
|
|
|
|
|
|
|
|
return reg_entry.flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ASSEMBLY_SEARCH_UNDEFINED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HKEY get_app_overrides_key(void)
|
|
|
|
{
|
|
|
|
static const WCHAR subkeyW[] = {'\\','M','o','n','o','\\','A','s','m','O','v','e','r','r','i','d','e','s',0};
|
|
|
|
WCHAR bufferW[MAX_PATH+18];
|
|
|
|
HKEY appkey = 0;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
len = (GetModuleFileNameW( 0, bufferW, MAX_PATH ));
|
|
|
|
if (len && len < MAX_PATH)
|
|
|
|
{
|
|
|
|
HKEY tmpkey;
|
|
|
|
WCHAR *p, *appname = bufferW;
|
2019-07-05 12:55:54 +02:00
|
|
|
if ((p = wcsrchr( appname, '/' ))) appname = p + 1;
|
|
|
|
if ((p = wcsrchr( appname, '\\' ))) appname = p + 1;
|
|
|
|
lstrcatW( appname, subkeyW );
|
2019-03-08 22:40:41 +01:00
|
|
|
/* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\Mono\AsmOverrides */
|
|
|
|
if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
|
|
|
|
{
|
|
|
|
if (RegOpenKeyW( tmpkey, appname, &appkey )) appkey = 0;
|
|
|
|
RegCloseKey( tmpkey );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return appkey;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD get_assembly_search_flags(MonoAssemblyName *aname)
|
|
|
|
{
|
|
|
|
const char *name = mono_assembly_name_get_name(aname);
|
|
|
|
char *name_copy, *name_end;
|
|
|
|
DWORD result;
|
|
|
|
HKEY appkey = 0, userkey;
|
|
|
|
|
|
|
|
/* @@ Wine registry key: HKCU\Software\Wine\Mono\AsmOverrides */
|
|
|
|
if (RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Mono\\AsmOverrides", &userkey )) userkey = 0;
|
|
|
|
|
|
|
|
appkey = get_app_overrides_key();
|
|
|
|
|
|
|
|
result = get_basename_search_flags(name, aname, userkey, appkey);
|
|
|
|
if (result != ASSEMBLY_SEARCH_UNDEFINED)
|
|
|
|
{
|
|
|
|
if (userkey) RegCloseKey(userkey);
|
|
|
|
if (appkey) RegCloseKey(appkey);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
name_copy = heap_alloc((strlen(name) + 3) * sizeof(WCHAR));
|
|
|
|
if (!name_copy)
|
|
|
|
{
|
|
|
|
ERR("out of memory\n");
|
|
|
|
if (userkey) RegCloseKey(userkey);
|
|
|
|
if (appkey) RegCloseKey(appkey);
|
|
|
|
return ASSEMBLY_SEARCH_DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(name_copy, name);
|
|
|
|
name_end = name_copy + strlen(name);
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
strcpy(name_end, ".*");
|
|
|
|
result = get_basename_search_flags(name_copy, aname, userkey, appkey);
|
|
|
|
if (result != ASSEMBLY_SEARCH_UNDEFINED) break;
|
|
|
|
|
|
|
|
*name_end = 0;
|
|
|
|
name_end = strrchr(name_copy, '.');
|
|
|
|
} while (name_end != NULL);
|
|
|
|
|
|
|
|
/* default flags */
|
|
|
|
if (result == ASSEMBLY_SEARCH_UNDEFINED)
|
|
|
|
{
|
|
|
|
result = get_basename_search_flags("*", aname, userkey, appkey);
|
|
|
|
if (result == ASSEMBLY_SEARCH_UNDEFINED)
|
|
|
|
result = ASSEMBLY_SEARCH_DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
heap_free(name_copy);
|
|
|
|
if (appkey) RegCloseKey(appkey);
|
|
|
|
if (userkey) RegCloseKey(userkey);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-06-04 21:10:27 +02:00
|
|
|
HRESULT get_file_from_strongname(WCHAR* stringnameW, WCHAR* assemblies_path, int path_length)
|
2010-10-05 22:50:01 +02:00
|
|
|
{
|
|
|
|
HRESULT hr=S_OK;
|
|
|
|
IAssemblyCache *asmcache;
|
|
|
|
ASSEMBLY_INFO info;
|
2013-12-16 23:26:11 +01:00
|
|
|
static const WCHAR fusiondll[] = {'f','u','s','i','o','n',0};
|
2010-10-05 22:50:01 +02:00
|
|
|
HMODULE hfusion=NULL;
|
2012-01-25 23:27:44 +01:00
|
|
|
static HRESULT (WINAPI *pCreateAssemblyCache)(IAssemblyCache**,DWORD);
|
2010-10-05 22:50:01 +02:00
|
|
|
|
|
|
|
if (!pCreateAssemblyCache)
|
|
|
|
{
|
|
|
|
hr = LoadLibraryShim(fusiondll, NULL, NULL, &hfusion);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
pCreateAssemblyCache = (void*)GetProcAddress(hfusion, "CreateAssemblyCache");
|
|
|
|
if (!pCreateAssemblyCache)
|
|
|
|
hr = E_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = pCreateAssemblyCache(&asmcache, 0);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2013-06-04 21:10:27 +02:00
|
|
|
info.cbAssemblyInfo = sizeof(info);
|
|
|
|
info.pszCurrentAssemblyPathBuf = assemblies_path;
|
|
|
|
info.cchBuf = path_length;
|
|
|
|
assemblies_path[0] = 0;
|
2010-10-05 22:50:01 +02:00
|
|
|
|
2013-06-04 21:10:27 +02:00
|
|
|
hr = IAssemblyCache_QueryAssemblyInfo(asmcache, 0, stringnameW, &info);
|
2010-10-05 22:50:01 +02:00
|
|
|
|
2013-06-04 21:10:27 +02:00
|
|
|
IAssemblyCache_Release(asmcache);
|
|
|
|
}
|
2010-10-05 22:50:01 +02:00
|
|
|
|
2013-06-04 21:10:27 +02:00
|
|
|
return hr;
|
|
|
|
}
|
2010-10-05 22:50:01 +02:00
|
|
|
|
2016-01-20 16:03:40 +01:00
|
|
|
static MonoAssembly* CDECL mono_assembly_preload_hook_fn(MonoAssemblyName *aname, char **assemblies_path, void *user_data)
|
2013-06-04 21:10:27 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
MonoAssembly *result=NULL;
|
|
|
|
char *stringname=NULL;
|
2019-10-17 22:12:32 +02:00
|
|
|
const char *assemblyname;
|
2013-06-04 21:10:27 +02:00
|
|
|
LPWSTR stringnameW;
|
|
|
|
int stringnameW_size;
|
|
|
|
WCHAR path[MAX_PATH];
|
|
|
|
char *pathA;
|
|
|
|
MonoImageOpenStatus stat;
|
2019-03-08 22:40:41 +01:00
|
|
|
DWORD search_flags;
|
2019-10-17 22:12:32 +02:00
|
|
|
int i;
|
|
|
|
static const WCHAR dotdllW[] = {'.','d','l','l',0};
|
|
|
|
static const WCHAR slashW[] = {'\\',0};
|
2010-10-05 22:50:01 +02:00
|
|
|
|
2013-10-24 21:34:24 +02:00
|
|
|
stringname = mono_stringify_assembly_name(aname);
|
2019-10-17 22:12:32 +02:00
|
|
|
assemblyname = mono_assembly_name_get_name(aname);
|
2013-06-04 21:10:27 +02:00
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_a(stringname));
|
|
|
|
|
2019-10-17 22:12:32 +02:00
|
|
|
if (!stringname || !assemblyname) return NULL;
|
2013-06-04 21:10:27 +02:00
|
|
|
|
2019-03-08 22:40:41 +01:00
|
|
|
search_flags = get_assembly_search_flags(aname);
|
2019-10-17 22:12:32 +02:00
|
|
|
if (private_path)
|
|
|
|
{
|
|
|
|
stringnameW_size = MultiByteToWideChar(CP_UTF8, 0, assemblyname, -1, NULL, 0);
|
|
|
|
stringnameW = HeapAlloc(GetProcessHeap(), 0, stringnameW_size * sizeof(WCHAR));
|
|
|
|
if (stringnameW)
|
|
|
|
{
|
|
|
|
MultiByteToWideChar(CP_UTF8, 0, assemblyname, -1, stringnameW, stringnameW_size);
|
|
|
|
for (i = 0; private_path[i] != NULL; i++)
|
|
|
|
{
|
|
|
|
wcscpy(path, private_path[i]);
|
|
|
|
wcscat(path, slashW);
|
|
|
|
wcscat(path, stringnameW);
|
|
|
|
wcscat(path, dotdllW);
|
|
|
|
pathA = WtoA(path);
|
|
|
|
if (pathA)
|
|
|
|
{
|
|
|
|
result = mono_assembly_open(pathA, &stat);
|
|
|
|
if (result)
|
|
|
|
{
|
|
|
|
TRACE("found: %s\n", debugstr_w(path));
|
|
|
|
HeapFree(GetProcessHeap(), 0, pathA);
|
|
|
|
HeapFree(GetProcessHeap(), 0, stringnameW);
|
|
|
|
mono_free(stringname);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, pathA);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, stringnameW);
|
|
|
|
}
|
|
|
|
}
|
2013-06-04 21:10:27 +02:00
|
|
|
|
2019-03-08 22:40:41 +01:00
|
|
|
/* FIXME: We should search the given paths before the GAC. */
|
2013-06-04 21:10:27 +02:00
|
|
|
|
2019-03-08 22:40:41 +01:00
|
|
|
if ((search_flags & ASSEMBLY_SEARCH_GAC) != 0)
|
2013-06-04 21:10:27 +02:00
|
|
|
{
|
2019-03-08 22:40:41 +01:00
|
|
|
stringnameW_size = MultiByteToWideChar(CP_UTF8, 0, stringname, -1, NULL, 0);
|
2013-06-04 21:10:27 +02:00
|
|
|
|
2019-03-08 22:40:41 +01:00
|
|
|
stringnameW = HeapAlloc(GetProcessHeap(), 0, stringnameW_size * sizeof(WCHAR));
|
|
|
|
if (stringnameW)
|
|
|
|
{
|
|
|
|
MultiByteToWideChar(CP_UTF8, 0, stringname, -1, stringnameW, stringnameW_size);
|
2010-10-05 22:50:01 +02:00
|
|
|
|
2019-03-08 22:40:41 +01:00
|
|
|
hr = get_file_from_strongname(stringnameW, path, MAX_PATH);
|
2010-10-05 22:50:01 +02:00
|
|
|
|
2019-03-08 22:40:41 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, stringnameW);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = E_OUTOFMEMORY;
|
2010-10-05 22:50:01 +02:00
|
|
|
|
2019-03-08 22:40:41 +01:00
|
|
|
if (SUCCEEDED(hr))
|
2010-10-05 22:50:01 +02:00
|
|
|
{
|
2019-03-08 22:40:41 +01:00
|
|
|
TRACE("found: %s\n", debugstr_w(path));
|
2010-10-05 22:50:01 +02:00
|
|
|
|
2019-03-08 22:40:41 +01:00
|
|
|
pathA = WtoA(path);
|
|
|
|
|
|
|
|
if (pathA)
|
|
|
|
{
|
|
|
|
result = mono_assembly_open(pathA, &stat);
|
2010-10-05 22:50:01 +02:00
|
|
|
|
2019-03-08 22:40:41 +01:00
|
|
|
if (!result)
|
|
|
|
ERR("Failed to load %s, status=%u\n", debugstr_w(path), stat);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, pathA);
|
|
|
|
}
|
2010-10-05 22:50:01 +02:00
|
|
|
}
|
|
|
|
}
|
2019-03-08 22:40:41 +01:00
|
|
|
else
|
|
|
|
TRACE("skipping Windows GAC search due to override setting\n");
|
2010-10-05 22:50:01 +02:00
|
|
|
|
2013-10-24 21:34:24 +02:00
|
|
|
mono_free(stringname);
|
2010-10-05 22:50:01 +02:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-10-01 21:11:09 +02:00
|
|
|
HRESULT get_runtime_info(LPCWSTR exefile, LPCWSTR version, LPCWSTR config_file,
|
2019-02-24 16:12:24 +01:00
|
|
|
IStream *config_stream, DWORD startup_flags, DWORD runtimeinfo_flags,
|
|
|
|
BOOL legacy, ICLRRuntimeInfo **result)
|
2010-10-01 21:11:09 +02:00
|
|
|
{
|
2010-10-05 00:37:00 +02:00
|
|
|
static const WCHAR dotconfig[] = {'.','c','o','n','f','i','g',0};
|
2010-10-01 21:11:09 +02:00
|
|
|
static const DWORD supported_startup_flags = 0;
|
|
|
|
static const DWORD supported_runtime_flags = RUNTIME_INFO_UPGRADE_VERSION;
|
|
|
|
int i;
|
2010-10-01 23:05:36 +02:00
|
|
|
WCHAR local_version[MAX_PATH];
|
|
|
|
ULONG local_version_size = MAX_PATH;
|
2010-10-05 00:37:00 +02:00
|
|
|
WCHAR local_config_file[MAX_PATH];
|
2010-10-01 23:05:36 +02:00
|
|
|
HRESULT hr;
|
2010-10-05 00:37:00 +02:00
|
|
|
parsed_config_file parsed_config;
|
2010-10-01 21:11:09 +02:00
|
|
|
|
|
|
|
if (startup_flags & ~supported_startup_flags)
|
|
|
|
FIXME("unsupported startup flags %x\n", startup_flags & ~supported_startup_flags);
|
|
|
|
|
|
|
|
if (runtimeinfo_flags & ~supported_runtime_flags)
|
|
|
|
FIXME("unsupported runtimeinfo flags %x\n", runtimeinfo_flags & ~supported_runtime_flags);
|
|
|
|
|
2013-11-05 05:13:34 +01:00
|
|
|
if (exefile && !exefile[0])
|
|
|
|
exefile = NULL;
|
|
|
|
|
2019-02-24 16:12:24 +01:00
|
|
|
if (exefile && !config_file && !config_stream)
|
2010-10-05 00:37:00 +02:00
|
|
|
{
|
2019-07-05 12:55:54 +02:00
|
|
|
lstrcpyW(local_config_file, exefile);
|
|
|
|
lstrcatW(local_config_file, dotconfig);
|
2010-10-05 00:37:00 +02:00
|
|
|
|
|
|
|
config_file = local_config_file;
|
|
|
|
}
|
|
|
|
|
2019-02-24 16:12:24 +01:00
|
|
|
if (config_file || config_stream)
|
2010-10-05 00:37:00 +02:00
|
|
|
{
|
2013-10-07 22:49:39 +02:00
|
|
|
BOOL found = FALSE;
|
2019-02-24 16:12:24 +01:00
|
|
|
if (config_file)
|
|
|
|
hr = parse_config_file(config_file, &parsed_config);
|
|
|
|
else
|
|
|
|
hr = parse_config_stream(config_stream, &parsed_config);
|
2010-10-05 00:37:00 +02:00
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
supported_runtime *entry;
|
|
|
|
LIST_FOR_EACH_ENTRY(entry, &parsed_config.supported_runtimes, supported_runtime, entry)
|
|
|
|
{
|
2014-07-14 22:55:18 +02:00
|
|
|
hr = get_runtime(entry->version, TRUE, &IID_ICLRRuntimeInfo, (void**)result);
|
2010-10-05 00:37:00 +02:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2013-10-07 22:49:39 +02:00
|
|
|
found = TRUE;
|
2010-10-05 00:37:00 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("failed to parse config file %s, hr=%x\n", debugstr_w(config_file), hr);
|
|
|
|
}
|
|
|
|
|
|
|
|
free_parsed_config_file(&parsed_config);
|
|
|
|
|
|
|
|
if (found)
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-10-01 23:05:36 +02:00
|
|
|
if (exefile && !version)
|
|
|
|
{
|
2019-05-04 20:25:58 +02:00
|
|
|
DWORD major, minor, build;
|
|
|
|
|
2010-10-01 23:05:36 +02:00
|
|
|
hr = CLRMetaHost_GetVersionFromFile(0, exefile, local_version, &local_version_size);
|
|
|
|
|
|
|
|
version = local_version;
|
|
|
|
|
|
|
|
if (FAILED(hr)) return hr;
|
2019-05-04 20:25:58 +02:00
|
|
|
|
|
|
|
/* When running an executable, specifically when getting the version number from
|
|
|
|
* the exe, native accepts a matching major.minor with build <= expected build. */
|
|
|
|
if (!parse_runtime_version(version, &major, &minor, &build))
|
|
|
|
{
|
|
|
|
ERR("Cannot parse %s\n", debugstr_w(version));
|
|
|
|
return CLR_E_SHIM_RUNTIME;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (legacy)
|
|
|
|
i = 3;
|
|
|
|
else
|
|
|
|
i = NUM_RUNTIMES;
|
|
|
|
|
|
|
|
while (i--)
|
|
|
|
{
|
|
|
|
if (runtimes[i].major == major && runtimes[i].minor == minor && runtimes[i].build >= build)
|
|
|
|
{
|
|
|
|
return ICLRRuntimeInfo_QueryInterface(&runtimes[i].ICLRRuntimeInfo_iface,
|
|
|
|
&IID_ICLRRuntimeInfo, (void **)result);
|
|
|
|
}
|
|
|
|
}
|
2010-10-01 23:05:36 +02:00
|
|
|
}
|
|
|
|
|
2010-10-01 21:11:09 +02:00
|
|
|
if (version)
|
|
|
|
{
|
2012-03-12 06:15:31 +01:00
|
|
|
hr = CLRMetaHost_GetRuntime(0, version, &IID_ICLRRuntimeInfo, (void**)result);
|
|
|
|
if(SUCCEEDED(hr))
|
|
|
|
return hr;
|
2010-10-01 21:11:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (runtimeinfo_flags & RUNTIME_INFO_UPGRADE_VERSION)
|
|
|
|
{
|
2012-03-12 06:15:31 +01:00
|
|
|
DWORD major, minor, build;
|
|
|
|
|
|
|
|
if (version && !parse_runtime_version(version, &major, &minor, &build))
|
|
|
|
{
|
|
|
|
ERR("Cannot parse %s\n", debugstr_w(version));
|
|
|
|
return CLR_E_SHIM_RUNTIME;
|
|
|
|
}
|
|
|
|
|
2010-10-01 21:11:09 +02:00
|
|
|
if (legacy)
|
2013-08-14 06:08:31 +02:00
|
|
|
i = 3;
|
2010-10-01 21:11:09 +02:00
|
|
|
else
|
|
|
|
i = NUM_RUNTIMES;
|
|
|
|
|
|
|
|
while (i--)
|
|
|
|
{
|
2015-02-20 19:59:53 +01:00
|
|
|
/* Must be greater or equal to the version passed in. */
|
|
|
|
if (!version || ((runtimes[i].major >= major && runtimes[i].minor >= minor && runtimes[i].build >= build) ||
|
|
|
|
(runtimes[i].major >= major && runtimes[i].minor > minor) ||
|
|
|
|
(runtimes[i].major > major)))
|
2012-03-12 06:15:31 +01:00
|
|
|
{
|
2015-02-20 19:59:53 +01:00
|
|
|
return ICLRRuntimeInfo_QueryInterface(&runtimes[i].ICLRRuntimeInfo_iface,
|
|
|
|
&IID_ICLRRuntimeInfo, (void **)result);
|
2012-03-12 06:15:31 +01:00
|
|
|
}
|
2010-10-01 21:11:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return CLR_E_SHIM_RUNTIME;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CLR_E_SHIM_RUNTIME;
|
|
|
|
}
|