X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmetadata%2Fverify.c;h=383ced4f1bf4a5540004bfc16ceb5fa8efa207e6;hb=ff49850dfc18f5991246a203184fa1e0b8a7c7ab;hp=68fe0688774e03bdf70e4f80f566f1e98cc3abf8;hpb=b61747cd90b883f1a6023ff66d743efaa4e26f99;p=mono.git diff --git a/mono/metadata/verify.c b/mono/metadata/verify.c index 68fe0688774..383ced4f1bf 100644 --- a/mono/metadata/verify.c +++ b/mono/metadata/verify.c @@ -390,7 +390,7 @@ mono_type_create_fnptr_from_mono_method (VerifyContext *ctx, MonoMethod *method) /* * mono_type_is_enum_type: * - * Returns TRUE if @type is an enum type. + * Returns: TRUE if @type is an enum type. */ static gboolean mono_type_is_enum_type (MonoType *type) @@ -405,14 +405,14 @@ mono_type_is_enum_type (MonoType *type) /* * mono_type_is_value_type: * - * Returns TRUE if @type is named after @namespace.@name. + * Returns: TRUE if @type is named after @namespace.@name. * */ static gboolean -mono_type_is_value_type (MonoType *type, const char *namespace, const char *name) +mono_type_is_value_type (MonoType *type, const char *namespace_, const char *name) { return type->type == MONO_TYPE_VALUETYPE && - !strcmp (namespace, type->data.klass->name_space) && + !strcmp (namespace_, type->data.klass->name_space) && !strcmp (name, type->data.klass->name); } @@ -466,7 +466,7 @@ mono_class_has_default_constructor (MonoClass *klass) int i; mono_class_setup_methods (klass); - if (klass->exception_type) + if (mono_class_has_failure (klass)) return FALSE; for (i = 0; i < klass->method.count; ++i) { @@ -639,8 +639,10 @@ is_valid_generic_instantiation (MonoGenericContainer *gc, MonoGenericContext *co return TRUE; } -/* - * Return true if @candidate is constraint compatible with @target. +/** + * mono_generic_param_is_constraint_compatible: + * + * Returns: TRUE if @candidate is constraint compatible with @target. * * This means that @candidate constraints are a super set of @target constaints */ @@ -882,7 +884,7 @@ 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 () || klass->exception_type != MONO_EXCEPTION_NONE) { + if (mono_loader_get_last_error () || mono_class_has_failure (klass)) { if (klass->generic_class && !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 @@ -891,7 +893,7 @@ mono_type_is_valid_in_context (VerifyContext *ctx, MonoType *type) return FALSE; } - if (klass->generic_class && klass->generic_class->container_class->exception_type != MONO_EXCEPTION_NONE) { + if (klass->generic_class && mono_class_has_failure (klass->generic_class->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; } @@ -941,7 +943,7 @@ verifier_load_field (VerifyContext *ctx, int token, MonoClass **out_klass, const MonoClass *klass = NULL; if (ctx->method->wrapper_type != MONO_WRAPPER_NONE) { - field = mono_method_get_wrapper_data (ctx->method, (guint32)token); + field = (MonoClassField *)mono_method_get_wrapper_data (ctx->method, (guint32)token); klass = field ? field->parent : NULL; } else { if (!IS_FIELD_DEF_OR_REF (token) || !token_bounds_check (ctx->image, token)) { @@ -978,7 +980,7 @@ verifier_load_method (VerifyContext *ctx, int token, const char *opcode) { if (ctx->method->wrapper_type != MONO_WRAPPER_NONE) { - method = mono_method_get_wrapper_data (ctx->method, (guint32)token); + method = (MonoMethod *)mono_method_get_wrapper_data (ctx->method, (guint32)token); } else { MonoError error; if (!IS_METHOD_DEF_OR_REF_OR_SPEC (token) || !token_bounds_check (ctx->image, token)) { @@ -1006,8 +1008,8 @@ verifier_load_type (VerifyContext *ctx, int token, const char *opcode) { MonoType* type; if (ctx->method->wrapper_type != MONO_WRAPPER_NONE) { - MonoClass *class = mono_method_get_wrapper_data (ctx->method, (guint32)token); - type = class ? &class->byval_arg : NULL; + MonoClass *klass = (MonoClass *)mono_method_get_wrapper_data (ctx->method, (guint32)token); + type = klass ? &klass->byval_arg : NULL; } else { MonoError error; if (!IS_TYPE_DEF_OR_REF_OR_SPEC (token) || !token_bounds_check (ctx->image, token)) { @@ -1175,7 +1177,7 @@ mono_free_verify_list (GSList *list) GSList *tmp; for (tmp = list; tmp; tmp = tmp->next) { - info = tmp->data; + info = (MonoVerifyInfoExtended *)tmp->data; g_free (info->info.message); g_free (info); } @@ -1655,7 +1657,7 @@ static MonoType* get_boxable_mono_type (VerifyContext* ctx, int token, const char *opcode) { MonoType *type; - MonoClass *class; + MonoClass *klass; if (!(type = verifier_load_type (ctx, token, opcode))) return NULL; @@ -1673,10 +1675,10 @@ get_boxable_mono_type (VerifyContext* ctx, int token, const char *opcode) if (type->type == MONO_TYPE_TYPEDBYREF) CODE_NOT_VERIFIABLE (ctx, g_strdup_printf ("Invalid use of typedbyref for %s at 0x%04x", opcode, ctx->ip_offset)); - if (!(class = mono_class_from_mono_type (type))) + 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 (class->generic_container && type->type != MONO_TYPE_GENERICINST) + if (klass->generic_container && 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); @@ -1875,8 +1877,12 @@ dump_stack_state (ILCodeDesc *state) } #endif -/*Returns TRUE if candidate array type can be assigned to target. - *Both parameters MUST be of type MONO_TYPE_ARRAY (target->type == MONO_TYPE_ARRAY) +/** + * is_array_type_compatible: + * + * Returns TRUE if candidate array type can be assigned to target. + * + * Both parameters MUST be of type MONO_TYPE_ARRAY (target->type == MONO_TYPE_ARRAY) */ static gboolean is_array_type_compatible (MonoType *target, MonoType *candidate) @@ -2072,49 +2078,35 @@ init_stack_with_value_at_exception_boundary (VerifyContext *ctx, ILCodeDesc *cod if (mono_type_is_generic_argument (type)) code->stack->stype |= BOXED_MASK; } +/* Class lazy loading functions */ +static GENERATE_GET_CLASS_WITH_CACHE (ienumerable, System.Collections.Generic, IEnumerable`1) +static GENERATE_GET_CLASS_WITH_CACHE (icollection, System.Collections.Generic, ICollection`1) +static GENERATE_GET_CLASS_WITH_CACHE (ireadonly_list, System.Collections.Generic, IReadOnlyList`1) +static GENERATE_GET_CLASS_WITH_CACHE (ireadonly_collection, System.Collections.Generic, IReadOnlyCollection`1) + static MonoClass* get_ienumerable_class (void) { - static MonoClass* generic_ienumerable_class = NULL; - - if (generic_ienumerable_class == NULL) - generic_ienumerable_class = mono_class_from_name (mono_defaults.corlib, - "System.Collections.Generic", "IEnumerable`1"); - return generic_ienumerable_class; + return mono_class_get_ienumerable_class (); } static MonoClass* get_icollection_class (void) { - static MonoClass* generic_icollection_class = NULL; - - if (generic_icollection_class == NULL) - generic_icollection_class = mono_class_from_name (mono_defaults.corlib, - "System.Collections.Generic", "ICollection`1"); - return generic_icollection_class; + return mono_class_get_icollection_class (); } static MonoClass* get_ireadonlylist_class (void) { - static MonoClass* generic_ireadonlylist_class = NULL; - - if (generic_ireadonlylist_class == NULL) - generic_ireadonlylist_class = mono_class_from_name (mono_defaults.corlib, - "System.Collections.Generic", "IReadOnlyList`1"); - return generic_ireadonlylist_class; + return mono_class_get_ireadonly_list_class (); } static MonoClass* get_ireadonlycollection_class (void) { - static MonoClass* generic_ireadonlycollection_class = NULL; - - if (generic_ireadonlycollection_class == NULL) - generic_ireadonlycollection_class = mono_class_from_name (mono_defaults.corlib, - "System.Collections.Generic", "IReadOnlyCollection`1"); - return generic_ireadonlycollection_class; + return mono_class_get_ireadonly_collection_class (); } static MonoClass* @@ -2444,21 +2436,21 @@ recursive_boxed_constraint_type_check (VerifyContext *ctx, MonoType *type, MonoC if (mono_type_is_generic_argument (constraint_type)) { MonoGenericParam *param = get_generic_param (ctx, constraint_type); - MonoClass **class; + MonoClass **klass; if (!param) return FALSE; - for (class = mono_generic_param_info (param)->constraints; class && *class; ++class) { - if (recursive_boxed_constraint_type_check (ctx, type, *class, recursion_level - 1)) + for (klass = mono_generic_param_info (param)->constraints; klass && *klass; ++klass) { + if (recursive_boxed_constraint_type_check (ctx, type, *klass, recursion_level - 1)) return TRUE; } } return FALSE; } -/* +/** * is_compatible_boxed_valuetype: * - * Returns TRUE if @candidate / @stack is a valid boxed valuetype. + * Returns: TRUE if @candidate / @stack is a valid boxed valuetype. * * @type The source type. It it tested to be of the proper type. * @candidate type of the boxed valuetype. @@ -2476,13 +2468,13 @@ is_compatible_boxed_valuetype (VerifyContext *ctx, MonoType *type, MonoType *can if (mono_type_is_generic_argument (candidate)) { MonoGenericParam *param = get_generic_param (ctx, candidate); - MonoClass **class; + MonoClass **klass; if (!param) return FALSE; - for (class = mono_generic_param_info (param)->constraints; class && *class; ++class) { + for (klass = mono_generic_param_info (param)->constraints; klass && *klass; ++klass) { /*256 should be enough since there can't be more than 255 generic arguments.*/ - if (recursive_boxed_constraint_type_check (ctx, type, *class, 256)) + if (recursive_boxed_constraint_type_check (ctx, type, *klass, 256)) return TRUE; } } @@ -2515,6 +2507,12 @@ verify_stack_type_compatibility_full (VerifyContext *ctx, MonoType *type, ILStac if (drop_byref) return verify_type_compatibility_full (ctx, type, mono_type_get_type_byval (candidate), FALSE); + /* Handle how Roslyn emit fixed statements by encoding it as byref */ + if (type->byref && candidate->byref && (type->type == MONO_TYPE_I) && !mono_type_is_reference (candidate)) { + if (!IS_STRICT_MODE (ctx)) + return TRUE; + } + return verify_type_compatibility_full (ctx, type, candidate, FALSE); } @@ -3142,7 +3140,7 @@ do_ret (VerifyContext *ctx) * TODO handle calling .ctor outside one or calling the .ctor for other class but super */ static void -do_invoke_method (VerifyContext *ctx, int method_token, gboolean virtual) +do_invoke_method (VerifyContext *ctx, int method_token, gboolean virtual_) { MonoError error; int param_count, i; @@ -3152,10 +3150,10 @@ do_invoke_method (VerifyContext *ctx, int method_token, gboolean virtual) gboolean virt_check_this = FALSE; gboolean constrained = ctx->prefix_set & PREFIX_CONSTRAINED; - if (!(method = verifier_load_method (ctx, method_token, virtual ? "callvirt" : "call"))) + if (!(method = verifier_load_method (ctx, method_token, virtual_ ? "callvirt" : "call"))) return; - if (virtual) { + if (virtual_) { CLEAR_PREFIX (ctx, PREFIX_CONSTRAINED); if (method->klass->valuetype) // && !constrained ??? @@ -3203,10 +3201,10 @@ do_invoke_method (VerifyContext *ctx, int method_token, gboolean virtual) } if (stack_slot_is_managed_mutability_pointer (value)) - CODE_NOT_VERIFIABLE (ctx, g_strdup_printf ("Cannot use a readonly pointer as argument of %s at 0x%04x", virtual ? "callvirt" : "call", ctx->ip_offset)); + CODE_NOT_VERIFIABLE (ctx, g_strdup_printf ("Cannot use a readonly pointer as argument of %s at 0x%04x", virtual_ ? "callvirt" : "call", ctx->ip_offset)); if ((ctx->prefix_set & PREFIX_TAIL) && stack_slot_is_managed_pointer (value)) { - ADD_VERIFY_ERROR (ctx, g_strdup_printf ("Cannot pass a byref argument to a tail %s at 0x%04x", virtual ? "callvirt" : "call", ctx->ip_offset)); + ADD_VERIFY_ERROR (ctx, g_strdup_printf ("Cannot pass a byref argument to a tail %s at 0x%04x", virtual_ ? "callvirt" : "call", ctx->ip_offset)); return; } } @@ -3238,7 +3236,7 @@ do_invoke_method (VerifyContext *ctx, int method_token, gboolean virtual) if (virt_check_this && !stack_slot_is_this_pointer (value) && !(method->klass->valuetype || stack_slot_is_boxed_value (value))) CODE_NOT_VERIFIABLE (ctx, g_strdup_printf ("Cannot use the call opcode with a non-final virtual method on an object different than the 'this' pointer at 0x%04x", ctx->ip_offset)); - if (constrained && virtual) { + if (constrained && virtual_) { if (!stack_slot_is_managed_pointer (value)) CODE_NOT_VERIFIABLE (ctx, g_strdup_printf ("Object is not a managed pointer for a constrained call at 0x%04x", ctx->ip_offset)); if (!mono_metadata_type_equal_full (mono_type_get_type_byval (value->type), mono_type_get_underlying_type (ctx->constrained_type), TRUE)) @@ -3249,10 +3247,10 @@ do_invoke_method (VerifyContext *ctx, int method_token, gboolean virtual) if (stack_slot_is_managed_pointer (value) && !mono_class_from_mono_type (value->type)->valuetype) CODE_NOT_VERIFIABLE (ctx, g_strdup_printf ("Cannot call a reference type using a managed pointer to the this arg at 0x%04x", ctx->ip_offset)); - if (!virtual && mono_class_from_mono_type (value->type)->valuetype && !method->klass->valuetype && !stack_slot_is_boxed_value (value)) + if (!virtual_ && mono_class_from_mono_type (value->type)->valuetype && !method->klass->valuetype && !stack_slot_is_boxed_value (value)) CODE_NOT_VERIFIABLE (ctx, g_strdup_printf ("Cannot call a valuetype baseclass at 0x%04x", ctx->ip_offset)); - if (virtual && mono_class_from_mono_type (value->type)->valuetype && !stack_slot_is_boxed_value (value)) + if (virtual_ && mono_class_from_mono_type (value->type)->valuetype && !stack_slot_is_boxed_value (value)) CODE_NOT_VERIFIABLE (ctx, g_strdup_printf ("Cannot use a valuetype with callvirt at 0x%04x", ctx->ip_offset)); if (method->klass->valuetype && (stack_slot_is_boxed_value (value) || !stack_slot_is_managed_pointer (value))) @@ -3621,7 +3619,7 @@ do_load_token (VerifyContext *ctx, int token) if (ctx->method->wrapper_type != MONO_WRAPPER_NONE) { handle = mono_method_get_wrapper_data (ctx->method, token); - handle_class = mono_method_get_wrapper_data (ctx->method, token + 1); + handle_class = (MonoClass *)mono_method_get_wrapper_data (ctx->method, token + 1); if (handle_class == mono_defaults.typehandle_class) handle = &((MonoClass*)handle)->byval_arg; } else { @@ -4347,19 +4345,19 @@ do_switch (VerifyContext *ctx, int count, const unsigned char *data) } static void -do_load_function_ptr (VerifyContext *ctx, guint32 token, gboolean virtual) +do_load_function_ptr (VerifyContext *ctx, guint32 token, gboolean virtual_) { ILStackDesc *top; MonoMethod *method; - if (virtual && !check_underflow (ctx, 1)) + if (virtual_ && !check_underflow (ctx, 1)) return; - if (!virtual && !check_overflow (ctx)) + if (!virtual_ && !check_overflow (ctx)) return; if (ctx->method->wrapper_type != MONO_WRAPPER_NONE) { - method = mono_method_get_wrapper_data (ctx->method, (guint32)token); + method = (MonoMethod *)mono_method_get_wrapper_data (ctx->method, (guint32)token); if (!method) { ADD_VERIFY_ERROR2 (ctx, g_strdup_printf ("Invalid token %x for ldftn at 0x%04x", token, ctx->ip_offset), MONO_EXCEPTION_BAD_IMAGE); return; @@ -4370,14 +4368,14 @@ do_load_function_ptr (VerifyContext *ctx, guint32 token, gboolean virtual) return; } - if (!(method = verifier_load_method (ctx, token, virtual ? "ldvirtfrn" : "ldftn"))) + if (!(method = verifier_load_method (ctx, token, virtual_ ? "ldvirtfrn" : "ldftn"))) return; } if (mono_method_is_constructor (method)) CODE_NOT_VERIFIABLE (ctx, g_strdup_printf ("Cannot use ldftn with a constructor at 0x%04x", ctx->ip_offset)); - if (virtual) { + if (virtual_) { ILStackDesc *top = stack_pop (ctx); if (stack_slot_get_type (top) != TYPE_COMPLEX || top->type->type == MONO_TYPE_VALUETYPE) @@ -4705,7 +4703,7 @@ end_verify: #define HANDLER_START(clause) ((clause)->flags == MONO_EXCEPTION_CLAUSE_FILTER ? (clause)->data.filter_offset : clause->handler_offset) #define IS_CATCH_OR_FILTER(clause) ((clause)->flags == MONO_EXCEPTION_CLAUSE_FILTER || (clause)->flags == MONO_EXCEPTION_CLAUSE_NONE) -/* +/** * is_clause_in_range : * * Returns TRUE if either the protected block or the handler of @clause is in the @start - @end range. @@ -4720,7 +4718,7 @@ is_clause_in_range (MonoExceptionClause *clause, guint32 start, guint32 end) return FALSE; } -/* +/** * is_clause_inside_range : * * Returns TRUE if @clause lies completely inside the @start - @end range. @@ -4735,7 +4733,7 @@ is_clause_inside_range (MonoExceptionClause *clause, guint32 start, guint32 end) return TRUE; } -/* +/** * is_clause_nested : * * Returns TRUE if @nested is nested in @clause. @@ -4856,9 +4854,10 @@ mono_method_verify (MonoMethod *method, int level) return ctx.list; } - ctx.header = mono_method_get_header (method); + ctx.header = mono_method_get_header_checked (method, &error); if (!ctx.header) { - ADD_VERIFY_ERROR (&ctx, g_strdup_printf ("Could not decode method header")); + ADD_VERIFY_ERROR (&ctx, g_strdup_printf ("Could not decode method header due to %s", mono_error_get_message (&error))); + mono_error_cleanup (&error); finish_collect_stats (); return ctx.list; } @@ -4880,7 +4879,7 @@ mono_method_verify (MonoMethod *method, int level) memset(ctx.code, 0, sizeof (ILCodeDesc) * ctx.header->code_size); ctx.num_locals = ctx.header->num_locals; - ctx.locals = g_memdup (ctx.header->locals, sizeof (MonoType*) * ctx.header->num_locals); + ctx.locals = (MonoType **)g_memdup (ctx.header->locals, sizeof (MonoType*) * ctx.header->num_locals); _MEM_ALLOC (sizeof (MonoType*) * ctx.header->num_locals); if (ctx.num_locals > 0 && !ctx.header->init_locals) @@ -5017,7 +5016,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); @@ -5961,7 +5960,7 @@ mono_method_verify (MonoMethod *method, int level) if (mono_method_is_constructor (ctx.method) && !ctx.super_ctor_called && !ctx.method->klass->valuetype && ctx.method->klass != mono_defaults.object_class) { char *method_name = mono_method_full_name (ctx.method, TRUE); char *type = mono_type_get_full_name (ctx.method->klass); - if (ctx.method->klass->parent && ctx.method->klass->parent->exception_type != MONO_EXCEPTION_NONE) + if (ctx.method->klass->parent && mono_class_has_failure (ctx.method->klass->parent)) CODE_NOT_VERIFIABLE (&ctx, g_strdup_printf ("Constructor %s for type %s not calling base type ctor due to a TypeLoadException on base type.", method_name, type)); else CODE_NOT_VERIFIABLE (&ctx, g_strdup_printf ("Constructor %s for type %s not calling base type ctor.", method_name, type)); @@ -5982,7 +5981,7 @@ cleanup: g_slist_free (ctx.funptrs); for (tmp = ctx.exception_types; tmp; tmp = tmp->next) - mono_metadata_free_type (tmp->data); + mono_metadata_free_type ((MonoType *)tmp->data); g_slist_free (ctx.exception_types); for (i = 0; i < ctx.num_locals; ++i) { @@ -6014,8 +6013,11 @@ mono_verify_corlib () return NULL; } -/* - * Returns true if @method needs to be verified. +/** + * mono_verifier_is_enabled_for_method: + * @method: the method to probe + * + * Returns TRUE if @method needs to be verified. * */ gboolean @@ -6024,8 +6026,11 @@ mono_verifier_is_enabled_for_method (MonoMethod *method) return mono_verifier_is_enabled_for_class (method->klass) && (method->wrapper_type == MONO_WRAPPER_NONE || method->wrapper_type == MONO_WRAPPER_DYNAMIC_METHOD); } -/* - * Returns true if @klass need to be verified. +/** + * mono_verifier_is_enabled_for_class: + * @klass: The `MonoClass` to probe + * + * Returns TRUE if @klass need to be verified. * */ gboolean @@ -6090,21 +6095,21 @@ get_field_end (MonoClassField *field) } static gboolean -verify_class_for_overlapping_reference_fields (MonoClass *class) +verify_class_for_overlapping_reference_fields (MonoClass *klass) { int i = 0, j; gpointer iter = NULL; MonoClassField *field; - gboolean is_fulltrust = mono_verifier_is_class_full_trust (class); + 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 (!((class->flags & TYPE_ATTRIBUTE_LAYOUT_MASK) == TYPE_ATTRIBUTE_EXPLICIT_LAYOUT)) + if (!((klass->flags & TYPE_ATTRIBUTE_LAYOUT_MASK) == TYPE_ATTRIBUTE_EXPLICIT_LAYOUT)) return TRUE; /*We must check for stuff overlapping reference fields. The outer loop uses mono_class_get_fields to ensure that MonoClass:fields get inited. */ - while ((field = mono_class_get_fields (class, &iter))) { + while ((field = mono_class_get_fields (klass, &iter))) { int fieldEnd = get_field_end (field); gboolean is_valuetype = !MONO_TYPE_IS_REFERENCE (field->type); ++i; @@ -6112,8 +6117,8 @@ verify_class_for_overlapping_reference_fields (MonoClass *class) if (mono_field_is_deleted (field) || (field->type->attrs & FIELD_ATTRIBUTE_STATIC)) continue; - for (j = i; j < class->field.count; ++j) { - MonoClassField *other = &class->fields [j]; + for (j = i; j < klass->field.count; ++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)) continue; @@ -6131,30 +6136,30 @@ verify_class_for_overlapping_reference_fields (MonoClass *class) static guint field_hash (gconstpointer key) { - const MonoClassField *field = key; + const MonoClassField *field = (const MonoClassField *)key; return g_str_hash (field->name) ^ mono_metadata_type_hash (field->type); /**/ } static gboolean field_equals (gconstpointer _a, gconstpointer _b) { - const MonoClassField *a = _a; - const MonoClassField *b = _b; + const MonoClassField *a = (const MonoClassField *)_a; + const MonoClassField *b = (const MonoClassField *)_b; return !strcmp (a->name, b->name) && mono_metadata_type_equal (a->type, b->type); } static gboolean -verify_class_fields (MonoClass *class) +verify_class_fields (MonoClass *klass) { gpointer iter = NULL; MonoClassField *field; - MonoGenericContext *context = mono_class_get_context (class); + MonoGenericContext *context = mono_class_get_context (klass); GHashTable *unique_fields = g_hash_table_new_full (&field_hash, &field_equals, NULL, NULL); - if (class->generic_container) - context = &class->generic_container->context; + if (klass->generic_container) + context = &klass->generic_container->context; - while ((field = mono_class_get_fields (class, &iter)) != NULL) { + while ((field = mono_class_get_fields (klass, &iter)) != NULL) { if (!mono_type_is_valid_type_in_context (field->type, context)) { g_hash_table_destroy (unique_fields); return FALSE; @@ -6170,11 +6175,11 @@ verify_class_fields (MonoClass *class) } static gboolean -verify_interfaces (MonoClass *class) +verify_interfaces (MonoClass *klass) { int i; - for (i = 0; i < class->interface_count; ++i) { - MonoClass *iface = class->interfaces [i]; + for (i = 0; i < klass->interface_count; ++i) { + MonoClass *iface = klass->interfaces [i]; if (!(iface->flags & TYPE_ATTRIBUTE_INTERFACE)) return FALSE; } @@ -6182,22 +6187,22 @@ verify_interfaces (MonoClass *class) } static gboolean -verify_valuetype_layout_with_target (MonoClass *class, MonoClass *target_class) +verify_valuetype_layout_with_target (MonoClass *klass, MonoClass *target_class) { int type; gpointer iter = NULL; MonoClassField *field; MonoClass *field_class; - if (!class->valuetype) + if (!klass->valuetype) return TRUE; - type = class->byval_arg.type; + type = klass->byval_arg.type; /*primitive type fields are not properly decoded*/ if ((type >= MONO_TYPE_BOOLEAN && type <= MONO_TYPE_R8) || (type >= MONO_TYPE_I && type <= MONO_TYPE_U)) return TRUE; - while ((field = mono_class_get_fields (class, &iter)) != NULL) { + while ((field = mono_class_get_fields (klass, &iter)) != NULL) { if (!field->type) return FALSE; @@ -6206,7 +6211,7 @@ verify_valuetype_layout_with_target (MonoClass *class, MonoClass *target_class) field_class = mono_class_get_generic_type_definition (mono_class_from_mono_type (field->type)); - if (field_class == target_class || class == field_class || !verify_valuetype_layout_with_target (field_class, target_class)) + if (field_class == target_class || klass == field_class || !verify_valuetype_layout_with_target (field_class, target_class)) return FALSE; } @@ -6214,10 +6219,10 @@ verify_valuetype_layout_with_target (MonoClass *class, MonoClass *target_class) } static gboolean -verify_valuetype_layout (MonoClass *class) +verify_valuetype_layout (MonoClass *klass) { gboolean res; - res = verify_valuetype_layout_with_target (class, class); + res = verify_valuetype_layout_with_target (klass, klass); return res; } @@ -6251,10 +6256,10 @@ recursive_mark_constraint_args (MonoBitSet *used_args, MonoGenericContainer *gc, } static gboolean -verify_generic_parameters (MonoClass *class) +verify_generic_parameters (MonoClass *klass) { int i; - MonoGenericContainer *gc = class->generic_container; + MonoGenericContainer *gc = klass->generic_container; MonoBitSet *used_args = mono_bitset_new (gc->type_argc, 0); for (i = 0; i < gc->type_argc; ++i) { @@ -6271,7 +6276,7 @@ verify_generic_parameters (MonoClass *class) MonoClass *ctr = *constraints; MonoType *constraint_type = &ctr->byval_arg; - if (!mono_class_can_access_class (class, ctr)) + if (!mono_class_can_access_class (klass, ctr)) goto fail; if (!mono_type_is_valid_type_in_context (constraint_type, &gc->context)) @@ -6301,48 +6306,48 @@ fail: * */ gboolean -mono_verifier_verify_class (MonoClass *class) +mono_verifier_verify_class (MonoClass *klass) { /*Neither , object or ifaces have parent.*/ - if (!class->parent && - class != mono_defaults.object_class && - !MONO_CLASS_IS_INTERFACE (class) && - (!image_is_dynamic (class->image) && class->type_token != 0x2000001)) /* is the first type in the assembly*/ + if (!klass->parent && + klass != mono_defaults.object_class && + !MONO_CLASS_IS_INTERFACE (klass) && + (!image_is_dynamic (klass->image) && klass->type_token != 0x2000001)) /* is the first type in the assembly*/ return FALSE; - if (class->parent) { - if (MONO_CLASS_IS_INTERFACE (class->parent)) + if (klass->parent) { + if (MONO_CLASS_IS_INTERFACE (klass->parent)) return FALSE; - if (!class->generic_class && class->parent->generic_container) + if (!klass->generic_class && klass->parent->generic_container) return FALSE; - if (class->parent->generic_class && !class->generic_class) { - MonoGenericContext *context = mono_class_get_context (class); - if (class->generic_container) - context = &class->generic_container->context; - if (!mono_type_is_valid_type_in_context (&class->parent->byval_arg, context)) + if (klass->parent->generic_class && !klass->generic_class) { + MonoGenericContext *context = mono_class_get_context (klass); + if (klass->generic_container) + context = &klass->generic_container->context; + if (!mono_type_is_valid_type_in_context (&klass->parent->byval_arg, context)) return FALSE; } } - if (class->generic_container && (class->flags & TYPE_ATTRIBUTE_LAYOUT_MASK) == TYPE_ATTRIBUTE_EXPLICIT_LAYOUT) + if (klass->generic_container && (klass->flags & TYPE_ATTRIBUTE_LAYOUT_MASK) == TYPE_ATTRIBUTE_EXPLICIT_LAYOUT) return FALSE; - if (class->generic_container && !verify_generic_parameters (class)) + if (klass->generic_container && !verify_generic_parameters (klass)) return FALSE; - if (!verify_class_for_overlapping_reference_fields (class)) + if (!verify_class_for_overlapping_reference_fields (klass)) return FALSE; - if (class->generic_class && !mono_class_is_valid_generic_instantiation (NULL, class)) + if (klass->generic_class && !mono_class_is_valid_generic_instantiation (NULL, klass)) return FALSE; - if (class->generic_class == NULL && !verify_class_fields (class)) + if (klass->generic_class == NULL && !verify_class_fields (klass)) return FALSE; - if (class->valuetype && !verify_valuetype_layout (class)) + if (klass->valuetype && !verify_valuetype_layout (klass)) return FALSE; - if (!verify_interfaces (class)) + if (!verify_interfaces (klass)) return FALSE; return TRUE; } gboolean -mono_verifier_class_is_valid_generic_instantiation (MonoClass *class) +mono_verifier_class_is_valid_generic_instantiation (MonoClass *klass) { - return mono_class_is_valid_generic_instantiation (NULL, class); + return mono_class_is_valid_generic_instantiation (NULL, klass); } gboolean @@ -6356,7 +6361,7 @@ mono_verifier_is_method_valid_generic_instantiation (MonoMethod *method) #else gboolean -mono_verifier_verify_class (MonoClass *class) +mono_verifier_verify_class (MonoClass *klass) { /* The verifier was disabled at compile time */ return TRUE; @@ -6419,7 +6424,7 @@ mono_free_verify_list (GSList *list) } gboolean -mono_verifier_class_is_valid_generic_instantiation (MonoClass *class) +mono_verifier_class_is_valid_generic_instantiation (MonoClass *klass) { return TRUE; }