* Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
* Copyright 2004-2009 Novell, Inc (http://www.novell.com)
* Copyright 2011 Rodrigo Kumpera
+ * Licensed under the MIT license. See LICENSE file in the project root for full license information.
*/
#include <config.h>
#include <mono/metadata/object-internals.h>
+#include <mono/metadata/dynamic-image-internals.h>
#include <mono/metadata/verify.h>
#include <mono/metadata/verify-internals.h>
#include <mono/metadata/opcodes.h>
token_bounds_check (MonoImage *image, guint32 token)
{
if (image_is_dynamic (image))
- return mono_reflection_is_valid_dynamic_token ((MonoDynamicImage*)image, token);
+ return mono_dynamic_image_is_valid_token ((MonoDynamicImage*)image, token);
return image->tables [mono_metadata_token_table (token)].rows >= mono_metadata_token_index (token) && mono_metadata_token_index (token) > 0;
}
return FALSE;
/*it's not safe to call mono_class_init from here*/
- if (paramClass->generic_class && !paramClass->inited) {
+ if (mono_class_is_ginst (paramClass) && !paramClass->inited) {
if (!mono_class_is_valid_generic_instantiation (NULL, paramClass))
return FALSE;
}
if (type->type == MONO_TYPE_VAR) {
MonoClass *gtd = method->klass;
- if (gtd->generic_class)
- gtd = gtd->generic_class->container_class;
+ if (mono_class_is_ginst (gtd))
+ gtd = mono_class_get_generic_class (gtd)->container_class;
gc = gtd->generic_container;
} else { //MVAR
MonoMethod *gmd = method;
static gboolean
mono_class_repect_method_constraints (VerifyContext *ctx, MonoClass *klass)
{
- MonoGenericClass *gklass = klass->generic_class;
+ MonoGenericClass *gklass = mono_class_get_generic_class (klass);
MonoGenericInst *ginst = gklass->context.class_inst;
MonoGenericContainer *gc = gklass->container_class->generic_container;
return !gc || generic_arguments_respect_constraints (ctx, gc, &gklass->context, ginst);
static gboolean
mono_class_is_valid_generic_instantiation (VerifyContext *ctx, MonoClass *klass)
{
- MonoGenericClass *gklass = klass->generic_class;
+ MonoGenericClass *gklass = mono_class_get_generic_class (klass);
MonoGenericInst *ginst = gklass->context.class_inst;
MonoGenericContainer *gc = gklass->container_class->generic_container;
if (ctx && !is_valid_generic_instantiation_in_context (ctx, ginst, TRUE))
klass = mono_class_from_mono_type (type);
mono_class_init (klass);
- if (mono_loader_get_last_error () || mono_class_has_failure (klass)) {
- if (klass->generic_class && !mono_class_is_valid_generic_instantiation (NULL, klass))
+ if (mono_class_has_failure (klass)) {
+ if (mono_class_is_ginst (klass) && !mono_class_is_valid_generic_instantiation (NULL, klass))
ADD_VERIFY_ERROR2 (ctx, g_strdup_printf ("Invalid generic instantiation of type %s.%s at 0x%04x", klass->name_space, klass->name, ctx->ip_offset), MONO_EXCEPTION_TYPE_LOAD);
else
ADD_VERIFY_ERROR2 (ctx, g_strdup_printf ("Could not load type %s.%s at 0x%04x", klass->name_space, klass->name, ctx->ip_offset), MONO_EXCEPTION_TYPE_LOAD);
- mono_loader_clear_error ();
return FALSE;
}
- if (klass->generic_class && mono_class_has_failure (klass->generic_class->container_class)) {
+ if (mono_class_is_ginst (klass) && mono_class_has_failure (mono_class_get_generic_class (klass)->container_class)) {
ADD_VERIFY_ERROR2 (ctx, g_strdup_printf ("Could not load type %s.%s at 0x%04x", klass->name_space, klass->name, ctx->ip_offset), MONO_EXCEPTION_TYPE_LOAD);
return FALSE;
}
- if (!klass->generic_class)
+ if (!mono_class_is_ginst (klass))
return TRUE;
if (!mono_class_is_valid_generic_instantiation (ctx, klass)) {
mono_error_cleanup (&error); /*FIXME don't swallow the error */
}
- if (!type || mono_loader_get_last_error ()) {
+ if (!type) {
ADD_VERIFY_ERROR2 (ctx, g_strdup_printf ("Cannot load type from token 0x%08x for %s at 0x%04x", token, opcode, ctx->ip_offset), MONO_EXCEPTION_BAD_IMAGE);
- mono_loader_clear_error ();
return NULL;
}
if (mono_class_is_assignable_from (target, candidate))
return TRUE;
- if (!MONO_CLASS_IS_INTERFACE (target) || !target->generic_class || candidate->rank != 1)
+ if (!MONO_CLASS_IS_INTERFACE (target) || !mono_class_is_ginst (target) || candidate->rank != 1)
return FALSE;
- iface_gtd = target->generic_class->container_class;
+ iface_gtd = mono_class_get_generic_class (target)->container_class;
if (iface_gtd != mono_defaults.generic_ilist_class && iface_gtd != get_icollection_class () && iface_gtd != get_ienumerable_class ())
return FALSE;
- target = mono_class_from_mono_type (target->generic_class->context.class_inst->type_argv [0]);
+ target = mono_class_from_mono_type (mono_class_get_generic_class (target)->context.class_inst->type_argv [0]);
candidate = candidate->element_class;
return TRUE;
CODE_NOT_VERIFIABLE (ctx, g_strdup_printf ("This object not compatible with function pointer for delegate creation at 0x%04x", ctx->ip_offset));
} else {
if (method->flags & METHOD_ATTRIBUTE_STATIC) {
- if (!stack_slot_is_null_literal (value) && !is_first_arg_bound)
+ if (!stack_slot_is_null_literal (value))
CODE_NOT_VERIFIABLE (ctx, g_strdup_printf ("Non-null this args used with static function for delegate creation at 0x%04x", ctx->ip_offset));
} else {
if (!verify_stack_type_compatibility_full (ctx, &method->klass->byval_arg, value, FALSE, TRUE) && !stack_slot_is_null_literal (value))
finish_collect_stats ();
return ctx.list;
}
- if (!method->is_generic && !method->klass->is_generic && ctx.signature->has_type_parameters) {
+ if (!method->is_generic && !mono_class_is_gtd (method->klass) && ctx.signature->has_type_parameters) {
ADD_VERIFY_ERROR (&ctx, g_strdup_printf ("Method and signature don't match in terms of genericity"));
finish_collect_stats ();
return ctx.list;
if (mono_type_is_generic_argument (constraint_type) && !recursive_mark_constraint_args (used_args, gc, constraint_type))
goto fail;
- if (ctr->generic_class && !mono_class_is_valid_generic_instantiation (NULL, ctr))
+ if (mono_class_is_ginst (ctr) && !mono_class_is_valid_generic_instantiation (NULL, ctr))
goto fail;
}
}
if (klass->parent) {
if (MONO_CLASS_IS_INTERFACE (klass->parent))
return FALSE;
- if (!klass->generic_class && klass->parent->generic_container)
+ if (!mono_class_is_ginst (klass) && klass->parent->generic_container)
return FALSE;
- if (klass->parent->generic_class && !klass->generic_class) {
+ if (mono_class_is_ginst (klass->parent) && !mono_class_is_ginst (klass)) {
MonoGenericContext *context = mono_class_get_context (klass);
if (klass->generic_container)
context = &klass->generic_container->context;
return FALSE;
if (!verify_class_for_overlapping_reference_fields (klass))
return FALSE;
- if (klass->generic_class && !mono_class_is_valid_generic_instantiation (NULL, klass))
+ if (mono_class_is_ginst (klass) && !mono_class_is_valid_generic_instantiation (NULL, klass))
return FALSE;
- if (klass->generic_class == NULL && !verify_class_fields (klass))
+ if (!mono_class_is_ginst (klass) && !verify_class_fields (klass))
return FALSE;
if (klass->valuetype && !verify_valuetype_layout (klass))
return FALSE;