Ejemplo n.º 1
0
/*
Convert this MonoError to an exception if it's faulty or return NULL.
The error object is cleant after.
*/
MonoException*
mono_error_convert_to_exception (MonoError *target_error)
{
	ERROR_DECL (error);
	MonoException *ex;

	/* Mempool stored error shouldn't be cleaned up */
	g_assert (!is_boxed ((MonoErrorInternal*)target_error));

	if (mono_error_ok (target_error))
		return NULL;

	ex = mono_error_prepare_exception (target_error, error);
	if (!mono_error_ok (error)) {
		ERROR_DECL (second_chance);
		/*Try to produce the exception for the second error. FIXME maybe we should log about the original one*/
		ex = mono_error_prepare_exception (error, second_chance);

		// We cannot reasonably handle double faults, maybe later.
		g_assert (mono_error_ok (second_chance));
		mono_error_cleanup (error);
	}
	mono_error_cleanup (target_error);
	return ex;
}
Ejemplo n.º 2
0
void
mono_error_set_argument_out_of_range (MonoError *error, const char *name)
{
	ERROR_DECL (error_creating_exception);
	mono_error_set_exception_handle (error, mono_new_exception_argument_out_of_range (name, error_creating_exception));
	mono_error_cleanup (error_creating_exception);
}
Ejemplo n.º 3
0
/* Used by mono_error_prepare_exception - it sets its own error on mono_string_new_checked failure. */
static MonoStringHandle
string_new_cleanup (MonoDomain *domain, const char *text)
{
	ERROR_DECL (ignored_err);
	MonoStringHandle result = mono_string_new_handle (domain, text, ignored_err);
	mono_error_cleanup (ignored_err);
	return result;
}
Ejemplo n.º 4
0
static int
dump_verify_info (MonoImage *image, int flags)
{
	GSList *errors, *tmp;
	int count = 0, verifiable = 0;
	const char* desc [] = {
		"Ok", "Error", "Warning", NULL, "CLS", NULL, NULL, NULL, "Not Verifiable"
	};

	if (verify_code) { /* verify code */
		int i;
		MonoTableInfo *m = &image->tables [MONO_TABLE_METHOD];

		for (i = 0; i < m->rows; ++i) {
			MonoMethod *method;
			MonoError error;

			method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i+1), NULL, NULL, &error);
			if (!method) {
				g_print ("Warning: Cannot lookup method with token 0x%08x due to %s\n", i + 1, mono_error_get_message (&error));
				mono_error_cleanup (&error);
				continue;
			}
			errors = mono_method_verify (method, flags);
			if (errors) {
				MonoClass *klass = mono_method_get_class (method);
				char *name = mono_type_full_name (&klass->byval_arg);
				if (mono_method_signature (method) == NULL) {
					g_print ("In method: %s::%s(ERROR)\n", name, mono_method_get_name (method));
				} else {
					char *sig;
					sig = mono_signature_get_desc (mono_method_signature (method), FALSE);	
					g_print ("In method: %s::%s(%s)\n", name, mono_method_get_name (method), sig);
					g_free (sig);
				}
				g_free (name);
			}

			for (tmp = errors; tmp; tmp = tmp->next) {
				MonoVerifyInfo *info = (MonoVerifyInfo *)tmp->data;
				g_print ("%s: %s\n", desc [info->status], info->message);
				if (info->status == MONO_VERIFY_ERROR) {
					count++;
					verifiable = 3;
				}
				if(info->status == MONO_VERIFY_NOT_VERIFIABLE) {
					if (verifiable < 2)
						verifiable = 2;	
				}
			}
			mono_free_verify_list (errors);
		}
	}

	if (count)
		g_print ("Error count: %d\n", count);
	return verifiable;
}
Ejemplo n.º 5
0
static void
do_console_cancel_event (void)
{
	static MonoClassField *cancel_handler_field;
	MonoError error;
	MonoDomain *domain = mono_domain_get ();
	MonoClass *klass;
	MonoDelegate *load_value;
	MonoMethod *method;
	MonoVTable *vtable;

	/* FIXME: this should likely iterate all the domains, instead */
	if (!domain->domain)
		return;

	klass = mono_class_try_load_from_name (mono_defaults.corlib, "System", "Console");
	if (klass == NULL)
		return;

	if (cancel_handler_field == NULL) {
		cancel_handler_field = mono_class_get_field_from_name (klass, "cancel_handler");
		g_assert (cancel_handler_field);
	}

	vtable = mono_class_vtable_full (domain, klass, &error);
	if (vtable == NULL || !is_ok (&error)) {
		mono_error_cleanup (&error);
		return;
	}
	mono_field_static_get_value_checked (vtable, cancel_handler_field, &load_value, &error);
	if (load_value == NULL || !is_ok (&error)) {
		mono_error_cleanup (&error);
		return;
	}

	klass = load_value->object.vtable->klass;
	method = mono_class_get_method_from_name (klass, "BeginInvoke", -1);
	g_assert (method != NULL);

	mono_threadpool_ms_begin_invoke (domain, (MonoObject*) load_value, method, NULL, &error);
	if (!is_ok (&error)) {
		g_warning ("Couldn't invoke System.Console cancel handler due to %s", mono_error_get_message (&error));
		mono_error_cleanup (&error);
	}
}
Ejemplo n.º 6
0
/**
 * mono_get_exception_argument_internal:
 * \param type the actual type
 * \param arg the name of the argument that is invalid or null, etc.
 * \param msg optional message
 * \returns a new instance of the \c System.ArgumentException or derived
 */
