/* Entry point called by LdrLoadDll of ntdll.dll after _CorValidateImage. */ BOOL STDMETHODCALLTYPE _CorDllMain(HINSTANCE hInst, DWORD dwReason, LPVOID lpReserved) { MonoAssembly* assembly; MonoImage* image; gchar* file_name; gchar* error; switch (dwReason) { case DLL_PROCESS_ATTACH: DisableThreadLibraryCalls (hInst); file_name = mono_get_module_file_name (hInst); if (mono_get_root_domain ()) { image = mono_image_open_from_module_handle (hInst, mono_path_resolve_symlinks (file_name), TRUE, NULL); } else { init_from_coree = TRUE; mono_runtime_load (file_name, NULL); error = (gchar*) mono_check_corlib_version (); if (error) { g_free (error); g_free (file_name); mono_runtime_quit (); return FALSE; } image = mono_image_open (file_name, NULL); if (image) { image->has_entry_point = TRUE; mono_close_exe_image (); /* Decrement reference count to zero. (Image will not be closed.) */ mono_image_close (image); } } if (!image) { g_free (file_name); return FALSE; } /* * FIXME: Find a better way to call mono_image_fixup_vtable. Only * loader trampolines should be used and assembly loading should * probably be delayed until the first call to an exported function. */ if (image->tables [MONO_TABLE_ASSEMBLY].rows && ((MonoCLIImageInfo*) image->image_info)->cli_cli_header.ch_vtable_fixups.rva) assembly = mono_assembly_open (file_name, NULL); g_free (file_name); break; case DLL_PROCESS_DETACH: if (lpReserved != NULL) /* The process is terminating. */ return TRUE; file_name = mono_get_module_file_name (hInst); image = mono_image_loaded (file_name); if (image) mono_image_close (image); g_free (file_name); break; } return TRUE; }
__int32 STDMETHODCALLTYPE _CorExeMain(void) { ERROR_DECL (error); MonoDomain* domain; MonoAssembly* assembly; MonoImage* image; MonoMethod* method; guint32 entry; gchar* file_name; gchar* corlib_version_error; int argc; gunichar2** argvw; gchar** argv; int i; file_name = mono_get_module_file_name (NULL); init_from_coree = TRUE; domain = mono_runtime_load (file_name, NULL); corlib_version_error = (gchar*) mono_check_corlib_version (); if (corlib_version_error) { g_free (corlib_version_error); g_free (file_name); MessageBox (NULL, L"Corlib not in sync with this runtime.", NULL, MB_ICONERROR); mono_runtime_quit (); ExitProcess (1); } MonoAssemblyOpenRequest req; mono_assembly_request_prepare (&req.request, sizeof (req), MONO_ASMCTX_DEFAULT); assembly = mono_assembly_request_open (file_name, &req, NULL); mono_close_exe_image (); if (!assembly) { g_free (file_name); MessageBox (NULL, L"Cannot open assembly.", NULL, MB_ICONERROR); mono_runtime_quit (); ExitProcess (1); } image = assembly->image; entry = mono_image_get_entry_point (image); if (!entry) { g_free (file_name); MessageBox (NULL, L"Assembly doesn't have an entry point.", NULL, MB_ICONERROR); mono_runtime_quit (); ExitProcess (1); } method = mono_get_method_checked (image, entry, NULL, NULL, error); if (method == NULL) { g_free (file_name); mono_error_cleanup (error); /* FIXME don't swallow the error */ MessageBox (NULL, L"The entry point method could not be loaded.", NULL, MB_ICONERROR); mono_runtime_quit (); ExitProcess (1); } argvw = CommandLineToArgvW (GetCommandLine (), &argc); argv = g_new0 (gchar*, argc); argv [0] = file_name; for (i = 1; i < argc; ++i) argv [i] = g_utf16_to_utf8 (argvw [i], -1, NULL, NULL, NULL); LocalFree (argvw); mono_runtime_run_main_checked (method, argc, argv, error); mono_error_raise_exception_deprecated (error); /* OK, triggers unhandled exn handler */ mono_thread_manage (); mono_runtime_quit (); /* return does not terminate the process. */ ExitProcess (mono_environment_exitcode_get ()); }
/* Called by ntdll.dll reagardless of entry point after _CorValidateImage. */ __int32 STDMETHODCALLTYPE _CorExeMain(void) { MonoDomain* domain; MonoAssembly* assembly; MonoImage* image; MonoMethod* method; guint32 entry; gchar* file_name; gchar* error; int argc; gunichar2** argvw; gchar** argv; int i; file_name = mono_get_module_file_name (NULL); init_from_coree = TRUE; domain = mono_runtime_load (file_name, NULL); error = (gchar*) mono_check_corlib_version (); if (error) { g_free (error); g_free (file_name); MessageBox (NULL, L"Corlib not in sync with this runtime.", NULL, MB_ICONERROR); mono_runtime_quit (); ExitProcess (1); } assembly = mono_assembly_open (file_name, NULL); mono_close_exe_image (); if (!assembly) { g_free (file_name); MessageBox (NULL, L"Cannot open assembly.", NULL, MB_ICONERROR); mono_runtime_quit (); ExitProcess (1); } image = assembly->image; entry = mono_image_get_entry_point (image); if (!entry) { g_free (file_name); MessageBox (NULL, L"Assembly doesn't have an entry point.", NULL, MB_ICONERROR); mono_runtime_quit (); ExitProcess (1); } method = mono_get_method (image, entry, NULL); if (method == NULL) { g_free (file_name); MessageBox (NULL, L"The entry point method could not be loaded.", NULL, MB_ICONERROR); mono_runtime_quit (); ExitProcess (1); } argvw = CommandLineToArgvW (GetCommandLine (), &argc); argv = g_new0 (gchar*, argc); argv [0] = file_name; for (i = 1; i < argc; ++i) argv [i] = g_utf16_to_utf8 (argvw [i], -1, NULL, NULL, NULL); LocalFree (argvw); mono_runtime_run_main (method, argc, argv, NULL); mono_thread_manage (); mono_runtime_quit (); /* return does not terminate the process. */ ExitProcess (mono_environment_exitcode_get ()); }
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 }