Beispiel #1
0
void main(int argc, char* argv[])
{
	mono_set_dirs("lib", "");
	mono_config_parse(NULL);

	MonoDomain* domain = mono_jit_init("managed.exe");
	if(!domain)
	{
		printf("Unable to initialize mono jit.\n");
		return;
	}
	MonoAssembly* assembly = mono_domain_assembly_open(domain, "managed.exe");
	if (!assembly)
	{
		printf("Unable to open assembly.\n");
		return;
	}
	
	char* argvv[1] = { "managed" };
	mono_jit_exec(domain, assembly, 1, argvv);
	
	mono_jit_cleanup(domain);

	return;
}
Beispiel #2
0
void MonoEmbedding::Initialize()
{
    // Construct the absolute file path to MonoEmbedding.exe assuming
    // it is located next to edge.node
    Dl_info dlinfo;
    char fullPath[PATH_MAX];
    dladdr((void*)&MonoEmbedding::Initialize, &dlinfo);
    strcpy(fullPath, dlinfo.dli_fname);
    strcpy(fullPath, dirname(fullPath));
    strcat(fullPath, "/MonoEmbedding.exe");

    mono_config_parse (NULL);
    mono_jit_init (fullPath);
    assembly = mono_domain_assembly_open (mono_domain_get(), fullPath);
    MonoClass* klass = mono_class_from_name(mono_assembly_get_image(assembly), "", "MonoEmbedding");
    MonoMethod* main = mono_class_get_method_from_name(klass, "Main", -1);
    MonoException* exc;
    MonoArray* args = mono_array_new(mono_domain_get(), mono_get_string_class(), 0);
    mono_runtime_exec_main(main, args, (MonoObject**)&exc);

    mono_add_internal_call("ClrFuncInvokeContext::CompleteOnV8ThreadAsynchronousICall", (const void*)&ClrFuncInvokeContext::CompleteOnV8ThreadAsynchronous); 
    mono_add_internal_call("ClrFuncInvokeContext::CompleteOnCLRThreadICall", (const void*)&ClrFuncInvokeContext::CompleteOnCLRThread); 
    mono_add_internal_call("NodejsFuncInvokeContext::CallFuncOnV8ThreadInternal", (const void*)&NodejsFuncInvokeContext::CallFuncOnV8Thread); 
    mono_add_internal_call("NodejsFunc::ExecuteActionOnV8Thread", (const void*)&NodejsFunc::ExecuteActionOnV8Thread); 
    mono_add_internal_call("NodejsFunc::Release", (const void*)&NodejsFunc::Release); 
}
Beispiel #3
0
MaigreMonoBridge *
maigre_mono_bridge ()
{
    static MaigreMonoBridge *bridge;
    static gboolean load_attempted;

    if (load_attempted) {
        return bridge;
    }

    load_attempted = TRUE;

    bridge = g_new0 (MaigreMonoBridge, 1);

    bridge->domain = mono_domain_get ();

    if (bridge->domain == NULL) {
        mono_config_parse (NULL);
        bridge->domain = mono_jit_init ("maigre-domain");
    }

    if ((bridge->assembly = mono_domain_assembly_open (
            bridge->domain, ".run/engines/Maigre.dll")) == NULL ||
        (bridge->image = mono_assembly_get_image (bridge->assembly)) == NULL) {
        g_warning ("Could not load Maigre.dll assembly");
        g_free (bridge);
        bridge = NULL;
    }

    return bridge;
}
Beispiel #4
0
int mono_sr_init_child(void)
{
	memset(&_sr_M_env, 0, sizeof(sr_mono_env_t));

	/*
	 * Load the default Mono configuration file, this is needed
	 * if you are planning on using the dllmaps defined on the
	 * system configuration
	 */
	mono_config_parse (NULL);

	return 0;
}
Beispiel #5
0
int app_mono_exec(struct sip_msg *msg, char *script, char *param)
{
	int ret;
	char *argv[2];
	int argc;

	argc = 1;
	argv[0] = script;
	if(param!=NULL) {
		argc++;
		argv[1] = param;
	}
	LM_DBG("executing Mono assembly: [[%s]]\n", argv[0]);
	_sr_M_env.msg = msg;

	mono_config_parse (NULL);
	/*
	 * mono_jit_init() creates a domain: each assembly is
	 * loaded and run in a MonoDomain.
	 */
	_sr_M_env.domain = mono_jit_init (argv[0]);
	/*
	 * We add our special internal functions, so that C# code
	 * can call us back.
	 */
	sr_mono_load_class_core();
	sr_mono_load_class_pv();
	sr_mono_load_class_hdr();

	_sr_M_env.assembly = mono_domain_assembly_open(_sr_M_env.domain, argv[0]);
	if (_sr_M_env.assembly==NULL) {
		ret = -1;
		goto done;
	}
	/*
	 * mono_jit_exec() will run the Main() method in the assembly.
	 * The return value needs to be looked up from
	 * System.Environment.ExitCode.
	 */
	mono_jit_exec(_sr_M_env.domain, _sr_M_env.assembly, argc, argv);
	ret = mono_environment_exitcode_get();
	LM_DBG("returned code from mono environment: %d\n", ret);

done:
	mono_jit_cleanup(_sr_M_env.domain);

	memset(&_sr_M_env, 0, sizeof(sr_mono_env_t));
	return (ret==0)?1:-1;
}
Beispiel #6
0
int main(int argc, char* argv[])
{
    MonoDomain *domain;
    MonoAssembly *assembly;
    const char *file;
    int retval;
    
    if (argc < 2)
    {
        fprintf(stderr, "Please provide name of mono assembly to load.\n");
        return 1;
    }
    
    file = argv[1];

    // Load the default Mono configuration file, this is needed
    // if you are planning on using the dllmaps defined on the
    // system configuration
    mono_config_parse(NULL);
    
    // Create mono AppDomain
    domain = mono_jit_init(file);

    // Open entry assembly in new AppDomain
    assembly = mono_domain_assembly_open(domain, file);

    if (assembly != NULL)
    {
        // mono_jit_exec runs the Main() method in the assembly
        mono_jit_exec(domain, assembly, argc - 1, argv + 1);

        // Get exit code from entry assembly
        retval = mono_environment_exitcode_get();
    }
    else
    {
        fprintf(stderr, "Failed to load mono assembly: %s\n", file);
        retval = 2;
    }
    
    // This clean up call tends to crash - since we are exiting anyway, we skip it...
    //mono_jit_cleanup(domain);

    return retval;
}
Beispiel #7
0
/**
 * This program must be run like this: ./test MonoEmbedded.exe
 * (it requires one argument, even when it is not going to be used because I do not know what
 *  parameters to use in mono_jit_exec method, it crashes with NULL value :/)
 */