static MonoException*
mono_get_exception_argument_internal (const char *type, const char *arg, const char *msg)
{
	HANDLE_FUNCTION_ENTER ();
	ERROR_DECL (error);
	MonoExceptionHandle ex = mono_exception_new_argument_internal (type, arg, msg, error);
	mono_error_cleanup (error);
	HANDLE_FUNCTION_RETURN_OBJ (ex);
}
Ejemplo n.º 7
0
/**
 * mono_exception_from_token_two_strings:
 *
 *   Same as mono_exception_from_name_two_strings, but lookup the exception class using
 * IMAGE and TOKEN.
 */
MonoException *
mono_exception_from_token_two_strings (MonoImage *image, guint32 token,
									   MonoString *a1, MonoString *a2)
{
	MonoError error;
	MonoException *ret;
	ret = mono_exception_from_token_two_strings_checked (image, token, a1, a2, &error);
	mono_error_cleanup (&error);
	return ret;
}
Ejemplo n.º 8
0
/**
 * mono_exception_from_name_two_strings:
 * @image: the Mono image where to look for the class
 * @name_space: the namespace for the class
 * @name: class name
 * @a1: first string argument to pass
 * @a2: second string argument to pass
 *
 * Creates an exception from a constructor that takes two string
 * arguments.
 *
 * Returns: the initialized exception instance.
 */
MonoException *
mono_exception_from_name_two_strings (MonoImage *image, const char *name_space,
				      const char *name, MonoString *a1, MonoString *a2)
{
	MonoError error;
	MonoException *ret;

	ret = mono_exception_from_name_two_strings_checked (image, name_space, name, a1, a2, &error);
	mono_error_cleanup (&error);
	return ret;
}
Ejemplo n.º 9
0
/**
 * mono_exception_from_token_two_strings:
 *
 *   Same as mono_exception_from_name_two_strings, but lookup the exception class using
 * IMAGE and TOKEN.
 */
