/** * mono_config_parse: * @filename: the filename to load the configuration variables from. * * Pass a NULL filename to parse the default config files * (or the file in the MONO_CONFIG env var). */ void mono_config_parse (const char *filename) { const char *home; char *mono_cfg; #ifndef TARGET_WIN32 char *user_cfg; #endif if (filename) { mono_config_parse_file (filename); return; } home = g_getenv ("MONO_CONFIG"); if (home) { mono_config_parse_file (home); return; } mono_cfg = g_build_filename (mono_get_config_dir (), "mono", "config", NULL); mono_config_parse_file (mono_cfg); g_free (mono_cfg); #if !defined(TARGET_WIN32) && !defined(__native_client__) home = g_get_home_dir (); user_cfg = g_strconcat (home, G_DIR_SEPARATOR_S, ".mono/config", NULL); mono_config_parse_file (user_cfg); g_free (user_cfg); #endif }
void mono_config_for_assembly (MonoImage *assembly) { ParseState state = {NULL}; int got_it = 0, i; char *aname, *cfg, *cfg_name; const char *bundled_config; const char *home; state.assembly = assembly; bundled_config = mono_config_string_for_assembly_file (assembly->module_name); if (bundled_config) { state.user_data = (gpointer) "<bundled>"; mono_config_parse_xml_with_context (&state, bundled_config, strlen (bundled_config)); } cfg_name = g_strdup_printf ("%s.config", mono_image_get_filename (assembly)); mono_config_parse_file_with_context (&state, cfg_name); g_free (cfg_name); cfg_name = g_strdup_printf ("%s.config", mono_image_get_name (assembly)); home = g_get_home_dir (); for (i = 0; (aname = get_assembly_filename (assembly, i)) != NULL; ++i) { cfg = g_build_filename (mono_get_config_dir (), "mono", "assemblies", aname, cfg_name, NULL); got_it += mono_config_parse_file_with_context (&state, cfg); g_free (cfg); #ifdef TARGET_WIN32 cfg = g_build_filename (home, ".mono", "assemblies", aname, cfg_name, NULL); got_it += mono_config_parse_file_with_context (&state, cfg); g_free (cfg); #endif g_free (aname); if (got_it) break; } g_free (cfg_name); }
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 }
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"); }