int main (int argc, char *argv[])
{
    /*
     * Load the default Mono configuration file, this is needed
     * if you are planning on using the dllmaps defined on the
     * system configuration
     */
    mono_config_parse (NULL);

    /*
     * mono_jit_init() creates a domain: each assembly is
     * loaded and run in a MonoDomain.
     */
    MonoDomain *domain = mono_jit_init ("../MonoEmbedded/bin/Debug/MonoEmbedded.exe");

    /*
     * Optionally, add an internal call that your startup.exe
     * code can call, this will bridge startup.exe to Mono
     */
    mono_add_internal_call ("MonoEmbedded.MainClass::Print", (void *)p_Print);

    /*
     * Open the executable, and run the Main method declared
     * in the executable
     */
    MonoAssembly *assembly = mono_domain_assembly_open (domain, "../MonoEmbedded/bin/Debug/MonoEmbedded.exe");
    if (!assembly) {
        exit (2);
    }

    /*
     * mono_jit_exec() will run the Main() method in the assembly.
     * The return value needs to be looked up from
     * System.Environment.ExitCode.
     */
    mono_jit_exec (domain, assembly, argc - 1, argv + 1);

    return 0;
}
Beispiel #8
0
// initialize Mono and PythonNet
PyNet_Args* PyNet_Init(int ext) {
    PyNet_Args *pn_args;
    pn_args = (PyNet_Args *)malloc(sizeof(PyNet_Args));
    pn_args->pr_file = PR_ASSEMBLY;
    pn_args->error = NULL;
    pn_args->shutdown = NULL;
    pn_args->module = NULL;

    if (ext == 0) {
        pn_args->init_name = "Python.Runtime:Initialize()";
    } else {
        pn_args->init_name = "Python.Runtime:InitExt()";
    }
    pn_args->shutdown_name = "Python.Runtime:Shutdown()";

    pn_args->domain = mono_jit_init_version(MONO_DOMAIN, MONO_VERSION);

    /*
     * Load the default Mono configuration file, this is needed
     * if you are planning on using the dllmaps defined on the
     * system configuration
     */
    mono_config_parse(NULL);

    /* I can't use this call to run the main_thread_handler. The function
     * runs it in another thread but *this* thread holds the Python
     * import lock -> DEAD LOCK.
     *
     * mono_runtime_exec_managed_code(pn_args->domain, main_thread_handler,
     *                                pn_args);
     */
                                   
    main_thread_handler(pn_args);

    if (pn_args->error != NULL) {
        PyErr_SetString(PyExc_ImportError, pn_args->error);
    }
    return pn_args;
} 
Beispiel #9
0
int 
main(int argc, char* argv[]) {
	MonoDomain *domain;
	const char *file;
	int retval;
	puts("Ola");
	if (argc < 2){
		fprintf (stderr, "Please provide an assembly to load\n");
		return 1;
	}
	file = argv [1];

	/*
	 * Load the default Mono configuration file, this is needed
	 * if you are planning on using the dllmaps defined on the
	 * system configuration
	 */
	mono_config_parse (NULL);
	/*
	 * mono_jit_init() creates a domain: each assembly is
	 * loaded and run in a MonoDomain.
	 */
	domain = mono_jit_init (file);
	/*
	 * We add our special internal call, so that C# code
	 * can call us back.
	 */
	mono_add_internal_call ("MonoEmbed::gimme", gimme);

	main_function (domain, file, argc - 1, argv + 1);
	
	retval = mono_environment_exitcode_get ();
	
	mono_jit_cleanup (domain);
 getch();
	return retval;
}
Beispiel #10
0
void Application::InitializeMono()
{
	//this will override the internal assembly search logic.
	//do it in case you package mono in a different structure
	//mono_set_assemblies_path(dllDir.c_str());

	mono_config_parse(NULL);

	// initialize the root domain which will hold corlib and will always be alive
	domain = mono_jit_init_version("CCubed Root Domain", "v4.0.30319");

	// soft debugger needs this
	mono_thread_set_main(mono_thread_current());

	// add icalls
	mono_add_internal_call("EmbedThings.EntryPoint::reload", reload);

	// run the c# bits
	Run();

	// we're exiting the whole thing, cleanup
	mono_jit_cleanup(mono_domain_get());

}
Beispiel #11
0
int mono_sr_init_load(void)
{
	sr_mono_load_t *mi;
	if(_sr_mono_load_list == NULL) {
		LM_DBG("no assembly to load\n");
		return 0;
	}
	mono_config_parse (NULL);
	mi = _sr_mono_load_list;
	if(mi && mi->domain != NULL)
	{
		LM_ERR("worker mono environment already initialized\n");
		return 0;
	}
	while(mi!=NULL)
	{
		mi->domain = mono_jit_init (mi->script);
		if (mi->domain==NULL) {
			LM_ERR("failed to init domain for: %s\n", mi->script);
			return -1;
		}
		sr_mono_load_class_core();
		sr_mono_load_class_pv();
		sr_mono_load_class_hdr();

		mi->assembly = mono_domain_assembly_open(mi->domain, mi->script);
		if (mi->assembly==NULL) {
			LM_ERR("failed to open assembly: %s\n", mi->script);
			return -1;
		}
		mi = mi->next;
		/* only one (first) assembly for now */
		break;
	}
	return 0;
}
Beispiel #12
0
static HRESULT load_mono(LPCWSTR mono_path)
{
    static const WCHAR lib[] = {'\\','l','i','b',0};
    static const WCHAR etc[] = {'\\','e','t','c',0};
    WCHAR mono_dll_path[MAX_PATH+16];
    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];
    int verbose_size;
    char verbose_setting[256];

    if (is_mono_shutdown)
    {
        ERR("Cannot load Mono after it has been shut down.\n");
        return E_FAIL;
    }

    if (!mono_handle)
    {
        strcpyW(mono_lib_path, mono_path);
        strcatW(mono_lib_path, lib);
        WideCharToMultiByte(CP_UTF8, 0, mono_lib_path, -1, mono_lib_path_a, MAX_PATH, NULL, NULL);

        strcpyW(mono_etc_path, mono_path);
        strcatW(mono_etc_path, etc);
        WideCharToMultiByte(CP_UTF8, 0, mono_etc_path, -1, mono_etc_path_a, MAX_PATH, NULL, NULL);

        if (!find_mono_dll(mono_path, mono_dll_path)) goto fail;

        mono_handle = LoadLibraryW(mono_dll_path);

        if (!mono_handle) goto fail;

#define LOAD_MONO_FUNCTION(x) do { \
    x = (void*)GetProcAddress(mono_handle, #x); \
    if (!x) { \
        goto fail; \
    } \
} while (0);

        LOAD_MONO_FUNCTION(mono_assembly_get_image);
        LOAD_MONO_FUNCTION(mono_assembly_load_from);
        LOAD_MONO_FUNCTION(mono_assembly_open);
        LOAD_MONO_FUNCTION(mono_config_parse);
        LOAD_MONO_FUNCTION(mono_class_from_mono_type);
        LOAD_MONO_FUNCTION(mono_class_from_name);
        LOAD_MONO_FUNCTION(mono_class_get_method_from_name);
        LOAD_MONO_FUNCTION(mono_domain_assembly_open);
        LOAD_MONO_FUNCTION(mono_domain_get);
        LOAD_MONO_FUNCTION(mono_domain_get_by_id);
        LOAD_MONO_FUNCTION(mono_domain_set);
        LOAD_MONO_FUNCTION(mono_domain_set_config);
        LOAD_MONO_FUNCTION(mono_free);
        LOAD_MONO_FUNCTION(mono_image_open);
        LOAD_MONO_FUNCTION(mono_install_assembly_preload_hook);
        LOAD_MONO_FUNCTION(mono_jit_exec);
        LOAD_MONO_FUNCTION(mono_jit_init_version);
        LOAD_MONO_FUNCTION(mono_jit_set_trace_options);
        LOAD_MONO_FUNCTION(mono_marshal_get_vtfixup_ftnptr);
        LOAD_MONO_FUNCTION(mono_object_get_domain);
        LOAD_MONO_FUNCTION(mono_object_get_virtual_method);
        LOAD_MONO_FUNCTION(mono_object_new);
        LOAD_MONO_FUNCTION(mono_object_unbox);
        LOAD_MONO_FUNCTION(mono_profiler_install);
        LOAD_MONO_FUNCTION(mono_reflection_type_from_name);
        LOAD_MONO_FUNCTION(mono_runtime_invoke);
        LOAD_MONO_FUNCTION(mono_runtime_object_init);
        LOAD_MONO_FUNCTION(mono_runtime_quit);
        LOAD_MONO_FUNCTION(mono_set_dirs);
        LOAD_MONO_FUNCTION(mono_set_verbose_level);
        LOAD_MONO_FUNCTION(mono_stringify_assembly_name);
        LOAD_MONO_FUNCTION(mono_string_new);
        LOAD_MONO_FUNCTION(mono_thread_attach);
        LOAD_MONO_FUNCTION(mono_thread_manage);
        LOAD_MONO_FUNCTION(mono_trace_set_assembly);

#undef LOAD_MONO_FUNCTION

#define LOAD_OPT_MONO_FUNCTION(x, default) do { \
    x = (void*)GetProcAddress(mono_handle, #x); \
    if (!x) { \
        x = default; \
    } \
} while (0);

        LOAD_OPT_MONO_FUNCTION(mono_image_open_from_module_handle, image_open_module_handle_dummy);
        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);

