mono_native_tls_alloc (&loader_error_thread_id, NULL);
mono_native_tls_alloc (&loader_lock_nest_id, NULL);
+ mono_counters_init ();
mono_counters_register ("Inflated signatures size",
MONO_COUNTER_GENERICS | MONO_COUNTER_INT, &inflated_signatures_size);
mono_counters_register ("Memberref signature cache size",
static MonoClassField*
field_from_memberref (MonoImage *image, guint32 token, MonoClass **retklass,
- MonoGenericContext *context)
+ MonoGenericContext *context, MonoError *error)
{
- MonoClass *klass;
+ MonoClass *klass = NULL;
MonoClassField *field;
MonoTableInfo *tables = image->tables;
MonoType *sig_type;
guint32 cols[6];
- guint32 nindex, class, class_table;
+ guint32 nindex, class;
const char *fname;
const char *ptr;
guint32 idx = mono_metadata_token_index (token);
- MonoError error;
+
+ mono_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_loader_set_error_bad_image (g_strdup_printf ("Bad field signature class token 0x%08x field name %s token 0x%08x on image %s", class, fname, token, image->name));
+ mono_error_set_bad_image (error, image, "Bad field '%s' signature 0x%08x", class, token);
return NULL;
}
switch (class) {
case MONO_MEMBERREF_PARENT_TYPEDEF:
- class_table = MONO_TOKEN_TYPE_DEF;
- klass = mono_class_get_checked (image, MONO_TOKEN_TYPE_DEF | nindex, &error);
- if (!mono_error_ok (&error)) {
- /*FIXME don't swallow the error message*/
- mono_error_cleanup (&error);
- }
-
+ klass = mono_class_get_checked (image, MONO_TOKEN_TYPE_DEF | nindex, error);
break;
case MONO_MEMBERREF_PARENT_TYPEREF:
- class_table = MONO_TOKEN_TYPE_REF;
- klass = mono_class_from_typeref_checked (image, MONO_TOKEN_TYPE_REF | nindex, &error);
- if (!mono_error_ok (&error)) {
- /*FIXME don't swallow the error message*/
- mono_error_cleanup (&error);
- }
-
+ klass = mono_class_from_typeref_checked (image, MONO_TOKEN_TYPE_REF | nindex, error);
break;
case MONO_MEMBERREF_PARENT_TYPESPEC:
- class_table = MONO_TOKEN_TYPE_SPEC;
- klass = mono_class_get_and_inflate_typespec_checked (image, MONO_TOKEN_TYPE_SPEC | nindex, context, &error);
- if (!mono_error_ok (&error)) {
- /*FIXME don't swallow the error message*/
- mono_error_cleanup (&error);
- }
+ klass = mono_class_get_and_inflate_typespec_checked (image, MONO_TOKEN_TYPE_SPEC | nindex, context, error);
break;
default:
- /*FIXME this must set a loader error!*/
- g_warning ("field load from %x", class);
- return NULL;
+ mono_error_set_bad_image (error, image, "Bad field field '%s' signature 0x%08x", class, token);
}
- if (!klass) {
- char *name = mono_class_name_from_token (image, class_table | nindex);
- g_warning ("Missing field %s in class %s (type token %d)", fname, name, class_table | nindex);
- mono_loader_set_error_type_load (name, image->assembly_name);
- g_free (name);
+ if (!klass)
return NULL;
- }
ptr = mono_metadata_blob_heap (image, cols [MONO_MEMBERREF_SIGNATURE]);
mono_metadata_decode_blob_size (ptr, &ptr);
/* we may want to check the signature here... */
if (*ptr++ != 0x6) {
- g_warning ("Bad field signature class token %08x field name %s token %08x", class, fname, token);
- mono_loader_set_error_field_load (klass, fname);
+ mono_error_set_field_load (error, klass, fname, "Bad field signature class token %08x field name %s token %08x", class, fname, token);
return NULL;
}
+
/* FIXME: This needs a cache, especially for generic instances, since
* mono_metadata_parse_type () allocates everything from a mempool.
*/
if (!sig_type) {
sig_type = mono_metadata_parse_type (image, MONO_PARSE_TYPE, 0, ptr, &ptr);
if (sig_type == NULL) {
- mono_loader_set_error_field_load (klass, fname);
+ mono_error_set_field_load (error, klass, fname, "Could not parse field '%s' signature %08x", fname, token);
return NULL;
}
sig_type = cache_memberref_sig (image, cols [MONO_MEMBERREF_SIGNATURE], sig_type);
*retklass = klass;
field = mono_class_get_field_from_name_full (klass, fname, sig_type);
- if (!field)
- mono_loader_set_error_field_load (klass, fname);
+ if (!field) {
+ g_assert (!mono_loader_get_last_error ());
+ mono_error_set_field_load (error, klass, fname, "Could not find field '%s'", fname);
+ }
return field;
}
+/*
+ * mono_field_from_token:
+ * @deprecated use the _checked variant
+*/
MonoClassField*
-mono_field_from_token (MonoImage *image, guint32 token, MonoClass **retklass,
- MonoGenericContext *context)
+mono_field_from_token (MonoImage *image, guint32 token, MonoClass **retklass, MonoGenericContext *context)
{
MonoError error;
+ MonoClassField *res = mono_field_from_token_checked (image, token, retklass, context, &error);
+ g_assert (!mono_loader_get_last_error ());
+ if (!mono_error_ok (&error)) {
+ mono_loader_set_error_from_mono_error (&error);
+ mono_error_cleanup (&error);
+ }
+ return res;
+}
+
+MonoClassField*
+mono_field_from_token_checked (MonoImage *image, guint32 token, MonoClass **retklass, MonoGenericContext *context, MonoError *error)
+{
MonoClass *k;
guint32 type;
MonoClassField *field;
+ mono_error_init (error);
+
if (image_is_dynamic (image)) {
MonoClassField *result;
MonoClass *handle_class;
result = mono_lookup_dynamic_token_class (image, token, TRUE, &handle_class, context);
// This checks the memberref type as well
if (!result || handle_class != mono_defaults.fieldhandle_class) {
- mono_loader_set_error_bad_image (g_strdup_printf ("Bad field token 0x%08x on image %s.", token, image->name));
+ mono_error_set_bad_image (error, image, "Bad field token 0x%08x", token);
return NULL;
}
*retklass = result->parent;
return field;
}
- if (mono_metadata_token_table (token) == MONO_TABLE_MEMBERREF)
- field = field_from_memberref (image, token, retklass, context);
- else {
+ if (mono_metadata_token_table (token) == MONO_TABLE_MEMBERREF) {
+ field = field_from_memberref (image, token, retklass, context, error);
+ g_assert (!mono_loader_get_last_error ());
+ } else {
type = mono_metadata_typedef_from_field (image, mono_metadata_token_index (token));
- if (!type)
- return NULL;
- k = mono_class_get_checked (image, MONO_TOKEN_TYPE_DEF | type, &error);
- if (!k) {
- mono_loader_set_error_from_mono_error (&error);
- mono_error_cleanup (&error); /*FIXME don't swallow the error message*/
+ if (!type) {
+ mono_error_set_bad_image (error, image, "Invalid field token 0x%08x", token);
return NULL;
}
+ k = mono_class_get_checked (image, MONO_TOKEN_TYPE_DEF | type, error);
+ if (!k)
+ return NULL;
+
mono_class_init (k);
if (retklass)
*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);
+ }
}
if (field && field->parent && !field->parent->generic_class && !field->parent->generic_container)
mono_conc_hashtable_insert (image->field_cache, GUINT_TO_POINTER (token), field);
+ g_assert (!mono_loader_get_last_error ());
return field;
}
static MonoMethod *
find_method_in_class (MonoClass *klass, const char *name, const char *qname, const char *fqname,
- MonoMethodSignature *sig, MonoClass *from_class)
+ MonoMethodSignature *sig, MonoClass *from_class, MonoError *error)
{
int i;
/* Search directly in the metadata to avoid calling setup_methods () */
+ mono_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) {
(name && !strcmp (m_name, name))))
continue;
- method = mono_get_method (klass->image, MONO_TOKEN_METHOD_DEF | (klass->method.first + i + 1), klass);
+ method = mono_get_method_checked (klass->image, MONO_TOKEN_METHOD_DEF | (klass->method.first + i + 1), klass, NULL, error);
+ if (!mono_error_ok (error)) //bail out if we hit a loader error
+ return NULL;
if (method) {
- other_sig = mono_method_signature (method);
+ other_sig = mono_method_signature_checked (method, error);
+ if (!mono_error_ok (error)) //bail out if we hit a loader error
+ return NULL;
if (other_sig && (sig->call_convention != MONO_CALL_VARARG) && mono_metadata_signature_equal (sig, other_sig))
return method;
}
}
}
- mono_class_setup_methods (klass);
+ mono_class_setup_methods (klass); /* FIXME don't swallow the error here. */
/*
We can't fail lookup of methods otherwise the runtime will fail with MissingMethodException instead of TypeLoadException.
See mono/tests/generic-type-load-exception.2.il
FIXME we should better report this error to the caller
*/
- if (!klass->methods)
+ if (!klass->methods || klass->exception_type) {
+ mono_error_set_type_load_class (error, klass, "Could not find method due to a type load error"); //FIXME get the error from the class
+
return NULL;
+ }
for (i = 0; i < klass->method.count; ++i) {
MonoMethod *m = klass->methods [i];
MonoMethodSignature *msig;
(qname && !strcmp (m->name, qname)) ||
(name && !strcmp (m->name, name))))
continue;
- msig = mono_method_signature (m);
+ msig = mono_method_signature_checked (m, error);
+ if (!mono_error_ok (error)) //bail out if we hit a loader error
+ return NULL;
+
if (!msig)
continue;
}
static MonoMethod *
-find_method (MonoClass *in_class, MonoClass *ic, const char* name, MonoMethodSignature *sig, MonoClass *from_class)
+find_method (MonoClass *in_class, MonoClass *ic, const char* name, MonoMethodSignature *sig, MonoClass *from_class, MonoError *error)
{
int i;
char *qname, *fqname, *class_name;
gboolean is_interface;
MonoMethod *result = NULL;
+ MonoClass *initial_class = in_class;
+ mono_error_init (error);
is_interface = MONO_CLASS_IS_INTERFACE (in_class);
if (ic) {
while (in_class) {
g_assert (from_class);
- result = find_method_in_class (in_class, name, qname, fqname, sig, from_class);
- if (result)
+ result = find_method_in_class (in_class, name, qname, fqname, sig, from_class, error);
+ if (result || !mono_error_ok (error))
goto out;
if (name [0] == '.' && (!strcmp (name, ".ctor") || !strcmp (name, ".cctor")))
else
ic_fqname = NULL;
- result = find_method_in_class (in_ic, ic ? name : NULL, ic_qname, ic_fqname, sig, from_ic);
+ result = find_method_in_class (in_ic, ic ? name : NULL, ic_qname, ic_fqname, sig, from_ic, error);
g_free (ic_class_name);
g_free (ic_fqname);
g_free (ic_qname);
- if (result)
+ if (result || !mono_error_ok (error))
goto out;
}
g_assert (!in_class == !from_class);
if (is_interface)
- result = find_method_in_class (mono_defaults.object_class, name, qname, fqname, sig, mono_defaults.object_class);
+ result = find_method_in_class (mono_defaults.object_class, name, qname, fqname, sig, mono_defaults.object_class, error);
+ //we did not find the method
+ if (!result && mono_error_ok (error)) {
+ char *desc = mono_signature_get_desc (sig, FALSE);
+ mono_error_set_method_load (error, initial_class, name, "Could not find method with signature %s", desc);
+ g_free (desc);
+ }
+
out:
g_free (class_name);
g_free (fqname);
*/
MonoMethodSignature*
mono_method_get_signature_full (MonoMethod *method, MonoImage *image, guint32 token, MonoGenericContext *context)
+{
+ MonoError error;
+ MonoMethodSignature *res = mono_method_get_signature_checked (method, image, token, context, &error);
+
+ g_assert (!mono_loader_get_last_error ());
+
+ if (!res) {
+ g_assert (!mono_error_ok (&error));
+ mono_loader_set_error_from_mono_error (&error);
+ mono_error_cleanup (&error); /* FIXME Don't swallow the error */
+ }
+ return res;
+}
+
+MonoMethodSignature*
+mono_method_get_signature_checked (MonoMethod *method, MonoImage *image, guint32 token, MonoGenericContext *context, MonoError *error)
{
int table = mono_metadata_token_table (token);
int idx = mono_metadata_token_index (token);
MonoMethodSignature *sig;
const char *ptr;
+ mono_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 (method);
+ return mono_method_signature_checked (method, error);
if (table == MONO_TABLE_METHODSPEC) {
/* the verifier (do_invoke_method) will turn the NULL into a verifier error */
if ((method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) || !method->is_inflated)
return NULL;
- return mono_method_signature (method);
+ return mono_method_signature_checked (method, error);
}
if (method->klass->generic_class)
- return mono_method_signature (method);
+ return mono_method_signature_checked (method, error);
if (image_is_dynamic (image)) {
- sig = mono_reflection_lookup_signature (image, method, token);
+ sig = mono_reflection_lookup_signature (image, method, token, error);
+ if (!sig)
+ return NULL;
} else {
mono_metadata_decode_row (&image->tables [MONO_TABLE_MEMBERREF], idx-1, cols, MONO_MEMBERREF_SIZE);
sig_idx = cols [MONO_MEMBERREF_SIGNATURE];
guint32 class = cols [MONO_MEMBERREF_CLASS] & MONO_MEMBERREF_PARENT_MASK;
const char *fname = mono_metadata_string_heap (image, cols [MONO_MEMBERREF_NAME]);
- mono_loader_set_error_bad_image (g_strdup_printf ("Bad method signature class token 0x%08x field name %s token 0x%08x on image %s", class, fname, token, image->name));
+ //FIXME include the verification error
+ mono_error_set_bad_image (error, image, "Bad method signature class token 0x%08x field name %s token 0x%08x", class, fname, token);
return NULL;
}
ptr = mono_metadata_blob_heap (image, sig_idx);
mono_metadata_decode_blob_size (ptr, &ptr);
- sig = mono_metadata_parse_method_signature (image, 0, ptr, NULL);
+
+ sig = mono_metadata_parse_method_signature_full (image, NULL, 0, ptr, NULL, error);
if (!sig)
return NULL;
+
sig = cache_memberref_sig (image, sig_idx, sig);
}
/* FIXME: we probably should verify signature compat in the dynamic case too*/
guint32 class = cols [MONO_MEMBERREF_CLASS] & MONO_MEMBERREF_PARENT_MASK;
const char *fname = mono_metadata_string_heap (image, cols [MONO_MEMBERREF_NAME]);
- mono_loader_set_error_bad_image (g_strdup_printf ("Incompatible method signature class token 0x%08x field name %s token 0x%08x on image %s", class, fname, token, image->name));
+ mono_error_set_bad_image (error, image, "Incompatible method signature class token 0x%08x field name %s token 0x%08x", class, fname, token);
return NULL;
}
}
if (context) {
- MonoError error;
MonoMethodSignature *cached;
/* This signature is not owned by a MonoMethod, so need to cache */
- sig = inflate_generic_signature_checked (image, sig, context, &error);
- if (!mono_error_ok (&error)) {/*XXX bubble up this and kill one use of loader errors */
- mono_loader_set_error_bad_image (g_strdup_printf ("Could not inflate signature %s", mono_error_get_message (&error)));
- mono_error_cleanup (&error);
+ sig = inflate_generic_signature_checked (image, sig, context, error);
+ if (!mono_error_ok (error))
return NULL;
- }
cached = mono_metadata_get_inflated_signature (sig, context);
if (cached != sig)
sig = cached;
}
+ g_assert (mono_error_ok (error));
return sig;
}
MonoMethodSignature*
mono_method_get_signature (MonoMethod *method, MonoImage *image, guint32 token)
{
- return mono_method_get_signature_full (method, image, token, NULL);
+ MonoError error;
+ MonoMethodSignature *res = mono_method_get_signature_checked (method, image, token, NULL, &error);
+
+ g_assert (!mono_loader_get_last_error ());
+
+ if (!res) {
+ g_assert (!mono_error_ok (&error));
+ mono_loader_set_error_from_mono_error (&error);
+ mono_error_cleanup (&error); /* FIXME Don't swallow the error */
+ }
+ return res;
}
/* this is only for the typespec array methods */
static MonoMethod *
method_from_memberref (MonoImage *image, guint32 idx, MonoGenericContext *typespec_context,
- gboolean *used_context)
+ gboolean *used_context, MonoError *error)
{
MonoClass *klass = NULL;
MonoMethod *method = NULL;
const char *mname;
MonoMethodSignature *sig;
const char *ptr;
- MonoError error;
+
+ mono_error_init (error);
mono_metadata_decode_row (&tables [MONO_TABLE_MEMBERREF], idx-1, cols, 3);
nindex = cols [MONO_MEMBERREF_CLASS] >> MONO_MEMBERREF_PARENT_BITS;
switch (class) {
case MONO_MEMBERREF_PARENT_TYPEREF:
- klass = mono_class_from_typeref_checked (image, MONO_TOKEN_TYPE_REF | nindex, &error);
- if (!klass) {
- mono_loader_set_error_from_mono_error (&error);
- mono_error_cleanup (&error); /* FIXME Don't swallow the error */
- return NULL;
- }
+ klass = mono_class_from_typeref_checked (image, MONO_TOKEN_TYPE_REF | nindex, error);
+ if (!klass)
+ goto fail;
break;
case MONO_MEMBERREF_PARENT_TYPESPEC:
/*
* Parse the TYPESPEC in the parent's context.
*/
- klass = mono_class_get_and_inflate_typespec_checked (image, MONO_TOKEN_TYPE_SPEC | nindex, typespec_context, &error);
- if (!klass) {
- mono_loader_set_error_from_mono_error (&error);
- mono_error_cleanup (&error); /*FIXME don't swallow the error message*/
- return NULL;
- }
+ klass = mono_class_get_and_inflate_typespec_checked (image, MONO_TOKEN_TYPE_SPEC | nindex, typespec_context, error);
+ if (!klass)
+ goto fail;
break;
case MONO_MEMBERREF_PARENT_TYPEDEF:
- klass = mono_class_get_checked (image, MONO_TOKEN_TYPE_DEF | nindex, &error);
- if (!klass) {
- mono_loader_set_error_from_mono_error (&error);
- mono_error_cleanup (&error); /*FIXME don't swallow the error message*/
- return NULL;
- }
+ klass = mono_class_get_checked (image, MONO_TOKEN_TYPE_DEF | nindex, error);
+ if (!klass)
+ goto fail;
break;
- case MONO_MEMBERREF_PARENT_METHODDEF:
- return mono_get_method (image, MONO_TOKEN_METHOD_DEF | nindex, NULL);
-
+ case MONO_MEMBERREF_PARENT_METHODDEF: {
+ method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | nindex, NULL, NULL, error);
+ if (!method)
+ goto fail;
+ return method;
+ }
default:
- {
- /* This message leaks */
- char *message = g_strdup_printf ("Memberref parent unknown: class: %d, index %d", class, nindex);
- mono_loader_set_error_method_load ("", message);
- return NULL;
- }
-
+ mono_error_set_bad_image (error, image, "Memberref parent unknown: class: %d, index %d", class, nindex);
+ goto fail;
}
+
g_assert (klass);
mono_class_init (klass);
sig_idx = cols [MONO_MEMBERREF_SIGNATURE];
if (!mono_verifier_verify_memberref_method_signature (image, sig_idx, NULL)) {
- mono_loader_set_error_method_load (klass->name, mname);
- return NULL;
+ mono_error_set_method_load (error, klass, mname, "Verifier rejected method signature");
+ goto fail;
}
ptr = mono_metadata_blob_heap (image, sig_idx);
sig = find_cached_memberref_sig (image, sig_idx);
if (!sig) {
- sig = mono_metadata_parse_method_signature (image, 0, ptr, NULL);
+ sig = mono_metadata_parse_method_signature_full (image, NULL, 0, ptr, NULL, error);
if (sig == NULL)
- return NULL;
+ goto fail;
sig = cache_memberref_sig (image, sig_idx, sig);
}
switch (class) {
case MONO_MEMBERREF_PARENT_TYPEREF:
case MONO_MEMBERREF_PARENT_TYPEDEF:
- method = find_method (klass, NULL, mname, sig, klass);
+ method = find_method (klass, NULL, mname, sig, klass, error);
break;
case MONO_MEMBERREF_PARENT_TYPESPEC: {
if (type->type != MONO_TYPE_ARRAY && type->type != MONO_TYPE_SZARRAY) {
MonoClass *in_class = klass->generic_class ? klass->generic_class->container_class : klass;
- method = find_method (in_class, NULL, mname, sig, klass);
+ method = find_method (in_class, NULL, mname, sig, klass, error);
break;
}
break;
}
default:
- g_error ("Memberref parent unknown: class: %d, index %d", class, nindex);
- g_assert_not_reached ();
+ mono_error_set_bad_image (error, image,"Memberref parent unknown: class: %d, index %d", class, nindex);
+ goto fail;
}
- if (!method) {
+ if (!method && mono_error_ok (error)) {
char *msig = mono_signature_get_desc (sig, FALSE);
- char * class_name = mono_type_get_name (&klass->byval_arg);
GString *s = g_string_new (mname);
if (sig->generic_param_count)
g_string_append_printf (s, "<[%d]>", sig->generic_param_count);
g_free (msig);
msig = g_string_free (s, FALSE);
- g_warning (
- "Missing method %s::%s in assembly %s, referenced in assembly %s",
- class_name, msig, klass->image->name, image->name);
- mono_loader_set_error_method_load (class_name, mname);
+ 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);
+
g_free (msig);
- g_free (class_name);
}
+ g_assert (!mono_loader_get_last_error ());
return method;
+
+fail:
+ g_assert (!mono_loader_get_last_error ());
+ g_assert (!mono_error_ok (error));
+ return NULL;
}
static MonoMethod *
-method_from_methodspec (MonoImage *image, MonoGenericContext *context, guint32 idx)
+method_from_methodspec (MonoImage *image, MonoGenericContext *context, guint32 idx, MonoError *error)
{
- MonoError error;
MonoMethod *method;
MonoClass *klass;
MonoTableInfo *tables = image->tables;
guint32 cols [MONO_METHODSPEC_SIZE];
guint32 token, nindex, param_count;
+ mono_error_init (error);
+
mono_metadata_decode_row (&tables [MONO_TABLE_METHODSPEC], idx - 1, cols, MONO_METHODSPEC_SIZE);
token = cols [MONO_METHODSPEC_METHOD];
nindex = token >> MONO_METHODDEFORREF_BITS;
- if (!mono_verifier_verify_methodspec_signature (image, cols [MONO_METHODSPEC_SIGNATURE], NULL))
+ if (!mono_verifier_verify_methodspec_signature (image, cols [MONO_METHODSPEC_SIGNATURE], NULL)) {
+ mono_error_set_bad_image (error, image, "Bad method signals signature 0x%08x", idx);
return NULL;
+ }
ptr = mono_metadata_blob_heap (image, cols [MONO_METHODSPEC_SIGNATURE]);
param_count = mono_metadata_decode_value (ptr, &ptr);
inst = mono_metadata_parse_generic_inst (image, NULL, param_count, ptr, &ptr);
- if (!inst)
+ if (!inst) {
+ g_assert (!mono_loader_get_last_error ());
+ mono_error_set_bad_image (error, image, "Cannot parse generic instance for methodspec 0x%08x", idx);
return NULL;
+ }
if (context && inst->is_open) {
- inst = mono_metadata_inflate_generic_inst (inst, context, &error);
- if (!mono_error_ok (&error)) {
- mono_error_cleanup (&error); /*FIXME don't swallow error message.*/
+ inst = mono_metadata_inflate_generic_inst (inst, context, error);
+ if (!mono_error_ok (error))
return NULL;
- }
}
- if ((token & MONO_METHODDEFORREF_MASK) == MONO_METHODDEFORREF_METHODDEF)
- method = mono_get_method_full (image, MONO_TOKEN_METHOD_DEF | nindex, NULL, context);
- else
- method = method_from_memberref (image, nindex, context, NULL);
+ if ((token & MONO_METHODDEFORREF_MASK) == MONO_METHODDEFORREF_METHODDEF) {
+ method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | nindex, NULL, context, error);
+ if (!method)
+ return NULL;
+ } else {
+ method = method_from_memberref (image, nindex, context, NULL, error);
+ }
if (!method)
return NULL;
new_context.class_inst = klass->generic_class ? klass->generic_class->context.class_inst : NULL;
new_context.method_inst = inst;
- return mono_class_inflate_generic_method_full (method, klass, &new_context);
+ method = mono_class_inflate_generic_method_full_checked (method, klass, &new_context, error);
+ g_assert (!mono_loader_get_last_error ());
+ return method;
}
struct _MonoDllMap {
"Probing '%s'.", mangled_name2);
error_msg = mono_dl_symbol (module, mangled_name2, &piinfo->addr);
- g_free (error_msg);
- error_msg = NULL;
if (piinfo->addr)
mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_DLLIMPORT,
"Found as '%s'.", mangled_name2);
+ else
+ mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_DLLIMPORT,
+ "Could not find '%s' due to '%s'.", mangled_name2, error_msg);
+
+ g_free (error_msg);
+ error_msg = NULL;
if (mangled_name != mangled_name2)
g_free (mangled_name2);
*/
static MonoMethod *
mono_get_method_from_token (MonoImage *image, guint32 token, MonoClass *klass,
- MonoGenericContext *context, gboolean *used_context)
+ MonoGenericContext *context, gboolean *used_context, MonoError *error)
{
- MonoError error;
MonoMethod *result;
int table = mono_metadata_token_table (token);
int idx = mono_metadata_token_index (token);
MonoTableInfo *tables = image->tables;
MonoGenericContainer *generic_container = NULL, *container = NULL;
const char *sig = NULL;
- int size;
guint32 cols [MONO_TYPEDEF_SIZE];
+ mono_error_init (error);
+
if (image_is_dynamic (image)) {
MonoClass *handle_class;
result = mono_lookup_dynamic_token_class (image, token, TRUE, &handle_class, context);
+ g_assert (!mono_loader_get_last_error ());
+
// This checks the memberref type as well
if (result && handle_class != mono_defaults.methodhandle_class) {
- mono_loader_set_error_bad_image (g_strdup_printf ("Bad method token 0x%08x on image %s.", token, image->name));
+ mono_error_set_bad_image (error, image, "Bad method token 0x%08x on dynamic image", token);
return NULL;
}
return result;
if (table != MONO_TABLE_METHOD) {
if (table == MONO_TABLE_METHODSPEC) {
if (used_context) *used_context = TRUE;
- return method_from_methodspec (image, context, idx);
+ return method_from_methodspec (image, context, idx, error);
}
if (table != MONO_TABLE_MEMBERREF) {
- g_warning ("got wrong token: 0x%08x\n", token);
- mono_loader_set_error_bad_image (g_strdup_printf ("Bad method token 0x%08x on image %s.", token, image->name));
+ mono_error_set_bad_image (error, image, "Bad method token 0x%08x.", token);
return NULL;
}
- return method_from_memberref (image, idx, context, used_context);
+ return method_from_memberref (image, idx, context, used_context, error);
}
if (used_context) *used_context = FALSE;
if (idx > image->tables [MONO_TABLE_METHOD].rows) {
- mono_loader_set_error_bad_image (g_strdup_printf ("Bad method token 0x%08x on image %s.", token, image->name));
+ mono_error_set_bad_image (error, image, "Bad method token 0x%08x (out of bounds).", token);
return NULL;
}
if (!klass) {
guint32 type = mono_metadata_typedef_from_method (image, token);
- if (!type)
- return NULL;
- klass = mono_class_get_checked (image, MONO_TOKEN_TYPE_DEF | type, &error);
- if (klass == NULL) {
- mono_loader_set_error_from_mono_error (&error);
- mono_error_cleanup (&error); /*FIXME don't swallow the error message*/
+ if (!type) {
+ mono_error_set_bad_image (error, image, "Bad method token 0x%08x (could not find corresponding typedef).", token);
return NULL;
}
+ klass = mono_class_get_checked (image, MONO_TOKEN_TYPE_DEF | type, error);
+ if (klass == NULL)
+ return NULL;
}
mono_metadata_decode_row (&image->tables [MONO_TABLE_METHOD], idx - 1, cols, 6);
if (!sig) /* already taken from the methodref */
sig = mono_metadata_blob_heap (image, cols [4]);
- size = mono_metadata_decode_blob_size (sig, &sig);
+ /* size = */ mono_metadata_decode_blob_size (sig, &sig);
container = klass->generic_container;
* load_generic_params does a binary search so only call it if the method
* is generic.
*/
- if (*sig & 0x10)
+ if (*sig & 0x10) {
generic_container = mono_metadata_load_generic_params (image, token, container);
+ g_assert (!mono_loader_get_last_error ()); /* FIXME don't swallow this error. */
+ }
if (generic_container) {
- MonoError error;
result->is_generic = TRUE;
generic_container->owner.method = result;
/*FIXME put this before the image alloc*/
- if (!mono_metadata_load_generic_param_constraints_checked (image, token, generic_container, &error)) {
- mono_loader_set_error_from_mono_error (&error);
- mono_error_cleanup (&error); /*FIXME don't swallow the error message*/
+ if (!mono_metadata_load_generic_param_constraints_checked (image, token, generic_container, error))
return NULL;
- }
container = generic_container;
}
if (generic_container)
mono_method_set_generic_container (result, generic_container);
+ g_assert (!mono_loader_get_last_error ());
return result;
}
MonoMethod *
mono_get_method_full (MonoImage *image, guint32 token, MonoClass *klass,
MonoGenericContext *context)
+{
+ MonoError error;
+ MonoMethod *result = mono_get_method_checked (image, token, klass, context, &error);
+ g_assert (!mono_loader_get_last_error ());
+ if (!mono_error_ok (&error)) {
+ mono_loader_set_error_from_mono_error (&error);
+ mono_error_cleanup (&error);
+ }
+ return result;
+}
+
+MonoMethod *
+mono_get_method_checked (MonoImage *image, guint32 token, MonoClass *klass, MonoGenericContext *context, MonoError *error)
{
MonoMethod *result = NULL;
gboolean used_context = FALSE;
/* We do everything inside the lock to prevent creation races */
+ mono_error_init (error);
+
mono_image_lock (image);
if (mono_metadata_token_table (token) == MONO_TABLE_METHOD) {
return result;
- result = mono_get_method_from_token (image, token, klass, context, &used_context);
+ result = mono_get_method_from_token (image, token, klass, context, &used_context, error);
if (!result)
return NULL;
}
static MonoMethod *
-get_method_constrained (MonoImage *image, MonoMethod *method, MonoClass *constrained_class, MonoGenericContext *context)
+get_method_constrained (MonoImage *image, MonoMethod *method, MonoClass *constrained_class, MonoGenericContext *context, MonoError *error)
{
MonoMethod *result;
MonoClass *ic = NULL;
MonoGenericContext *method_context = NULL;
MonoMethodSignature *sig, *original_sig;
+ mono_error_init (error);
+
mono_class_init (constrained_class);
- original_sig = sig = mono_method_signature (method);
+ original_sig = sig = mono_method_signature_checked (method, error);
if (sig == NULL) {
return NULL;
}
if (method->is_inflated && sig->generic_param_count) {
MonoMethodInflated *imethod = (MonoMethodInflated *) method;
- sig = mono_method_signature (imethod->declaring); /*We assume that if the inflated method signature is valid, the declaring method is too*/
+ sig = mono_method_signature_checked (imethod->declaring, error); /*We assume that if the inflated method signature is valid, the declaring method is too*/
+ if (!sig)
+ return NULL;
method_context = mono_method_get_context (method);
original_sig = sig;
* any type argument which a concrete type. See #325283.
*/
if (method_context->class_inst) {
- MonoError error;
MonoGenericContext ctx;
ctx.method_inst = NULL;
ctx.class_inst = method_context->class_inst;
/*Fixme, property propagate this error*/
- sig = inflate_generic_signature_checked (method->klass->image, sig, &ctx, &error);
- if (!mono_error_ok (&error)) {
- mono_error_cleanup (&error);
+ sig = inflate_generic_signature_checked (method->klass->image, sig, &ctx, error);
+ if (!sig)
return NULL;
- }
}
}
if ((constrained_class != method->klass) && (MONO_CLASS_IS_INTERFACE (method->klass)))
ic = method->klass;
- result = find_method (constrained_class, ic, method->name, sig, constrained_class);
+ result = find_method (constrained_class, ic, method->name, sig, constrained_class, error);
if (sig != original_sig)
mono_metadata_free_inflated_signature (sig);
- if (!result) {
- char *m = mono_method_full_name (method, 1);
- g_warning ("Missing method %s.%s.%s in assembly %s method %s", method->klass->name_space,
- method->klass->name, method->name, image->name, m);
- g_free (m);
+ if (!result)
return NULL;
- }
- if (method_context)
- result = mono_class_inflate_generic_method (result, method_context);
+ if (method_context) {
+ result = mono_class_inflate_generic_method_checked (result, method_context, error);
+ if (!result)
+ return NULL;
+ }
return result;
}
MonoMethod *
mono_get_method_constrained_with_method (MonoImage *image, MonoMethod *method, MonoClass *constrained_class,
- MonoGenericContext *context)
+ MonoGenericContext *context, MonoError *error)
{
g_assert (method);
- return get_method_constrained (image, method, constrained_class, context);
+ return get_method_constrained (image, method, constrained_class, context, error);
}
/**
mono_get_method_constrained (MonoImage *image, guint32 token, MonoClass *constrained_class,
MonoGenericContext *context, MonoMethod **cil_method)
{
- MonoMethod *result;
+ MonoError error;
+ MonoMethod *result = mono_get_method_constrained_checked (image, token, constrained_class, context, cil_method, &error);
+
+ g_assert (!mono_loader_get_last_error ());
+ if (!mono_error_ok (&error)) {
+ mono_loader_set_error_from_mono_error (&error);
+ mono_error_cleanup (&error);
+ }
+ return result;
+}
- *cil_method = mono_get_method_from_token (image, token, NULL, context, NULL);
+MonoMethod *
+mono_get_method_constrained_checked (MonoImage *image, guint32 token, MonoClass *constrained_class, MonoGenericContext *context, MonoMethod **cil_method, MonoError *error)
+{
+ mono_error_init (error);
+
+ *cil_method = mono_get_method_from_token (image, token, NULL, context, NULL, error);
if (!*cil_method)
return NULL;
- result = get_method_constrained (image, *cil_method, constrained_class, context);
-
- return result;
+ return get_method_constrained (image, *cil_method, constrained_class, context, error);
}
void
void
mono_loader_lock (void)
{
+ MONO_TRY_BLOCKING
mono_locks_acquire (&loader_mutex, LoaderLock);
+ MONO_FINISH_TRY_BLOCKING
+
if (G_UNLIKELY (loader_lock_track_ownership)) {
mono_native_tls_set_value (loader_lock_nest_id, GUINT_TO_POINTER (GPOINTER_TO_UINT (mono_native_tls_get_value (loader_lock_nest_id)) + 1));
}
mono_method_signature_checked (MonoMethod *m, MonoError *error)
{
int idx;
- int size;
MonoImage* img;
const char *sig;
gboolean can_cache_signature;
if (!mono_verifier_verify_method_signature (img, sig_offset, error))
return NULL;
- size = mono_metadata_decode_blob_size (sig, &sig_body);
+ /* size = */ mono_metadata_decode_blob_size (sig, &sig_body);
- signature = mono_metadata_parse_method_signature_full (img, container, idx, sig_body, NULL);
- if (!signature) {
- mono_error_set_from_loader_error (error);
+ signature = mono_metadata_parse_method_signature_full (img, container, idx, sig_body, NULL, error);
+ if (!signature)
return NULL;
- }
if (can_cache_signature) {
mono_image_lock (img);