MonoException *
mono_exception_from_token_two_strings (MonoImage *image, guint32 token, MonoString *arg1_raw, MonoString *arg2_raw)
{
	HANDLE_FUNCTION_ENTER ();
	ERROR_DECL (error);
	MONO_HANDLE_DCL (MonoString, arg1);
	MONO_HANDLE_DCL (MonoString, arg2);
	MonoExceptionHandle ret = mono_exception_from_token_two_strings_checked (image, token, arg1, arg2, error);
	mono_error_cleanup (error);
	HANDLE_FUNCTION_RETURN_OBJ (ret);
}
Ejemplo n.º 10
0
/**
 * mono_exception_from_name_two_strings:
 * \param image the Mono image where to look for the class
 * \param name_space the namespace for the class
 * \param name class name
 * \param a1 first string argument to pass
 * \param a2 second string argument to pass
 *
 * Creates an exception from a constructor that takes two string
 * arguments.
 *
 * \returns the initialized exception instance.
 */
MonoException *
mono_exception_from_name_two_strings (MonoImage *image, const char *name_space,
				      const char *name, MonoString *a1_raw, MonoString *a2_raw)
{
	HANDLE_FUNCTION_ENTER ();
	ERROR_DECL (error);
	MONO_HANDLE_DCL (MonoString, a1);
	MONO_HANDLE_DCL (MonoString, a2);
	MonoExceptionHandle ret = mono_exception_from_name_two_strings_checked (image, name_space, name, a1, a2, error);
	mono_error_cleanup (error);
	HANDLE_FUNCTION_RETURN_OBJ (ret);
}
Ejemplo n.º 11
0
static MonoClass *test_mono_class_from_name (MonoImage *image,
					     const char *name_space,
					     const char *name)
{
	ERROR_DECL (error);
	MonoClass *klass;

	klass = mono_class_from_name_checked (image, name_space, name, error);
	mono_error_cleanup (error); /* FIXME Don't swallow the error */

	return klass;
}
Ejemplo n.º 12
0
MonoException*
mono_error_convert_to_exception (MonoError *target_error)
{
	MonoError error;
	MonoException *ex;

	if (mono_error_ok (target_error))
		return NULL;

	ex = mono_error_prepare_exception (target_error, &error);
	if (!mono_error_ok (&error)) {
		MonoError second_chance;
		/*Try to produce the exception for the second error. FIXME maybe we should log about the original one*/
		ex = mono_error_prepare_exception (&error, &second_chance);

		g_assert (mono_error_ok (&second_chance)); /*We can't reasonable handle double faults, maybe later.*/
		mono_error_cleanup (&error);
	}
	mono_error_cleanup (target_error);
	return ex;
}
Ejemplo n.º 13
0
MonoException *
mono_get_exception_runtime_wrapped (MonoObject *wrapped_exception)
{
	MonoError error;
	MonoException *ret = mono_get_exception_runtime_wrapped_checked (wrapped_exception, &error);
	if (!is_ok (&error)) {
		mono_error_cleanup (&error);
		return NULL;
	}

	return ret;
}
Ejemplo n.º 14
0
/**
 * mono_get_exception_type_initialization:
 * @type_name: the name of the type that failed to initialize.
 * @inner: the inner exception.
 *
 * Returns: a new instance of the `System.TypeInitializationException`
 */
MonoException *
mono_get_exception_type_initialization (const gchar *type_name, MonoException *inner)
{
	MonoError error;
	MonoException *ret = mono_get_exception_type_initialization_checked (type_name, inner, &error);
	if (!is_ok (&error)) {
		mono_error_cleanup (&error);
		return NULL;
	}

	return ret;
}
Ejemplo n.º 15
0
/**
 * mono_get_exception_reflection_type_load:
 * @types: an array of types that were defined in the moduled loaded.
 * @exceptions: an array of exceptions that were thrown during the type loading.
 *
 * Returns: a new instance of the `System.Reflection.ReflectionTypeLoadException`
 */
MonoException *
mono_get_exception_reflection_type_load (MonoArray *types, MonoArray *exceptions)
{
	MonoError error;
	MonoException *ret = mono_get_exception_reflection_type_load_checked (types, exceptions, &error);
	if (is_ok (&error)) {
		mono_error_cleanup (&error);
		return NULL;
	}

	return ret;
}
Ejemplo n.º 16
0
/**
 * mono_get_exception_runtime_wrapped:
 */
