Exemple #1
0
static void
initialize (void)
{
	g_assert (!threadpool_io);
	threadpool_io = g_new0 (ThreadPoolIO, 1);
	g_assert (threadpool_io);

	mono_coop_mutex_init (&threadpool_io->updates_lock);
	mono_coop_cond_init (&threadpool_io->updates_cond);
	mono_gc_register_root ((char *)&threadpool_io->updates [0], sizeof (threadpool_io->updates), MONO_GC_DESCRIPTOR_NULL, MONO_ROOT_SOURCE_THREAD_POOL, "i/o thread pool updates list");

	threadpool_io->updates_size = 0;

	threadpool_io->backend = backend_poll;
	if (g_getenv ("MONO_ENABLE_AIO") != NULL) {
#if defined(HAVE_EPOLL)
		threadpool_io->backend = backend_epoll;
#elif defined(HAVE_KQUEUE)
		threadpool_io->backend = backend_kqueue;
#endif
	}

	wakeup_pipes_init ();

	if (!threadpool_io->backend.init (threadpool_io->wakeup_pipes [0]))
		g_error ("initialize: backend->init () failed");

	MonoError error;
	if (!mono_thread_create_internal (mono_get_root_domain (), selector_thread, NULL, TRUE, SMALL_STACK, &error))
		g_error ("initialize: mono_thread_create_internal () failed due to %s", mono_error_get_message (&error));
}
Exemple #2
0
void
mono_error_assert_ok_pos (MonoError *error, const char* filename, int lineno)
{
	if (mono_error_ok (error))
		return;

	g_error ("%s:%d: %s\n", filename, lineno, mono_error_get_message (error));
}
Exemple #3
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;
}
Exemple #4
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);
	}
}
Exemple #5
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;
}
Exemple #6
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;
}
Exemple #7
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 {