#undef LOAD_OPT_MONO_FUNCTION

        mono_profiler_install(NULL, mono_shutdown_callback_fn);

        mono_trace_set_print_handler(mono_print_handler_fn);
        mono_trace_set_printerr_handler(mono_print_handler_fn);

        mono_set_dirs(mono_lib_path_a, mono_etc_path_a);

        mono_config_parse(NULL);

        mono_install_assembly_preload_hook(mono_assembly_preload_hook_fn, NULL);

        trace_size = GetEnvironmentVariableA("WINE_MONO_TRACE", trace_setting, sizeof(trace_setting));

        if (trace_size)
        {
            mono_jit_set_trace_options(trace_setting);
        }

        verbose_size = GetEnvironmentVariableA("WINE_MONO_VERBOSE", verbose_setting, sizeof(verbose_setting));

        if (verbose_size)
        {
            mono_set_verbose_level(verbose_setting[0] - '0');
        }
    }

    return S_OK;

fail:
    ERR("Could not load Mono into this process\n");
    FreeLibrary(mono_handle);
    mono_handle = NULL;
    return E_FAIL;
}
Beispiel #13
0
void
mono_init_virt ()
{
  const char *error;
#ifndef MONO_AGENT
  char * cfg_mono_root_path;
  char * cfg_mono_cfg_dir;
  char * cfg_mono_path;
  char * cfg_mono_trace;

/*g_log_set_always_fatal (G_LOG_LEVEL_ERROR);
  g_log_set_fatal_mask (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR);*/

#ifndef VIRT_MINT
  if (virtuoso_cfg_getstring ("Mono", "MONO_TRACE", &cfg_mono_trace) != -1)
    mono_jit_trace_calls = strcmp (cfg_mono_trace, "On") ? FALSE : TRUE;
#endif
  if (virtuoso_cfg_getstring ("Mono", "MONO_PATH", &cfg_mono_path) != -1)
    setenv ("MONO_PATH", cfg_mono_path, 1);
  if (virtuoso_cfg_getstring ("Mono", "MONO_ROOT", &cfg_mono_root_path) != -1)
    setenv ("MONO_ROOT", cfg_mono_root_path, 1);
  if (virtuoso_cfg_getstring ("Mono", "MONO_CFG_DIR", &cfg_mono_cfg_dir) != -1)
    setenv ("MONO_CFG_DIR", cfg_mono_cfg_dir, 1);
  if (virtuoso_cfg_getstring ("Mono", "virtclr.dll", &VIRTCLR_NAME) == -1)
    VIRTCLR_NAME = "virtclr.dll";

#endif
#ifdef WIN32
  /* mono initialization on win32 has to be done sooner than later */
#ifdef VIRT_MINT
  virtuoso_domain = mono_interp_init ("virtuoso");
#else
  virtuoso_domain = mono_jit_init ("virtuoso");
#endif
  if (cfg_mono_root_path)
    mono_assembly_setrootdir (cfg_mono_root_path);
#endif
#ifndef VIRT_MINT
  mono_jit_trace_calls = FALSE;
#endif
    {
      char *path = getenv ("MONO_ROOT");
      if (path)
	mono_assembly_setrootdir (path);
    }
  /* mono_debug_init (1); */
#ifndef WIN32
  setlocale(LC_ALL, "");
#endif
  g_log_set_always_fatal (G_LOG_LEVEL_ERROR);
  g_log_set_fatal_mask (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR);

  g_set_printerr_handler (dummy_print);
#ifndef WIN32
#ifdef VIRT_MINT
  virtuoso_domain = mono_interp_init ("virtuoso");
#else
  virtuoso_domain = mono_jit_init ("virtuoso");
#endif

  mono_config_parse (NULL);

#ifdef OLD_KIT
  if (NULL != (error = mono_verify_corlib ()))
#elif !defined (OLD_KIT_1_1_5)
  if (NULL != (error = mono_check_corlib_version ()))
#endif
    {
      log_error ("Mono Corlib not in sync with this runtime: %s", error);
      exit (-1);
    }
#ifndef VIRT_MINT
#ifdef OLD_KIT_1_1_5
  mono_thread_attach_aborted_cb = virt_mono_throw_unhandled_exception;
#else
  mono_thread_set_attach_aborted_cb (virt_mono_throw_unhandled_exception);
#endif
#endif
#endif
  mono_add_internal_call ("VInvoke::LoadAssemblyFromVirtuoso(string)", ves_icall_VInvoke_LoadAssemblyFromVirtuoso);

#ifndef MONO_AGENT
  mono_set_port ();
#endif

#ifndef MONO_AGENT
#ifdef OLD_KIT_1_1_4
  log_debug ("Mono config path [%s]", mono_cfg_dir);
#else
  log_debug ("Mono config path [%s]", mono_get_config_dir ());
#endif
#endif
#ifndef WIN32
  setlocale (LC_ALL, "C");
#endif
#ifndef OLD_KIT_1_1_5
  mono_thread_manage ();
  mono_thread_set_main (mono_thread_current());
#endif
}
Beispiel #14
0
void GDMono::initialize() {

	ERR_FAIL_NULL(Engine::get_singleton());

	print_verbose("Mono: Initializing module...");

#ifdef DEBUG_METHODS_ENABLED
	_initialize_and_check_api_hashes();
#endif

	GDMonoLog::get_singleton()->initialize();

#ifdef MONO_PRINT_HANDLER_ENABLED
	mono_trace_set_print_handler(gdmono_MonoPrintCallback);
	mono_trace_set_printerr_handler(gdmono_MonoPrintCallback);
#endif

#ifdef WINDOWS_ENABLED
	mono_reg_info = MonoRegUtils::find_mono();

	CharString assembly_dir;
	CharString config_dir;

	if (mono_reg_info.assembly_dir.length() && DirAccess::exists(mono_reg_info.assembly_dir)) {
		assembly_dir = mono_reg_info.assembly_dir.utf8();
	}

	if (mono_reg_info.config_dir.length() && DirAccess::exists(mono_reg_info.config_dir)) {
		config_dir = mono_reg_info.config_dir.utf8();
	}

	mono_set_dirs(assembly_dir.length() ? assembly_dir.get_data() : NULL,
			config_dir.length() ? config_dir.get_data() : NULL);
#elif OSX_ENABLED
	mono_set_dirs(NULL, NULL);

	{
		const char *assembly_rootdir = mono_assembly_getrootdir();
		const char *config_dir = mono_get_config_dir();

		if (!assembly_rootdir || !config_dir || !DirAccess::exists(assembly_rootdir) || !DirAccess::exists(config_dir)) {
			Vector<const char *> locations;
			locations.push_back("/Library/Frameworks/Mono.framework/Versions/Current/");
			locations.push_back("/usr/local/var/homebrew/linked/mono/");

			for (int i = 0; i < locations.size(); i++) {
				String hint_assembly_rootdir = path_join(locations[i], "lib");
				String hint_mscorlib_path = path_join(hint_assembly_rootdir, "mono", "4.5", "mscorlib.dll");
				String hint_config_dir = path_join(locations[i], "etc");

				if (FileAccess::exists(hint_mscorlib_path) && DirAccess::exists(hint_config_dir)) {
					mono_set_dirs(hint_assembly_rootdir.utf8().get_data(), hint_config_dir.utf8().get_data());
					break;
				}
			}
		}
	}
#else
	mono_set_dirs(NULL, NULL);
#endif

	GDMonoAssembly::initialize();

#ifdef DEBUG_ENABLED
	gdmono_debug_init();
#endif

	mono_config_parse(NULL);

	mono_install_unhandled_exception_hook(&unhandled_exception_hook, NULL);

	root_domain = mono_jit_init_version("GodotEngine.RootDomain", "v4.0.30319");

	ERR_EXPLAIN("Mono: Failed to initialize runtime");
	ERR_FAIL_NULL(root_domain);

	GDMonoUtils::set_main_thread(GDMonoUtils::get_current_thread());

	setup_runtime_main_args(); // Required for System.Environment.GetCommandLineArgs

	runtime_initialized = true;

	print_verbose("Mono: Runtime initialized");

	// mscorlib assembly MUST be present at initialization
	ERR_EXPLAIN("Mono: Failed to load mscorlib assembly");
	ERR_FAIL_COND(!_load_corlib_assembly());

#ifdef TOOLS_ENABLED
	// The tools domain must be loaded here, before the scripts domain.
	// Otherwise domain unload on the scripts domain will hang indefinitely.

	ERR_EXPLAIN("Mono: Failed to load tools domain");
	ERR_FAIL_COND(_load_tools_domain() != OK);

	// TODO move to editor init callback, and do it lazily when required before editor init (e.g.: bindings generation)
	ERR_EXPLAIN("Mono: Failed to load Editor Tools assembly");
	ERR_FAIL_COND(!_load_editor_tools_assembly());
#endif

	ERR_EXPLAIN("Mono: Failed to load scripts domain");
	ERR_FAIL_COND(_load_scripts_domain() != OK);

#ifdef DEBUG_ENABLED
	bool debugger_attached = _wait_for_debugger_msecs(500);
	if (!debugger_attached && OS::get_singleton()->is_stdout_verbose())
		print_error("Mono: Debugger wait timeout");
#endif

	_register_internal_calls();

	// The following assemblies are not required at initialization
#ifdef MONO_GLUE_ENABLED
	if (_load_api_assemblies()) {
		if (!core_api_assembly_out_of_sync && !editor_api_assembly_out_of_sync && GDMonoUtils::mono_cache.godot_api_cache_updated) {
			// Everything is fine with the api assemblies, load the project assembly
			_load_project_assembly();
		} else {
#ifdef TOOLS_ENABLED
			// The assembly was successfully loaded, but the full api could not be cached.
			// This is most likely an outdated assembly loaded because of an invalid version in the metadata,
			// so we invalidate the version in the metadata and unload the script domain.

			if (core_api_assembly_out_of_sync) {
				ERR_PRINT("The loaded Core API assembly is out of sync");
				metadata_set_api_assembly_invalidated(APIAssembly::API_CORE, true);
			} else if (!GDMonoUtils::mono_cache.godot_api_cache_updated) {
				ERR_PRINT("The loaded Core API assembly is in sync, but the cache update failed");
				metadata_set_api_assembly_invalidated(APIAssembly::API_CORE, true);
			}

			if (editor_api_assembly_out_of_sync) {
				ERR_PRINT("The loaded Editor API assembly is out of sync");
				metadata_set_api_assembly_invalidated(APIAssembly::API_EDITOR, true);
			}

			print_line("Mono: Proceeding to unload scripts domain because of invalid API assemblies.");

			Error err = _unload_scripts_domain();
			if (err != OK) {
				WARN_PRINT("Mono: Failed to unload scripts domain");
			}
#else
			ERR_PRINT("The loaded API assembly is invalid");
			CRASH_NOW();
#endif
		}
	}
#else
	print_verbose("Mono: Glue disabled, ignoring script assemblies.");
#endif

	print_verbose("Mono: INITIALIZED");
}
Beispiel #15
0
void GDMono::initialize() {

	ERR_FAIL_NULL(Engine::get_singleton());

	OS::get_singleton()->print("Mono: Initializing module...\n");

#ifdef DEBUG_METHODS_ENABLED
	_initialize_and_check_api_hashes();
#endif

	GDMonoLog::get_singleton()->initialize();

#ifdef MONO_PRINT_HANDLER_ENABLED
	mono_trace_set_print_handler(gdmono_MonoPrintCallback);
	mono_trace_set_printerr_handler(gdmono_MonoPrintCallback);
#endif

#ifdef WINDOWS_ENABLED
	mono_reg_info = MonoRegUtils::find_mono();

	CharString assembly_dir;
	CharString config_dir;

	if (mono_reg_info.assembly_dir.length() && DirAccess::exists(mono_reg_info.assembly_dir)) {
		assembly_dir = mono_reg_info.assembly_dir.utf8();
	}

	if (mono_reg_info.config_dir.length() && DirAccess::exists(mono_reg_info.config_dir)) {
		config_dir = mono_reg_info.config_dir.utf8();
	}

	mono_set_dirs(assembly_dir.length() ? assembly_dir.get_data() : NULL,
			config_dir.length() ? config_dir.get_data() : NULL);
#else
	mono_set_dirs(NULL, NULL);
#endif

	GDMonoAssembly::initialize();

#ifdef DEBUG_ENABLED
	gdmono_debug_init();
#endif

	mono_config_parse(NULL);

	root_domain = mono_jit_init_version("GodotEngine.RootDomain", "v4.0.30319");

	ERR_EXPLAIN("Mono: Failed to initialize runtime");
	ERR_FAIL_NULL(root_domain);

	GDMonoUtils::set_main_thread(GDMonoUtils::get_current_thread());

	runtime_initialized = true;

	OS::get_singleton()->print("Mono: Runtime initialized\n");

	// mscorlib assembly MUST be present at initialization
	ERR_EXPLAIN("Mono: Failed to load mscorlib assembly");
	ERR_FAIL_COND(!_load_corlib_assembly());

#ifdef TOOLS_ENABLED
	// The tools domain must be loaded here, before the scripts domain.
	// Otherwise domain unload on the scripts domain will hang indefinitely.

	ERR_EXPLAIN("Mono: Failed to load tools domain");
	ERR_FAIL_COND(_load_tools_domain() != OK);

	// TODO move to editor init callback, and do it lazily when required before editor init (e.g.: bindings generation)
	ERR_EXPLAIN("Mono: Failed to load Editor Tools assembly");
	ERR_FAIL_COND(!_load_editor_tools_assembly());
#endif

	ERR_EXPLAIN("Mono: Failed to load scripts domain");
	ERR_FAIL_COND(_load_scripts_domain() != OK);

#ifdef DEBUG_ENABLED
	bool debugger_attached = _wait_for_debugger_msecs(500);
	if (!debugger_attached && OS::get_singleton()->is_stdout_verbose())
		OS::get_singleton()->printerr("Mono: Debugger wait timeout\n");
#endif

	_register_internal_calls();

	// The following assemblies are not required at initialization
	_load_all_script_assemblies();

	mono_install_unhandled_exception_hook(gdmono_unhandled_exception_hook, NULL);

	OS::get_singleton()->print("Mono: INITIALIZED\n");
}