MonoException *
mono_get_exception_runtime_wrapped (MonoObject *wrapped_exception_raw)
{
	HANDLE_FUNCTION_ENTER ();
	ERROR_DECL (error);
	MONO_HANDLE_DCL (MonoObject, wrapped_exception);
	MonoExceptionHandle ret = mono_get_exception_runtime_wrapped_handle (wrapped_exception, error);
	if (!is_ok (error)) {
		mono_error_cleanup (error);
		ret = MONO_HANDLE_CAST (MonoException, mono_new_null ());
	}
	HANDLE_FUNCTION_RETURN_OBJ (ret);
}
Ejemplo n.º 17
0
/**
 * mono_exception_from_name_msg:
 * \param image the Mono image where to look for the class
 * \param name_space the namespace for the class
 * \param name class name
 * \param msg the message to embed inside the exception
 *
 * Creates an exception and initializes its message field.
 *
 * \returns the initialized exception instance.
 */
MonoException *
mono_exception_from_name_msg (MonoImage *image, const char *name_space,
			      const char *name, const char *msg)
{
	HANDLE_FUNCTION_ENTER ();
	MonoExceptionHandle ex;
	MONO_ENTER_GC_UNSAFE;
	ERROR_DECL (error);
	ex = mono_exception_new_by_name_msg (image, name_space, name, msg, error);
	mono_error_cleanup (error);
	MONO_EXIT_GC_UNSAFE;
	HANDLE_FUNCTION_RETURN_OBJ (ex);
}
Ejemplo n.º 18
0
/**
 * mono_get_exception_reflection_type_load:
 * \param types an array of types that were defined in the moduled loaded.
 * \param exceptions an array of exceptions that were thrown during the type loading.
 * \returns a new instance of the \c System.Reflection.ReflectionTypeLoadException
 */
MonoException *
mono_get_exception_reflection_type_load (MonoArray *types_raw, MonoArray *exceptions_raw)
{
	HANDLE_FUNCTION_ENTER ();
	ERROR_DECL (error);
	MONO_HANDLE_DCL (MonoArray, types);
	MONO_HANDLE_DCL (MonoArray, exceptions);
	MonoExceptionHandle ret = mono_get_exception_reflection_type_load_checked (types, exceptions, error);
	if (!is_ok (error))
		ret = MONO_HANDLE_CAST (MonoException, mono_new_null ());
	mono_error_cleanup (error);
	HANDLE_FUNCTION_RETURN_OBJ (ret);
}
Ejemplo n.º 19
0
/**
 * mono_get_exception_type_initialization:
 * \param type_name the name of the type that failed to initialize.
 * \param inner the inner exception.
 * \returns a new instance of the \c System.TypeInitializationException
 */
