* TODO:
* This should keep track of the assembly versions that we are loading.
*
+ * Licensed under the MIT license. See LICENSE file in the project root for full license information.
*/
#include <config.h>
#include <glib.h>
static guint32 methods_size;
static guint32 signatures_size;
-/*
- * This TLS variable contains the last type load error encountered by the loader.
- */
-MonoNativeTlsKey loader_error_thread_id;
-
/*
* This TLS variable holds how many times the current thread has acquired the loader
* lock.
mono_os_mutex_init_recursive (&global_loader_data_mutex);
loader_lock_inited = TRUE;
- mono_native_tls_alloc (&loader_error_thread_id, NULL);
mono_native_tls_alloc (&loader_lock_nest_id, NULL);
mono_counters_init ();
{
dllmap_cleanup ();
- mono_native_tls_free (loader_error_thread_id);
mono_native_tls_free (loader_lock_nest_id);
mono_coop_mutex_destroy (&loader_mutex);
loader_lock_inited = FALSE;
}
-/*
- * Handling of type load errors should be done as follows:
- *
- * If something could not be loaded, the loader should call one of the
- * mono_loader_set_error_XXX functions ()
- * with the appropriate arguments, then return NULL to report the failure. The error
- * should be propagated until it reaches code which can throw managed exceptions. At that
- * point, an exception should be thrown based on the information returned by
- * mono_loader_get_last_error (). Then the error should be cleared by calling
- * mono_loader_clear_error ().
- */
-
-static void
-set_loader_error (MonoLoaderError *error)
-{
- mono_loader_clear_error ();
- mono_native_tls_set_value (loader_error_thread_id, error);
-}
-
-/**
- * mono_loader_set_error_assembly_load:
- *
- * Set the loader error for this thread.
- */
-void
-mono_loader_set_error_assembly_load (const char *assembly_name, gboolean ref_only)
-{
- MonoLoaderError *error;
-
- if (mono_loader_get_last_error ())
- return;
-
- error = g_new0 (MonoLoaderError, 1);
- error->exception_type = MONO_EXCEPTION_FILE_NOT_FOUND;
- error->assembly_name = g_strdup (assembly_name);
- error->ref_only = ref_only;
-
- /*
- * This is not strictly needed, but some (most) of the loader code still
- * can't deal with load errors, and this message is more helpful than an
- * assert.
- */
- if (ref_only)
- mono_trace (G_LOG_LEVEL_WARNING, MONO_TRACE_ASSEMBLY, "Cannot resolve dependency to assembly '%s' because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event.", assembly_name);
- else
- mono_trace (G_LOG_LEVEL_WARNING, MONO_TRACE_ASSEMBLY, "Could not load file or assembly '%s' or one of its dependencies.", assembly_name);
-
- set_loader_error (error);
-}
-
-/**
- * mono_loader_set_error_type_load:
- *
- * Set the loader error for this thread.
- */
-void
-mono_loader_set_error_type_load (const char *class_name, const char *assembly_name)
-{
- MonoLoaderError *error;
-
- if (mono_loader_get_last_error ())
- return;
-
- error = g_new0 (MonoLoaderError, 1);
- error->exception_type = MONO_EXCEPTION_TYPE_LOAD;
- error->class_name = g_strdup (class_name);
- error->assembly_name = g_strdup (assembly_name);
-
- /*
- * This is not strictly needed, but some (most) of the loader code still
- * can't deal with load errors, and this message is more helpful than an
- * assert.
- */
- mono_trace_warning (MONO_TRACE_TYPE, "The class %s could not be loaded, used in %s", class_name, assembly_name);
-
- set_loader_error (error);
-}
-
-/*
- * mono_loader_set_error_method_load:
- *
- * Set the loader error for this thread. MEMBER_NAME should point to a string
- * inside metadata.
- */
-void
-mono_loader_set_error_method_load (const char *class_name, const char *member_name)
-{
- MonoLoaderError *error;
-
- /* FIXME: Store the signature as well */
- if (mono_loader_get_last_error ())
- return;
-
- error = g_new0 (MonoLoaderError, 1);
- error->exception_type = MONO_EXCEPTION_MISSING_METHOD;
- error->class_name = g_strdup (class_name);
- error->member_name = member_name;
-
- set_loader_error (error);
-}
-
-/*
- * mono_loader_set_error_field_load:
- *
- * Set the loader error for this thread. MEMBER_NAME should point to a string
- * inside metadata.
- */
-void
-mono_loader_set_error_field_load (MonoClass *klass, const char *member_name)
-{
- MonoLoaderError *error;
-
- /* FIXME: Store the signature as well */
- if (mono_loader_get_last_error ())
- return;
-
- error = g_new0 (MonoLoaderError, 1);
- error->exception_type = MONO_EXCEPTION_MISSING_FIELD;
- error->klass = klass;
- error->member_name = member_name;
-
- set_loader_error (error);
-}
-
-/*
- * mono_loader_set_error_bad_image:
- *
- * Set the loader error for this thread.
- */
-void
-mono_loader_set_error_bad_image (char *msg)
-{
- MonoLoaderError *error;
-
- if (mono_loader_get_last_error ())
- return;
-
- error = g_new0 (MonoLoaderError, 1);
- error->exception_type = MONO_EXCEPTION_BAD_IMAGE;
- error->msg = msg;
-
- set_loader_error (error);
-}
-
-
-/*
- * mono_loader_get_last_error:
- *
- * Returns information about the last type load exception encountered by the loader, or
- * NULL. After use, the exception should be cleared by calling mono_loader_clear_error.
- */
-MonoLoaderError*
-mono_loader_get_last_error (void)
-{
- return (MonoLoaderError*)mono_native_tls_get_value (loader_error_thread_id);
-}
-
-void
-mono_loader_assert_no_error (void)
-{
- MonoLoaderError *error = mono_loader_get_last_error ();
-
- if (error) {
- g_print ("Unhandled loader error: %x, %s %s %s\n", error->exception_type, error->msg, error->assembly_name, error->class_name);
- g_assert_not_reached ();
- }
-}
-
-/**
- * mono_loader_clear_error:
- *
- * Disposes any loader error messages on this thread
- */
-void
-mono_loader_clear_error (void)
-{
- MonoLoaderError *ex = (MonoLoaderError*)mono_native_tls_get_value (loader_error_thread_id);
-
- if (ex) {
- g_free (ex->class_name);
- g_free (ex->assembly_name);
- g_free (ex->msg);
- g_free (ex);
-
- mono_native_tls_set_value (loader_error_thread_id, NULL);
- }
-}
-
-/**
- * mono_loader_error_prepare_exception:
- * @error: The MonoLoaderError to turn into an exception
- *
- * This turns a MonoLoaderError into an exception that can be thrown
- * and resets the Mono Loader Error state during this process.
- *
- */
-MonoException *
-mono_loader_error_prepare_exception (MonoLoaderError *error)
-{
- MonoException *ex = NULL;
-
- switch (error->exception_type) {
- case MONO_EXCEPTION_TYPE_LOAD: {
- char *cname = g_strdup (error->class_name);
- char *aname = g_strdup (error->assembly_name);
- MonoString *class_name;
-
- mono_loader_clear_error ();
-
- class_name = mono_string_new (mono_domain_get (), cname);
-
- ex = mono_get_exception_type_load (class_name, aname);
- g_free (cname);
- g_free (aname);
- break;
- }
- case MONO_EXCEPTION_MISSING_METHOD: {
- char *cname = g_strdup (error->class_name);
- char *aname = g_strdup (error->member_name);
-
- mono_loader_clear_error ();
- ex = mono_get_exception_missing_method (cname, aname);
- g_free (cname);
- g_free (aname);
- break;
- }
-
- case MONO_EXCEPTION_MISSING_FIELD: {
- char *class_name;
- char *cmembername = g_strdup (error->member_name);
- if (error->klass)
- class_name = mono_type_get_full_name (error->klass);
- else
- class_name = g_strdup ("");
-
- mono_loader_clear_error ();
-
- ex = mono_get_exception_missing_field (class_name, cmembername);
- g_free (class_name);
- g_free (cmembername);
- break;
- }
-
- case MONO_EXCEPTION_FILE_NOT_FOUND: {
- char *msg;
- char *filename;
-
- if (error->ref_only)
- msg = g_strdup_printf ("Cannot resolve dependency to assembly '%s' because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event.", error->assembly_name);
- else
- msg = g_strdup_printf ("Could not load file or assembly '%s' or one of its dependencies.", error->assembly_name);
- filename = g_strdup (error->assembly_name);
- /* Has to call this before calling anything which might call mono_class_init () */
- mono_loader_clear_error ();
- ex = mono_get_exception_file_not_found2 (msg, mono_string_new (mono_domain_get (), filename));
- g_free (msg);
- g_free (filename);
- break;
- }
-
- case MONO_EXCEPTION_BAD_IMAGE: {
- char *msg = g_strdup (error->msg);
- mono_loader_clear_error ();
- ex = mono_get_exception_bad_image_format (msg);
- g_free (msg);
- break;
- }
-
- default:
- g_assert_not_reached ();
- }
-
- return ex;
-}
-
/*
* find_cached_memberref_sig:
*
const char *ptr;
guint32 idx = mono_metadata_token_index (token);
- mono_error_init (error);
+ error_init (error);
mono_metadata_decode_row (&tables [MONO_TABLE_MEMBERREF], idx-1, cols, MONO_MEMBERREF_SIZE);
nindex = cols [MONO_MEMBERREF_CLASS] >> MONO_MEMBERREF_PARENT_BITS;
fname = mono_metadata_string_heap (image, cols [MONO_MEMBERREF_NAME]);
if (!mono_verifier_verify_memberref_field_signature (image, cols [MONO_MEMBERREF_SIGNATURE], NULL)) {
- mono_error_set_bad_image (error, image, "Bad field '%s' signature 0x%08x", class_index, token);
+ mono_error_set_bad_image (error, image, "Bad field '%u' signature 0x%08x", class_index, token);
return NULL;
}
klass = mono_class_get_and_inflate_typespec_checked (image, MONO_TOKEN_TYPE_SPEC | nindex, context, error);
break;
default:
- mono_error_set_bad_image (error, image, "Bad field field '%s' signature 0x%08x", class_index, token);
+ mono_error_set_bad_image (error, image, "Bad field field '%u' signature 0x%08x", class_index, token);
}
if (!klass)
field = mono_class_get_field_from_name_full (klass, fname, sig_type);
if (!field) {
- mono_loader_assert_no_error ();
mono_error_set_field_load (error, klass, fname, "Could not find field '%s'", fname);
}
guint32 type;
MonoClassField *field;
- mono_error_init (error);
+ error_init (error);
if (image_is_dynamic (image)) {
MonoClassField *result;
MonoClass *handle_class;
*retklass = NULL;
- result = (MonoClassField *)mono_lookup_dynamic_token_class (image, token, TRUE, &handle_class, context);
+ MonoError inner_error;
+ result = (MonoClassField *)mono_lookup_dynamic_token_class (image, token, TRUE, &handle_class, context, &inner_error);
+ mono_error_cleanup (&inner_error);
// This checks the memberref type as well
if (!result || handle_class != mono_defaults.fieldhandle_class) {
mono_error_set_bad_image (error, image, "Bad field token 0x%08x", token);
if (mono_metadata_token_table (token) == MONO_TABLE_MEMBERREF) {
field = field_from_memberref (image, token, retklass, context, error);
- mono_loader_assert_no_error ();
} else {
type = mono_metadata_typedef_from_field (image, mono_metadata_token_index (token));
if (!type) {
*retklass = k;
field = mono_class_get_field (k, token);
if (!field) {
- if (mono_loader_get_last_error ())
- mono_error_set_from_loader_error (error);
- else
- mono_error_set_bad_image (error, image, "Could not resolve field token 0x%08x", token);
+ mono_error_set_bad_image (error, image, "Could not resolve field token 0x%08x", token);
}
}
- if (field && field->parent && !field->parent->generic_class && !field->parent->generic_container) {
+ if (field && field->parent && !mono_class_is_ginst (field->parent) && !mono_class_is_gtd (field->parent)) {
mono_image_lock (image);
mono_conc_hashtable_insert (image->field_cache, GUINT_TO_POINTER (token), field);
mono_image_unlock (image);
}
- mono_loader_assert_no_error ();
return field;
}
int i;
/* Search directly in the metadata to avoid calling setup_methods () */
- mono_error_init (error);
+ error_init (error);
- /* FIXME: !from_class->generic_class condition causes test failures. */
- if (klass->type_token && !image_is_dynamic (klass->image) && !klass->methods && !klass->rank && klass == from_class && !from_class->generic_class) {
- for (i = 0; i < klass->method.count; ++i) {
+ /* FIXME: !mono_class_is_ginst (from_class) condition causes test failures. */
+ if (klass->type_token && !image_is_dynamic (klass->image) && !klass->methods && !klass->rank && klass == from_class && !mono_class_is_ginst (from_class)) {
+ int first_idx = mono_class_get_first_method_idx (klass);
+ int mcount = mono_class_get_method_count (klass);
+ for (i = 0; i < mcount; ++i) {
guint32 cols [MONO_METHOD_SIZE];
MonoMethod *method;
const char *m_name;
MonoMethodSignature *other_sig;
- mono_metadata_decode_table_row (klass->image, MONO_TABLE_METHOD, klass->method.first + i, cols, MONO_METHOD_SIZE);
+ mono_metadata_decode_table_row (klass->image, MONO_TABLE_METHOD, first_idx + i, cols, MONO_METHOD_SIZE);
m_name = mono_metadata_string_heap (klass->image, cols [MONO_METHOD_NAME]);
(name && !strcmp (m_name, name))))
continue;
- method = mono_get_method_checked (klass->image, MONO_TOKEN_METHOD_DEF | (klass->method.first + i + 1), klass, NULL, error);
+ method = mono_get_method_checked (klass->image, MONO_TOKEN_METHOD_DEF | (first_idx + i + 1), klass, NULL, error);
if (!mono_error_ok (error)) //bail out if we hit a loader error
return NULL;
if (method) {
return NULL;
}
- for (i = 0; i < klass->method.count; ++i) {
+ int mcount = mono_class_get_method_count (klass);
+ for (i = 0; i < mcount; ++i) {
MonoMethod *m = klass->methods [i];
MonoMethodSignature *msig;
}
}
- if (i < klass->method.count)
+ if (i < mcount)
return mono_class_get_method_by_index (from_class, i);
return NULL;
}
MonoMethod *result = NULL;
MonoClass *initial_class = in_class;
- mono_error_init (error);
+ error_init (error);
is_interface = MONO_CLASS_IS_INTERFACE (in_class);
if (ic) {
gboolean is_open;
int i;
- mono_error_init (error);
+ error_init (error);
if (!context)
return sig;
static MonoMethodHeader*
inflate_generic_header (MonoMethodHeader *header, MonoGenericContext *context, MonoError *error)
{
- MonoMethodHeader *res;
- int i;
- res = (MonoMethodHeader *)g_malloc0 (MONO_SIZEOF_METHOD_HEADER + sizeof (gpointer) * header->num_locals);
+ size_t locals_size = sizeof (gpointer) * header->num_locals;
+ size_t clauses_size = header->num_clauses * sizeof (MonoExceptionClause);
+ size_t header_size = MONO_SIZEOF_METHOD_HEADER + locals_size + clauses_size;
+ MonoMethodHeader *res = (MonoMethodHeader *)g_malloc0 (header_size);
+ res->num_locals = header->num_locals;
+ res->clauses = (MonoExceptionClause *) &res->locals [res->num_locals] ;
+ memcpy (res->clauses, header->clauses, clauses_size);
+
res->code = header->code;
res->code_size = header->code_size;
res->max_stack = header->max_stack;
res->num_clauses = header->num_clauses;
res->init_locals = header->init_locals;
- res->num_locals = header->num_locals;
- res->clauses = header->clauses;
- mono_error_init (error);
+ res->is_transient = TRUE;
- for (i = 0; i < header->num_locals; ++i) {
+ error_init (error);
+
+ for (int i = 0; i < header->num_locals; ++i) {
res->locals [i] = mono_class_inflate_generic_type_checked (header->locals [i], context, error);
if (!is_ok (error))
goto fail;
}
if (res->num_clauses) {
- res->clauses = (MonoExceptionClause *)g_memdup (header->clauses, sizeof (MonoExceptionClause) * res->num_clauses);
- for (i = 0; i < header->num_clauses; ++i) {
+ for (int i = 0; i < header->num_clauses; ++i) {
MonoExceptionClause *clause = &res->clauses [i];
if (clause->flags != MONO_EXCEPTION_CLAUSE_NONE)
continue;
MonoMethodSignature *sig;
const char *ptr;
- mono_error_init (error);
+ error_init (error);
/* !table is for wrappers: we should really assign their own token to them */
if (!table || table == MONO_TABLE_METHOD)
return mono_method_signature_checked (method, error);
}
- if (method->klass->generic_class)
+ if (mono_class_is_ginst (method->klass))
return mono_method_signature_checked (method, error);
if (image_is_dynamic (image)) {
mono_class_setup_methods (klass);
g_assert (!mono_class_has_failure (klass)); /*FIXME this should not fail, right?*/
- for (i = 0; i < klass->method.count; ++i) {
+ int mcount = mono_class_get_method_count (klass);
+ for (i = 0; i < mcount; ++i) {
MonoMethod *method = klass->methods [i];
if (strcmp (method->name, name) == 0 && sig->param_count == method->signature->param_count)
return method;
MonoMethodSignature *sig;
const char *ptr;
- mono_error_init (error);
+ error_init (error);
mono_metadata_decode_row (&tables [MONO_TABLE_MEMBERREF], idx-1, cols, 3);
nindex = cols [MONO_MEMBERREF_CLASS] >> MONO_MEMBERREF_PARENT_BITS;
type = &klass->byval_arg;
if (type->type != MONO_TYPE_ARRAY && type->type != MONO_TYPE_SZARRAY) {
- MonoClass *in_class = klass->generic_class ? klass->generic_class->container_class : klass;
+ MonoClass *in_class = mono_class_is_ginst (klass) ? mono_class_get_generic_class (klass)->container_class : klass;
method = find_method (in_class, NULL, mname, sig, klass, error);
break;
}
g_free (msig);
msig = g_string_free (s, FALSE);
- if (mono_loader_get_last_error ()) /* FIXME find_method and mono_method_search_in_array_class can leak a loader error */
- mono_error_set_from_loader_error (error);
- else
- mono_error_set_method_load (error, klass, mname, "Could not find method %s", msig);
+ mono_error_set_method_load (error, klass, mname, "Could not find method %s", msig);
g_free (msig);
}
- mono_loader_assert_no_error ();
return method;
fail:
- mono_loader_assert_no_error ();
g_assert (!mono_error_ok (error));
return NULL;
}
guint32 cols [MONO_METHODSPEC_SIZE];
guint32 token, nindex, param_count;
- mono_error_init (error);
+ error_init (error);
mono_metadata_decode_row (&tables [MONO_TABLE_METHODSPEC], idx - 1, cols, MONO_METHODSPEC_SIZE);
token = cols [MONO_METHODSPEC_METHOD];
klass = method->klass;
- if (klass->generic_class) {
+ if (mono_class_is_ginst (klass)) {
g_assert (method->is_inflated);
method = ((MonoMethodInflated *) method)->declaring;
}
- new_context.class_inst = klass->generic_class ? klass->generic_class->context.class_inst : NULL;
+ new_context.class_inst = mono_class_is_ginst (klass) ? mono_class_get_generic_class (klass)->context.class_inst : NULL;
new_context.method_inst = inst;
method = mono_class_inflate_generic_method_full_checked (method, klass, &new_context, error);
- mono_loader_assert_no_error ();
return method;
}
*/
}
if (dll_map->func && strcmp (dll_map->func, func) == 0) {
+ *rdll = dll_map->target;
*rfunc = dll_map->target_func;
break;
}
* @dll: The name of the external library, as it would be found in the DllImport declaration. If prefixed with 'i:' the matching of the library name is done without case sensitivity
* @func: if not null, the mapping will only applied to the named function (the value of EntryPoint)
* @tdll: The name of the library to map the specified @dll if it matches.
- * @tfunc: if func is not NULL, the name of the function that replaces the invocation
+ * @tfunc: The name of the function that replaces the invocation. If NULL, it is replaced with a copy of @func.
*
* LOCKING: Acquires the loader lock.
*
entry->dll = dll? g_strdup (dll): NULL;
entry->target = tdll? g_strdup (tdll): NULL;
entry->func = func? g_strdup (func): NULL;
- entry->target_func = tfunc? g_strdup (tfunc): NULL;
+ entry->target_func = tfunc? g_strdup (tfunc): (func? g_strdup (func): NULL);
global_loader_data_lock ();
entry->next = global_dll_map;
entry->dll = dll? mono_image_strdup (assembly, dll): NULL;
entry->target = tdll? mono_image_strdup (assembly, tdll): NULL;
entry->func = func? mono_image_strdup (assembly, func): NULL;
- entry->target_func = tfunc? mono_image_strdup (assembly, tfunc): NULL;
+ entry->target_func = tfunc? mono_image_strdup (assembly, tfunc): (func? mono_image_strdup (assembly, func): NULL);
mono_image_lock (assembly);
entry->next = assembly->dll_map;
return res;
}
+void
+mono_loader_register_module (const char *name, MonoDl *module)
+{
+ if (!global_module_map)
+ global_module_map = g_hash_table_new (g_str_hash, g_str_equal);
+ g_hash_table_insert (global_module_map, g_strdup (name), module);
+}
+
static MonoDl *internal_module;
static gboolean
const char *sig = NULL;
guint32 cols [MONO_TYPEDEF_SIZE];
- mono_error_init (error);
+ error_init (error);
if (image_is_dynamic (image)) {
MonoClass *handle_class;
- result = (MonoMethod *)mono_lookup_dynamic_token_class (image, token, TRUE, &handle_class, context);
- mono_loader_assert_no_error ();
+ result = (MonoMethod *)mono_lookup_dynamic_token_class (image, token, TRUE, &handle_class, context, error);
+ mono_error_assert_ok (error);
// This checks the memberref type as well
if (result && handle_class != mono_defaults.methodhandle_class) {
sig = mono_metadata_blob_heap (image, cols [4]);
/* size = */ mono_metadata_decode_blob_size (sig, &sig);
- container = klass->generic_container;
+ container = mono_class_try_get_generic_container (klass);
/*
* load_generic_params does a binary search so only call it if the method
*/
if (*sig & 0x10) {
generic_container = mono_metadata_load_generic_params (image, token, container);
- mono_loader_assert_no_error (); /* FIXME don't swallow this error. */
}
if (generic_container) {
result->is_generic = TRUE;
if (generic_container)
mono_method_set_generic_container (result, generic_container);
- mono_loader_assert_no_error ();
return result;
}
/* We do everything inside the lock to prevent creation races */
- mono_error_init (error);
+ error_init (error);
mono_image_lock (image);
MonoGenericContext *method_context = NULL;
MonoMethodSignature *sig, *original_sig;
- mono_error_init (error);
+ error_init (error);
mono_class_init (constrained_class);
original_sig = sig = mono_method_signature_checked (method, error);
MonoMethod *
mono_get_method_constrained_checked (MonoImage *image, guint32 token, MonoClass *constrained_class, MonoGenericContext *context, MonoMethod **cil_method, MonoError *error)
{
- mono_error_init (error);
+ error_init (error);
*cil_method = mono_get_method_from_token (image, token, NULL, context, NULL, error);
if (!*cil_method)
g_assert (method != NULL);
g_assert (method->wrapper_type != MONO_WRAPPER_NONE);
- if (method->is_inflated)
- method = ((MonoMethodInflated *) method)->declaring;
data = (void **)((MonoMethodWrapper *)method)->method_data;
g_assert (data != NULL);
g_assert (id <= GPOINTER_TO_UINT (*data));
AsyncStackWalkUserData ud = { func, user_data };
mono_sigctx_to_monoctx (initial_sig_context, &ctx);
- mono_get_eh_callbacks ()->mono_walk_stack_with_ctx (async_stack_walk_adapter, NULL, MONO_UNWIND_SIGNAL_SAFE, &ud);
+ mono_get_eh_callbacks ()->mono_walk_stack_with_ctx (async_stack_walk_adapter, &ctx, MONO_UNWIND_SIGNAL_SAFE, &ud);
}
static gboolean
/* We need memory barriers below because of the double-checked locking pattern */
- mono_error_init (error);
+ error_init (error);
if (m->signature)
return m->signature;
sig = mono_metadata_blob_heap (img, sig_offset = mono_metadata_decode_row_col (&img->tables [MONO_TABLE_METHOD], idx - 1, MONO_METHOD_SIGNATURE));
- g_assert (!m->klass->generic_class);
+ g_assert (!mono_class_is_ginst (m->klass));
container = mono_method_get_generic_container (m);
if (!container)
- container = m->klass->generic_container;
+ container = mono_class_try_get_generic_container (m->klass);
/* Generic signatures depend on the container so they cannot be cached */
/* icall/pinvoke signatures cannot be cached cause we modify them below */
mono_error_set_method_load (error, m->klass, m->name, "generic_params table claims method has generic parameters, but signature says it doesn't for method 0x%08x from image %s", idx, img->name);
return NULL;
}
- if (m->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL)
+ if (m->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) {
signature->pinvoke = 1;
- else if (m->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) {
+#ifdef TARGET_WIN32
+ /*
+ * On Windows the default pinvoke calling convention is STDCALL but
+ * we need CDECL since this is actually an icall.
+ */
+ signature->call_convention = MONO_CALL_C;
+#endif
+ } else if (m->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) {
MonoCallConvention conv = (MonoCallConvention)0;
MonoMethodPInvoke *piinfo = (MonoMethodPInvoke *)m;
signature->pinvoke = 1;
gpointer loc;
MonoGenericContainer *container;
- mono_error_init (error);
+ error_init (error);
img = method->klass->image;
if ((method->flags & METHOD_ATTRIBUTE_ABSTRACT) || (method->iflags & METHOD_IMPL_ATTRIBUTE_RUNTIME) || (method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) || (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)) {
return NULL;
}
- mono_image_lock (img);
-
- if (imethod->header) {
- mono_metadata_free_mh (iheader);
- mono_image_unlock (img);
- return imethod->header;
- }
-
- mono_memory_barrier ();
- imethod->header = iheader;
-
- mono_image_unlock (img);
-
- return imethod->header;
+ return iheader;
}
if (method->wrapper_type != MONO_WRAPPER_NONE || method->sre_method) {
*/
container = mono_method_get_generic_container (method);
if (!container)
- container = method->klass->generic_container;
+ container = mono_class_try_get_generic_container (method->klass);
return mono_metadata_parse_mh_full (img, container, (const char *)loc, error);
}
mono_class_setup_methods (klass);
if (mono_class_has_failure (klass))
return 0;
- for (i = 0; i < klass->method.count; ++i) {
+ int first_idx = mono_class_get_first_method_idx (klass);
+ int mcount = mono_class_get_method_count (klass);
+ for (i = 0; i < mcount; ++i) {
if (method == klass->methods [i]) {
if (klass->image->uncompressed_metadata)
- return mono_metadata_translate_token_index (klass->image, MONO_TABLE_METHOD, klass->method.first + i + 1);
+ return mono_metadata_translate_token_index (klass->image, MONO_TABLE_METHOD, first_idx + i + 1);
else
- return klass->method.first + i + 1;
+ return first_idx + i + 1;
}
}
return 0;