Merge pull request #1122 from PoppermostProductions/master
[mono.git] / mono / metadata / verify.c
index 3c29b116e4c5522eb4a9176455a8c10ee2d8a9c2..b23a830dbcba02f8f2613f96c052ac10499044f9 100644 (file)
@@ -306,8 +306,8 @@ enum {
 
 #ifdef ENABLE_VERIFIER_STATS
 
-#define MEM_ALLOC(amt) do { allocated_memory += (amt); working_set += (amt); } while (0)
-#define MEM_FREE(amt) do { working_set -= (amt); } while (0)
+#define _MEM_ALLOC(amt) do { allocated_memory += (amt); working_set += (amt); } while (0)
+#define _MEM_FREE(amt) do { working_set -= (amt); } while (0)
 
 static int allocated_memory;
 static int working_set;
@@ -338,8 +338,8 @@ init_verifier_stats (void)
 
 #else
 
-#define MEM_ALLOC(amt) do {} while (0)
-#define MEM_FREE(amt) do { } while (0)
+#define _MEM_ALLOC(amt) do {} while (0)
+#define _MEM_FREE(amt) do { } while (0)
 
 #define finish_collect_stats()
 #define init_verifier_stats()
@@ -378,7 +378,7 @@ static MonoType *
 mono_type_create_fnptr_from_mono_method (VerifyContext *ctx, MonoMethod *method)
 {
        MonoType *res = g_new0 (MonoType, 1);
-       MEM_ALLOC (sizeof (MonoType));
+       _MEM_ALLOC (sizeof (MonoType));
 
        //FIXME use mono_method_get_signature_full
        res->data.method = mono_method_signature (method);
@@ -1500,13 +1500,13 @@ ensure_stack_size (ILCodeDesc *stack, int required)
        g_assert (new_size >= required);
 
        tmp = g_new0 (ILStackDesc, new_size);
-       MEM_ALLOC (sizeof (ILStackDesc) * new_size);
+       _MEM_ALLOC (sizeof (ILStackDesc) * new_size);
 
        if (stack->stack) {
                if (stack->size)
                        memcpy (tmp, stack->stack, stack->size * sizeof (ILStackDesc));
                g_free (stack->stack);
-               MEM_FREE (sizeof (ILStackDesc) * stack->max_size);
+               _MEM_FREE (sizeof (ILStackDesc) * stack->max_size);
        }
 
        stack->stack = tmp;
@@ -3219,9 +3219,10 @@ do_invoke_method (VerifyContext *ctx, int method_token, gboolean 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), ctx->constrained_type, TRUE))
+                       if (!mono_metadata_type_equal_full (mono_type_get_type_byval (value->type), mono_type_get_underlying_type (ctx->constrained_type), TRUE))
                                CODE_NOT_VERIFIABLE (ctx, g_strdup_printf ("Object not compatible with constrained type at 0x%04x", ctx->ip_offset));
                        copy.stype |= BOXED_MASK;
+                       copy.type = ctx->constrained_type;
                } else {
                        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));
@@ -4850,19 +4851,19 @@ mono_method_verify (MonoMethod *method, int level)
 
        ctx.code = g_new (ILCodeDesc, ctx.header->code_size);
        ctx.code_size = ctx.header->code_size;
-       MEM_ALLOC (sizeof (ILCodeDesc) * ctx.header->code_size);
+       _MEM_ALLOC (sizeof (ILCodeDesc) * ctx.header->code_size);
 
        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);
-       MEM_ALLOC (sizeof (MonoType*) * ctx.header->num_locals);
+       _MEM_ALLOC (sizeof (MonoType*) * ctx.header->num_locals);
 
        if (ctx.num_locals > 0 && !ctx.header->init_locals)
                CODE_NOT_VERIFIABLE (&ctx, g_strdup_printf ("Method with locals variable but without init locals set"));
 
        ctx.params = g_new (MonoType*, ctx.max_args);
-       MEM_ALLOC (sizeof (MonoType*) * ctx.max_args);
+       _MEM_ALLOC (sizeof (MonoType*) * ctx.max_args);
 
        if (ctx.signature->hasthis)
                ctx.params [0] = method->klass->valuetype ? &method->klass->this_arg : &method->klass->byval_arg;
@@ -5002,7 +5003,7 @@ mono_method_verify (MonoMethod *method, int level)
 
        while (ip < end && ctx.valid) {
                int op_size;
-               ip_offset = ip - code_start;
+               ip_offset = (guint) (ip - code_start);
                {
                        const unsigned char *ip_copy = ip;
                        int op;
@@ -5033,7 +5034,7 @@ mono_method_verify (MonoMethod *method, int level)
                        }
                }
 
-               ctx.ip_offset = ip_offset = ip - code_start;
+               ctx.ip_offset = ip_offset =  (guint) (ip - code_start);
 
                /*We need to check against fallthrou in and out of protected blocks.
                 * For fallout we check the once a protected block ends, if the start flag is not set.