MonoException *
mono_get_exception_type_initialization (const gchar *type_name, MonoException* inner_raw)
{
	HANDLE_FUNCTION_ENTER ();
	MONO_HANDLE_DCL (MonoException, inner);
	ERROR_DECL (error);
	MonoExceptionHandle ret = mono_get_exception_type_initialization_handle (type_name, inner, error);
	if (!is_ok (error)) {
		ret = MONO_HANDLE_CAST (MonoException, mono_new_null ());
		mono_error_cleanup (error);
	}
	HANDLE_FUNCTION_RETURN_OBJ (ret);
}
Ejemplo n.º 20
0
static int
mono_attach_load_agent (MonoDomain *domain, char *agent, char *args, MonoObject **exc)
{
	MonoError error;
	MonoAssembly *agent_assembly;
	MonoImage *image;
	MonoMethod *method;
	guint32 entry;
	MonoArray *main_args;
	gpointer pa [1];
	MonoImageOpenStatus open_status;

	agent_assembly = mono_assembly_open (agent, &open_status);
	if (!agent_assembly) {
		fprintf (stderr, "Cannot open agent assembly '%s': %s.\n", agent, mono_image_strerror (open_status));
		g_free (agent);
		return 2;
	}

	/* 
	 * Can't use mono_jit_exec (), as it sets things which might confuse the
	 * real Main method.
	 */
	image = mono_assembly_get_image (agent_assembly);
	entry = mono_image_get_entry_point (image);
	if (!entry) {
		g_print ("Assembly '%s' doesn't have an entry point.\n", mono_image_get_filename (image));
		g_free (agent);
		return 1;
	}

	method = mono_get_method_checked (image, entry, NULL, NULL, &error);
	if (method == NULL){
		g_print ("The entry point method of assembly '%s' could not be loaded due to %s\n", agent, mono_error_get_message (&error));
		mono_error_cleanup (&error);
		g_free (agent);
		return 1;
	}
	
	if (args) {
		main_args = (MonoArray*)mono_array_new (domain, mono_defaults.string_class, 1);
		mono_array_set (main_args, MonoString*, 0, mono_string_new (domain, args));
	} else {
Ejemplo n.º 21
0
MonoMethod*
mono_method_desc_search_in_image (MonoMethodDesc *desc, MonoImage *image)
{
	MonoClass *klass;
	const MonoTableInfo *methods;
	MonoMethod *method;
	int i;

	/* Handle short names for system classes */
	if (!desc->name_space && image == mono_defaults.corlib) {
		klass = find_system_class (desc->klass);
		if (klass)
			return mono_method_desc_search_in_class (desc, klass);
	}

	if (desc->name_space && desc->klass) {
		klass = mono_class_try_load_from_name (image, desc->name_space, desc->klass);
		if (!klass)
			return NULL;
		return mono_method_desc_search_in_class (desc, klass);
	}

	/* FIXME: Is this call necessary?  We don't use its result. */
	mono_image_get_table_info (image, MONO_TABLE_TYPEDEF);
	methods = mono_image_get_table_info (image, MONO_TABLE_METHOD);
	for (i = 0; i < mono_table_info_get_rows (methods); ++i) {
		MonoError error;
		guint32 token = mono_metadata_decode_row_col (methods, i, MONO_METHOD_NAME);
		const char *n = mono_metadata_string_heap (image, token);

		if (strcmp (n, desc->name))
			continue;
		method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
		if (!method) {
			mono_error_cleanup (&error);
			continue;
		}
		if (mono_method_desc_full_match (desc, method))
			return method;
	}
	return NULL;
}
Ejemplo n.º 22
0
void
mono_invoke_unhandled_exception_hook (MonoObject *exc)
{
	if (unhandled_exception_hook) {
		unhandled_exception_hook (exc, unhandled_exception_hook_data);
	} else {
		MonoError inner_error;
		MonoObject *other = NULL;
		MonoString *str = mono_object_try_to_string (exc, &other, &inner_error);
		char *msg = NULL;
		
		if (str && is_ok (&inner_error)) {
			msg = mono_string_to_utf8_checked (str, &inner_error);
			if (!is_ok (&inner_error)) {
				msg = g_strdup_printf ("Nested exception while formatting original exception");
				mono_error_cleanup (&inner_error);
			}
		} else if (other) {
			char *original_backtrace = mono_exception_get_managed_backtrace ((MonoException*)exc);
			char *nested_backtrace = mono_exception_get_managed_backtrace ((MonoException*)other);

			msg = g_strdup_printf ("Nested exception detected.\nOriginal Exception: %s\nNested exception:%s\n",
				original_backtrace, nested_backtrace);

			g_free (original_backtrace);
			g_free (nested_backtrace);
		} else {
			msg = g_strdup ("Nested exception trying to figure out what went wrong");
		}
		mono_runtime_printf_err ("[ERROR] FATAL UNHANDLED EXCEPTION: %s", msg);
		g_free (msg);
#if defined(HOST_IOS)
		g_assertion_message ("Terminating runtime due to unhandled exception");
#else
		exit (mono_environment_exitcode_get ());
#endif
	}

	g_assert_not_reached ();
}
Ejemplo n.º 23
0
static int
verify_image_file (const char *fname)
{
	GSList *errors = NULL, *tmp;
	MonoImage *image;
	MonoTableInfo *table;
	MonoAssembly *assembly;
	MonoImageOpenStatus status;
	int i, count = 0;
	const char* desc [] = {
		"Ok", "Error", "Warning", NULL, "CLS", NULL, NULL, NULL, "Not Verifiable"
	};

	image = mono_image_open_raw (fname, &status);
	if (!image) {
		printf ("Could not open %s\n", fname);
		return 1;
	}

	if (!mono_verifier_verify_pe_data (image, &errors))
		goto invalid_image;

	if (!mono_image_load_pe_data (image)) {
		printf ("Could not load pe data for assembly %s\n", fname);
		return 1;
	}

	if (!mono_verifier_verify_cli_data (image, &errors))
		goto invalid_image;

	if (!mono_image_load_cli_data (image)) {
		printf ("Could not load cli data for assembly %s\n", fname);
		return 1;
	}

	if (!mono_verifier_verify_table_data (image, &errors))
		goto invalid_image;

	mono_image_load_names (image);

	/*fake an assembly for class loading to work*/
	assembly = g_new0 (MonoAssembly, 1);
	assembly->in_gac = FALSE;
	assembly->image = image;
	image->assembly = assembly;
	mono_assembly_fill_assembly_name (image, &assembly->aname);

	/*Finish initializing the runtime*/
	mono_install_assembly_load_hook (pedump_assembly_load_hook, NULL);
	mono_install_assembly_search_hook (pedump_assembly_search_hook, NULL);

	mono_init_version ("pedump", image->version);

	mono_install_assembly_preload_hook (pedump_preload, GUINT_TO_POINTER (FALSE));

	mono_icall_init ();
	mono_marshal_init ();


	if (!verify_partial_md && !mono_verifier_verify_full_table_data (image, &errors))
		goto invalid_image;


	table = &image->tables [MONO_TABLE_TYPEDEF];
	for (i = 1; i <= table->rows; ++i) {
		MonoError error;
		guint32 token = i | MONO_TOKEN_TYPE_DEF;
		MonoClass *klass = mono_class_get_checked (image, token, &error);
		if (!klass) {
			printf ("Could not load class with token %x due to %s\n", token, mono_error_get_message (&error));
			mono_error_cleanup (&error);
			continue;
		}
		mono_class_init (klass);
		if (mono_class_has_failure (klass)) {
			printf ("Error verifying class(0x%08x) %s.%s a type load error happened\n", token, klass->name_space, klass->name);
			++count;
		}

		mono_class_setup_vtable (klass);
		if (mono_class_has_failure (klass)) {
			printf ("Error verifying class(0x%08x) %s.%s a type load error happened\n", token, klass->name_space, klass->name);
			++count;
		}
	}
	if (count)
		return 5;
	return 0;

invalid_image:
	for (tmp = errors; tmp; tmp = tmp->next) {
		MonoVerifyInfo *info = (MonoVerifyInfo *)tmp->data;
		g_print ("%s: %s\n", desc [info->status], info->message);
		if (info->status == MONO_VERIFY_ERROR)
			count++;
	}
	mono_free_verify_list (errors);
	if (count)
		g_print ("Error count: %d\n", count);
	return 1;
}
Ejemplo n.º 24
0
Archivo: coree.c Proyecto: vargaz/mono
__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 ());
}
Ejemplo n.º 25
0
static int
verify_image_file (const char *fname)
{
	ERROR_DECL (error);

	MonoImage *image;
	MonoTableInfo *table;
	MonoAssembly *assembly;
	MonoImageOpenStatus status;
	int i, count = 0;

	if (!strstr (fname, "mscorlib.dll")) {
		image = mono_image_open_raw (fname, &status);
		if (!image) {
			printf ("Could not open %s\n", fname);
			return 1;
		}

		if (!mono_verifier_verify_pe_data (image, error))
			goto invalid_image;

		if (!mono_image_load_pe_data (image)) {
			printf ("Could not load pe data for assembly %s\n", fname);
			return 1;
		}

		if (!mono_verifier_verify_cli_data (image, error))
			goto invalid_image;

		if (!mono_image_load_cli_data (image)) {
			printf ("Could not load cli data for assembly %s\n", fname);
			return 1;
		}

		if (!mono_verifier_verify_table_data (image, error))
			goto invalid_image;

		mono_image_load_names (image);

		/*fake an assembly for class loading to work*/
		assembly = g_new0 (MonoAssembly, 1);
		assembly->in_gac = FALSE;
		assembly->image = image;
		image->assembly = assembly;
		mono_assembly_fill_assembly_name (image, &assembly->aname);

		/*Finish initializing the runtime*/
		mono_install_assembly_load_hook (pedump_assembly_load_hook, NULL);
		mono_install_assembly_search_hook (pedump_assembly_search_hook, NULL);

		mono_init_version ("pedump", image->version);

		mono_install_assembly_preload_hook (pedump_preload, GUINT_TO_POINTER (FALSE));

		mono_icall_init ();
		mono_marshal_init ();
	} else {
		/*Finish initializing the runtime*/
		mono_install_assembly_load_hook (pedump_assembly_load_hook, NULL);
		mono_install_assembly_search_hook (pedump_assembly_search_hook, NULL);

		mono_init_version ("pedump", NULL);

		mono_install_assembly_preload_hook (pedump_preload, GUINT_TO_POINTER (FALSE));

		mono_icall_init ();
		mono_marshal_init ();
		image = mono_get_corlib ();

		if (!mono_verifier_verify_pe_data (image, error))
			goto invalid_image;

		if (!mono_image_load_pe_data (image)) {
			printf ("Could not load pe data for assembly %s\n", fname);
			return 1;
		}

		if (!mono_verifier_verify_cli_data (image, error))
			goto invalid_image;

		if (!mono_image_load_cli_data (image)) {
			printf ("Could not load cli data for assembly %s\n", fname);
			return 1;
		}

		if (!mono_verifier_verify_table_data (image, error))
			goto invalid_image;
	}

	if (!verify_partial_md && !mono_verifier_verify_full_table_data (image, error))
		goto invalid_image;


	table = &image->tables [MONO_TABLE_TYPEDEF];
	for (i = 1; i <= table->rows; ++i) {
		ERROR_DECL (error);
		guint32 token = i | MONO_TOKEN_TYPE_DEF;
		MonoClass *klass = mono_class_get_checked (image, token, error);
		if (!klass) {
			printf ("Could not load class with token %x due to %s\n", token, mono_error_get_message (error));
			mono_error_cleanup (error);
			continue;
		}
		mono_class_init_internal (klass);
		if (mono_class_has_failure (klass)) {
			ERROR_DECL (type_load_error);
			mono_error_set_for_class_failure (type_load_error, klass);
			printf ("Could not initialize class(0x%08x) %s.%s due to %s\n", token, m_class_get_name_space (klass), m_class_get_name (klass), mono_error_get_message (type_load_error));
			mono_error_cleanup (type_load_error);
			++count;
		}

		mono_class_setup_vtable (klass);
		if (mono_class_has_failure (klass)) {
			ERROR_DECL (type_load_error);
			mono_error_set_for_class_failure (type_load_error, klass);
			printf ("Could not initialize vtable of class(0x%08x) %s.%s due to %s\n", token, m_class_get_name_space (klass), m_class_get_name (klass), mono_error_get_message (type_load_error));
			mono_error_cleanup (type_load_error);
			++count;
		}
	}
	if (count)
		return 5;
	return 0;

invalid_image:
	if (!is_ok (error)) {
		g_print ("FAIL: %s\n", mono_error_get_message (error));
		mono_error_cleanup (error);
		++count;
	}
	if (count)
		g_print ("Error count: %d\n", count);
	return 1;
}