X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmetadata%2Fverify.c;h=106bae0725557f553a4fbb760eea7b3d04a9ee74;hb=e7d19721c601da32575571c7621d4d28e564cf4b;hp=54651bc2b3cac02ede81eb4ba04cacdd65df7551;hpb=ef0ddf45c3081e799edcb4e95770186514b80cf1;p=mono.git diff --git a/mono/metadata/verify.c b/mono/metadata/verify.c index 54651bc2b3c..106bae07255 100644 --- a/mono/metadata/verify.c +++ b/mono/metadata/verify.c @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -371,7 +372,7 @@ static gboolean 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; } @@ -470,7 +471,8 @@ mono_class_has_default_constructor (MonoClass *klass) if (mono_class_has_failure (klass)) return FALSE; - for (i = 0; i < klass->method.count; ++i) { + int mcount = mono_class_get_method_count (klass); + for (i = 0; i < mcount; ++i) { method = klass->methods [i]; if (mono_method_is_constructor (method) && mono_method_signature (method) && @@ -528,7 +530,7 @@ mono_type_is_valid_type_in_context_full (MonoType *type, MonoGenericContext *con if (klass->byval_arg.type != type->type) return mono_type_is_valid_type_in_context_full (&klass->byval_arg, context, check_gtd); - if (check_gtd && klass->generic_container) + if (check_gtd && mono_class_is_gtd (klass)) return FALSE; break; } @@ -596,11 +598,11 @@ is_valid_generic_instantiation (MonoGenericContainer *gc, MonoGenericContext *co * The type A has a parent B, that is inflated into the GTD B<>. * Since A is open, thus not instantiatable, this is valid. */ - if (paramClass->generic_container && param_type->type != MONO_TYPE_GENERICINST && !ginst->is_open) + if (mono_class_is_gtd (paramClass) && param_type->type != MONO_TYPE_GENERICINST && !ginst->is_open) 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; } @@ -753,9 +755,9 @@ verifier_get_generic_param_from_type (VerifyContext *ctx, MonoType *type) if (type->type == MONO_TYPE_VAR) { MonoClass *gtd = method->klass; - if (gtd->generic_class) - gtd = gtd->generic_class->container_class; - gc = gtd->generic_container; + if (mono_class_is_ginst (gtd)) + gtd = mono_class_get_generic_class (gtd)->container_class; + gc = mono_class_try_get_generic_container (gtd); } else { //MVAR MonoMethod *gmd = method; if (method->is_inflated) @@ -830,9 +832,9 @@ mono_method_repect_method_constraints (VerifyContext *ctx, MonoMethod *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; + MonoGenericContainer *gc = mono_class_get_generic_container (gklass->container_class); return !gc || generic_arguments_respect_constraints (ctx, gc, &gklass->context, ginst); } @@ -853,9 +855,9 @@ mono_method_is_valid_generic_instantiation (VerifyContext *ctx, MonoMethod *meth 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; + MonoGenericContainer *gc = mono_class_get_generic_container (gklass->container_class); if (ctx && !is_valid_generic_instantiation_in_context (ctx, ginst, TRUE)) return FALSE; return is_valid_generic_instantiation (gc, &gklass->context, ginst); @@ -885,21 +887,20 @@ mono_type_is_valid_in_context (VerifyContext *ctx, MonoType *type) 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)) { @@ -1021,9 +1022,8 @@ verifier_load_type (VerifyContext *ctx, int token, const char *opcode) { 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; } @@ -1679,7 +1679,7 @@ get_boxable_mono_type (VerifyContext* ctx, int token, const char *opcode) if (!(klass = mono_class_from_mono_type (type))) ADD_VERIFY_ERROR (ctx, g_strdup_printf ("Could not retrieve type token for %s at 0x%04x", opcode, ctx->ip_offset)); - if (klass->generic_container && type->type != MONO_TYPE_GENERICINST) + if (mono_class_is_gtd (klass) && type->type != MONO_TYPE_GENERICINST) CODE_NOT_VERIFIABLE (ctx, g_strdup_printf ("Cannot use the generic type definition in a boxable type position for %s at 0x%04x", opcode, ctx->ip_offset)); check_unverifiable_type (ctx, type); @@ -2189,14 +2189,14 @@ verifier_class_is_assignable_from (MonoClass *target, MonoClass *candidate) 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; @@ -2675,7 +2675,7 @@ verify_ldftn_delegate (VerifyContext *ctx, MonoClass *delegate, ILStackDesc *val * the object is a this arg (comes from a ldarg.0), and there is no starg.0. * This rules doesn't apply if the object on stack is a boxed valuetype. */ - if ((method->flags & METHOD_ATTRIBUTE_VIRTUAL) && !(method->flags & METHOD_ATTRIBUTE_FINAL) && !(method->klass->flags & TYPE_ATTRIBUTE_SEALED) && !stack_slot_is_boxed_value (value)) { + if ((method->flags & METHOD_ATTRIBUTE_VIRTUAL) && !(method->flags & METHOD_ATTRIBUTE_FINAL) && !mono_class_is_sealed (method->klass) && !stack_slot_is_boxed_value (value)) { /*A stdarg 0 must not happen, we fail here only in fail fast mode to avoid double error reports*/ if (IS_FAIL_FAST_MODE (ctx) && ctx->has_this_store) CODE_NOT_VERIFIABLE (ctx, g_strdup_printf ("Invalid ldftn with virtual function in method with stdarg 0 at 0x%04x", ctx->ip_offset)); @@ -2770,7 +2770,7 @@ verify_delegate_compatibility (VerifyContext *ctx, MonoClass *delegate, ILStackD 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)) @@ -3167,7 +3167,7 @@ do_invoke_method (VerifyContext *ctx, int method_token, gboolean virtual_) if (method->flags & METHOD_ATTRIBUTE_ABSTRACT) CODE_NOT_VERIFIABLE (ctx, g_strdup_printf ("Cannot use call with an abstract method at 0x%04x", ctx->ip_offset)); - if ((method->flags & METHOD_ATTRIBUTE_VIRTUAL) && !(method->flags & METHOD_ATTRIBUTE_FINAL) && !(method->klass->flags & TYPE_ATTRIBUTE_SEALED)) { + if ((method->flags & METHOD_ATTRIBUTE_VIRTUAL) && !(method->flags & METHOD_ATTRIBUTE_FINAL) && !mono_class_is_sealed (method->klass)) { virt_check_this = TRUE; ctx->code [ctx->ip_offset].flags |= IL_CODE_CALL_NONFINAL_VIRTUAL; } @@ -3812,7 +3812,7 @@ do_newobj (VerifyContext *ctx, int token) return; } - if (method->klass->flags & (TYPE_ATTRIBUTE_ABSTRACT | TYPE_ATTRIBUTE_INTERFACE)) + if (mono_class_get_flags (method->klass) & (TYPE_ATTRIBUTE_ABSTRACT | TYPE_ATTRIBUTE_INTERFACE)) CODE_NOT_VERIFIABLE (ctx, g_strdup_printf ("Trying to instantiate an abstract or interface type at 0x%04x", ctx->ip_offset)); if (!IS_SKIP_VISIBILITY (ctx) && !mono_method_can_access_method_full (ctx->method, method, NULL)) { @@ -4644,7 +4644,7 @@ merge_stacks (VerifyContext *ctx, ILCodeDesc *from, ILCodeDesc *to, gboolean sta } /* if old class is an interface that new class implements */ - if (old_class->flags & TYPE_ATTRIBUTE_INTERFACE) { + if (mono_class_is_interface (old_class)) { if (verifier_class_is_assignable_from (old_class, new_class)) { match_class = old_class; goto match_found; @@ -4657,7 +4657,7 @@ merge_stacks (VerifyContext *ctx, ILCodeDesc *from, ILCodeDesc *to, gboolean sta } } - if (new_class->flags & TYPE_ATTRIBUTE_INTERFACE) { + if (mono_class_is_interface (new_class)) { if (verifier_class_is_assignable_from (new_class, old_class)) { match_class = new_class; goto match_found; @@ -4849,7 +4849,7 @@ mono_method_verify (MonoMethod *method, int level) 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; @@ -4896,11 +4896,11 @@ mono_method_verify (MonoMethod *method, int level) if (ctx.signature->is_inflated) ctx.generic_context = generic_context = mono_method_get_context (method); - if (!generic_context && (method->klass->generic_container || method->is_generic)) { + if (!generic_context && (mono_class_is_gtd (method->klass) || method->is_generic)) { if (method->is_generic) ctx.generic_context = generic_context = &(mono_method_get_generic_container (method)->context); else - ctx.generic_context = generic_context = &method->klass->generic_container->context; + ctx.generic_context = generic_context = &mono_class_get_generic_container (method->klass)->context; } for (i = 0; i < ctx.num_locals; ++i) { @@ -5017,7 +5017,7 @@ mono_method_verify (MonoMethod *method, int level) if (!ctx.valid) goto cleanup; - original_bb = bb = mono_basic_block_split (method, &error); + original_bb = bb = mono_basic_block_split (method, &error, ctx.header); if (!mono_error_ok (&error)) { ADD_VERIFY_ERROR (&ctx, g_strdup_printf ("Invalid branch target: %s", mono_error_get_message (&error))); mono_error_cleanup (&error); @@ -6103,7 +6103,7 @@ verify_class_for_overlapping_reference_fields (MonoClass *klass) MonoClassField *field; gboolean is_fulltrust = mono_verifier_is_class_full_trust (klass); /*We can't skip types with !has_references since this is calculated after we have run.*/ - if (!((klass->flags & TYPE_ATTRIBUTE_LAYOUT_MASK) == TYPE_ATTRIBUTE_EXPLICIT_LAYOUT)) + if (!mono_class_is_explicit_layout (klass)) return TRUE; @@ -6118,7 +6118,8 @@ verify_class_for_overlapping_reference_fields (MonoClass *klass) if (mono_field_is_deleted (field) || (field->type->attrs & FIELD_ATTRIBUTE_STATIC)) continue; - for (j = i; j < klass->field.count; ++j) { + int fcount = mono_class_get_field_count (klass); + for (j = i; j < fcount; ++j) { MonoClassField *other = &klass->fields [j]; int otherEnd = get_field_end (other); if (mono_field_is_deleted (other) || (is_valuetype && !MONO_TYPE_IS_REFERENCE (other->type)) || (other->type->attrs & FIELD_ATTRIBUTE_STATIC)) @@ -6157,8 +6158,8 @@ verify_class_fields (MonoClass *klass) MonoClassField *field; MonoGenericContext *context = mono_class_get_context (klass); GHashTable *unique_fields = g_hash_table_new_full (&field_hash, &field_equals, NULL, NULL); - if (klass->generic_container) - context = &klass->generic_container->context; + if (mono_class_is_gtd (klass)) + context = &mono_class_get_generic_container (klass)->context; while ((field = mono_class_get_fields (klass, &iter)) != NULL) { if (!mono_type_is_valid_type_in_context (field->type, context)) { @@ -6181,7 +6182,7 @@ verify_interfaces (MonoClass *klass) int i; for (i = 0; i < klass->interface_count; ++i) { MonoClass *iface = klass->interfaces [i]; - if (!(iface->flags & TYPE_ATTRIBUTE_INTERFACE)) + if (!mono_class_get_flags (iface)) return FALSE; } return TRUE; @@ -6260,7 +6261,7 @@ static gboolean verify_generic_parameters (MonoClass *klass) { int i; - MonoGenericContainer *gc = klass->generic_container; + MonoGenericContainer *gc = mono_class_get_generic_container (klass); MonoBitSet *used_args = mono_bitset_new (gc->type_argc, 0); for (i = 0; i < gc->type_argc; ++i) { @@ -6285,7 +6286,7 @@ verify_generic_parameters (MonoClass *klass) 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; } } @@ -6318,25 +6319,25 @@ mono_verifier_verify_class (MonoClass *klass) 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) && mono_class_is_gtd (klass->parent)) 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; + if (mono_class_is_gtd (klass)) + context = &mono_class_get_generic_container (klass)->context; if (!mono_type_is_valid_type_in_context (&klass->parent->byval_arg, context)) return FALSE; } } - if (klass->generic_container && (klass->flags & TYPE_ATTRIBUTE_LAYOUT_MASK) == TYPE_ATTRIBUTE_EXPLICIT_LAYOUT) + if (mono_class_is_gtd (klass) && (mono_class_is_explicit_layout (klass))) return FALSE; - if (klass->generic_container && !verify_generic_parameters (klass)) + if (mono_class_is_gtd (klass) && !verify_generic_parameters (klass)) 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;