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); } }
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; }