Fri Feb 1 16:03:53 CET 2002 Paolo Molaro <lupus@ximian.com>
authorPaolo Molaro <lupus@oddwiz.org>
Fri, 1 Feb 2002 11:22:35 +0000 (11:22 -0000)
committerPaolo Molaro <lupus@oddwiz.org>
Fri, 1 Feb 2002 11:22:35 +0000 (11:22 -0000)
* interp.c: exception fixes. Use mono_method_pointer_get ()
to easy porting to other archs. Some support for overflow detection.

Fri Feb 1 16:03:00 CET 2002 Paolo Molaro <lupus@ximian.com>

* x86/tramp.c, ppc/tramp.c: implement mono_method_pointer_get ().

Fri Feb 1 16:13:20 CET 2002 Paolo Molaro <lupus@ximian.com>

* class.c: add asserts if we are ever going to scribble over memory.
* socket-io.c: not all systems have AF_IRDA defined.

svn path=/trunk/mono/; revision=2223

mono/arch/ChangeLog
mono/arch/ppc/tramp.c
mono/arch/x86/tramp.c
mono/interpreter/ChangeLog
mono/interpreter/interp.c
mono/interpreter/interp.h
mono/metadata/ChangeLog
mono/metadata/class.c
mono/metadata/socket-io.c

index 2be310938b3659dba7f3737aa858c01a81cd1b38..7c572e75abb7b439c6b39d5a523de6f65f9fe0fb 100644 (file)
@@ -1,3 +1,8 @@
+
+Fri Feb 1 16:03:00 CET 2002 Paolo Molaro <lupus@ximian.com>
+
+       * x86/tramp.c, ppc/tramp.c: implement mono_method_pointer_get ().
+
 2002-01-23  Miguel de Icaza  <miguel@ximian.com>
 
        * x86/tramp.c (mono_create_trampoline): Do not try to create a
index 8d7efae81e5d1658493f213009a044308016f0f2..871686e3a99bcfa0b5fcec98674b67835c7c77e9 100644 (file)
@@ -559,3 +559,14 @@ mono_create_method_pointer (MonoMethod *method)
 }
 
 
+/*
+ * mono_create_method_pointer () will insert a pointer to the MonoMethod
+ * so that the interp can easily get at the data: this function will retrieve 
+ * the method from the code stream.
+ */
+MonoMethod*
+mono_method_pointer_get (void *code)
+{
+       return NULL;
+}
+
index a94a863031714652ddd0028d5e417d942b72ce68..93e2664497e095cd17635d9397db8e02b10497da 100644 (file)
@@ -484,4 +484,16 @@ mono_create_method_pointer (MonoMethod *method)
        return g_memdup (code_buffer, p - code_buffer);
 }
 
-
+/*
+ * mono_create_method_pointer () will insert a pointer to the MonoMethod
+ * so that the interp can easily get at the data: this function will retrieve 
+ * the method from the code stream.
+ */
+MonoMethod*
+mono_method_pointer_get (void *code)
+{
+       unsigned char *c = code;
+       if (c [2] != 'M' || c [3] != 'o')
+               return NULL;
+       return *(MonoMethod**)(code + sizeof (gpointer));
+}
index 46bdc43b789916cea23540535c1333c62cab20af..6441215c77169a2564f1bf4da21ae0ac5fb0892e 100644 (file)
@@ -1,3 +1,9 @@
+
+Fri Feb 1 16:03:53 CET 2002 Paolo Molaro <lupus@ximian.com>
+
+       * interp.c: exception fixes. Use mono_method_pointer_get ()
+       to easy porting to other archs. Some support for overflow detection.
+
 2002-01-25  Dietmar Maurer  <dietmar@ximian.com>
 
        * interp.c, jit.c (main): install runtime_exec_main handler
index 30e3517ebcd6365ae89921debdbd0f8faf161ad2..26dac2014ee3c94fc25e38c081086b6f87a45eca 100644 (file)
@@ -514,8 +514,8 @@ ves_runtime_method (MonoInvocation *frame)
                MonoMethod *method;
                
                code = (guchar*)delegate->method_ptr;
-               g_assert (code [2] == 'M' && code [3] == 'o');
-               method = *(gpointer*)(code + sizeof (gpointer));
+               method = mono_method_pointer_get (code);
+               /* FIXME: check for NULL method */
                if (!method->addr)
                        method->addr = mono_create_trampoline (method, 1);
                func = method->addr;
@@ -756,6 +756,20 @@ verify_method (MonoMethod *m)
        mono_free_verify_list (errors);
 }
 
+#define CHECK_ADD_OVERFLOW(a,b) \
+       (gint32)(b) >= 0 ? (gint32)(INT_MAX) - (gint32)(b) < (gint32)(a) ? -1 : 0       \
+       : (gint32)(INT_MIN) - (gint32)(b) > (gint32)(a) ? +1 : 0
+
+#define CHECK_ADD_OVERFLOW_UN(a,b) \
+       (guint32)(UINT_MAX) - (guint32)(b) < (guint32)(a) ? -1 : 0
+
+#define CHECK_ADD_OVERFLOW64(a,b) \
+       (gint64)(b) >= 0 ? (gint64)(LLONG_MAX) - (gint64)(b) < (gint64)(a) ? -1 : 0     \
+       : (gint64)(LLONG_MIN) - (gint64)(b) > (gint64)(a) ? +1 : 0
+
+#define CHECK_ADD_OVERFLOW64_UN(a,b) \
+       (guint64)(ULONG_MAX) - (guint64)(b) < (guint64)(a) ? -1 : 0
+
 /*
  * Need to optimize ALU ops when natural int == int32 
  *
@@ -1128,9 +1142,8 @@ ves_exec_method (MonoInvocation *frame)
                                unsigned char *code;
                                --sp;
                                code = sp->data.p;
-                               /* check the signature we put in mono_create_method_pointer () */
-                               g_assert (code [2] == 'M' && code [3] == 'o');
-                               child_frame.method = *(gpointer*)(code + sizeof (gpointer));
+                               child_frame.method = mono_method_pointer_get (code);
+                               /* check for NULL with native code */
                                csignature = child_frame.method->signature;
                        } else {
                                child_frame.method = mono_get_method (image, token, NULL);
@@ -2784,20 +2797,24 @@ array_constructed:
                CASE (CEE_CONV_OVF_U) ves_abort(); BREAK;
                CASE (CEE_ADD_OVF)
                CASE (CEE_ADD_OVF_UN)
-                       ++ip;
                        --sp;
                        /* FIXME: check overflow, make unsigned */
-                       if (sp->type == VAL_I32)
-                               sp [-1].data.i += GET_NATI (sp [0]);
-                       else if (sp->type == VAL_I64)
-                               sp [-1].data.l += sp [0].data.l;
-                       else if (sp->type == VAL_DOUBLE)
+                       if (sp->type == VAL_I32) {
+                               if (CHECK_ADD_OVERFLOW_UN (sp [-1].data.i, GET_NATI (sp [0])))
+                                       THROW_EX (get_exception_overflow (), ip);
+                               sp [-1].data.i = (guint32)sp [-1].data.i + (guint32)GET_NATI (sp [0]);
+                       } else if (sp->type == VAL_I64) {
+                               if (CHECK_ADD_OVERFLOW64_UN (sp [-1].data.l, sp [0].data.l))
+                                       THROW_EX (get_exception_overflow (), ip);
+                               sp [-1].data.l = (guint64)sp [-1].data.l + (guint64)sp [0].data.l;
+                       } else if (sp->type == VAL_DOUBLE)
                                sp [-1].data.f += sp [0].data.f;
                        else {
                                char *p = sp [-1].data.p;
                                p += GET_NATI (sp [0]);
                                sp [-1].data.p = p;
                        }
+                       ++ip;
                        BREAK;
                CASE (CEE_MUL_OVF)
                        ++ip;
@@ -2833,6 +2850,7 @@ array_constructed:
                        BREAK;
                CASE (CEE_LEAVE) /* Fall through */
                CASE (CEE_LEAVE_S)
+                       sp = frame->stack; /* empty the stack */
                        frame->ip = ip;
                        if (*ip == CEE_LEAVE_S) {
                                ++ip;
@@ -2843,6 +2861,7 @@ array_constructed:
                                ip += (gint32) read32 (ip);
                                ip += 4;
                        }
+#if 0
                        /*
                         * We may be either inside a try block or inside an handler.
                         * In the first case there was no exception and we go on
@@ -2858,6 +2877,11 @@ array_constructed:
                                frame->ex = NULL;
                                frame->ex_handler = NULL;
                        }
+#endif
+                       frame->ex = NULL;
+                       frame->ex_handler = NULL;
+                       endfinally_ip = ip;
+                       goto handle_finally;
                        BREAK;
                CASE (CEE_UNUSED26) 
                CASE (CEE_UNUSED27) 
@@ -3501,6 +3525,18 @@ propertybuilder_fields[] = {
        {NULL, 0}
 };
 
+static FieldDesc 
+ilgenerator_fields[] = {
+       {"code", G_STRUCT_OFFSET (MonoReflectionILGen, code)},
+       {"mbuilder", G_STRUCT_OFFSET (MonoReflectionILGen, mbuilder)},
+       {"code_len", G_STRUCT_OFFSET (MonoReflectionILGen, code_len)},
+       {"max_stack", G_STRUCT_OFFSET (MonoReflectionILGen, max_stack)},
+       {"cur_stack", G_STRUCT_OFFSET (MonoReflectionILGen, cur_stack)},
+       {"locals", G_STRUCT_OFFSET (MonoReflectionILGen, locals)},
+       {"ex_handlers", G_STRUCT_OFFSET (MonoReflectionILGen, ex_handlers)},
+       {NULL, 0}
+};
+
 static ClassDesc
 emit_classes_to_check [] = {
        {"TypeBuilder", typebuilder_fields},
@@ -3510,6 +3546,7 @@ emit_classes_to_check [] = {
        {"MethodBuilder", methodbuilder_fields},
        {"FieldBuilder", fieldbuilder_fields},
        {"PropertyBuilder", propertybuilder_fields},
+       {"ILGenerator", ilgenerator_fields},
        {NULL, NULL}
 };
 
index d6e2ebebbc7eafdb02d81bd573bf750e4072da23..da619ca6ac12669780123cc0eef8539a5c5b6530 100644 (file)
@@ -76,3 +76,4 @@ typedef void (*MonoPIFunc) (MonoFunc callme, void *retval, void *obj_this, stack
  */
 MonoPIFunc mono_create_trampoline (MonoMethod *method, int runtime);
 void *mono_create_method_pointer (MonoMethod *method);
+MonoMethod *mono_method_pointer_get (void *code);
index 8e9d7271503fbc79a614e176f4208a73790636bd..595d837b5b9dedfa80951adf0277f4c660d278c2 100644 (file)
@@ -1,3 +1,9 @@
+
+Fri Feb 1 16:13:20 CET 2002 Paolo Molaro <lupus@ximian.com>
+
+       * class.c: add asserts if we are ever going to scribble over memory.
+       * socket-io.c: not all systems have AF_IRDA defined.
+
 2002-01-31  Dietmar Maurer  <dietmar@ximian.com>
 
        * class.c (class_compute_field_layout): do not consider static
index 8b1f9e128106cb2adc9ddded392c8efbe00850be..ce6cd34a15b78a8b6ab181ed88c0f72e3f3c7512 100644 (file)
@@ -353,6 +353,7 @@ mono_class_init (MonoClass *class)
                                                        continue;
                                                if (!strcmp(cm->name, im->name) && 
                                                    mono_metadata_signature_equal (cm->signature, im->signature)) {
+                                                       g_assert (io + l <= class->vtable_size);
                                                        tmp_vtable [io + l] = cm;
                                                }
                                        }
@@ -367,7 +368,7 @@ mono_class_init (MonoClass *class)
                                MonoMethod *im = ic->methods [l];                                               
                                MonoClass *k1;
 
-                               g_assert (io <= class->vtable_size);
+                               g_assert (io + l <= class->vtable_size);
 
                                if (tmp_vtable [io + l] || vtable [io + l])
                                        continue;
@@ -382,11 +383,13 @@ mono_class_init (MonoClass *class)
                                                
                                                if (!strcmp(cm->name, im->name) && 
                                                    mono_metadata_signature_equal (cm->signature, im->signature)) {
+                                                       g_assert (io + l <= class->vtable_size);
                                                        tmp_vtable [io + l] = cm;
                                                        break;
                                                }
                                                
                                        }
+                                       g_assert (io + l <= class->vtable_size);
                                        if (tmp_vtable [io + l])
                                                break;
                                }
@@ -408,6 +411,7 @@ mono_class_init (MonoClass *class)
                                        
                                        if (!strcmp (cm->name, qname) &&
                                            mono_metadata_signature_equal (cm->signature, im->signature)) {
+                                               g_assert (io + l <= class->vtable_size);
                                                tmp_vtable [io + l] = cm;
                                                break;
                                        }
@@ -419,6 +423,7 @@ mono_class_init (MonoClass *class)
                        if (!(class->flags & TYPE_ATTRIBUTE_ABSTRACT)) {
                                for (l = 0; l < ic->method.count; l++) {
                                        MonoMethod *im = ic->methods [l];                                               
+                                       g_assert (io + l <= class->vtable_size);
                                        if (!(tmp_vtable [io + l] || vtable [io + l])) {
                                                printf ("no implementation for interface method %s.%s::%s in class %s.%s\n",
                                                        ic->name_space, ic->name, im->name, class->name_space, class->name);
@@ -437,6 +442,7 @@ mono_class_init (MonoClass *class)
                                MonoMethod *im = tmp_vtable [io + l];
 
                                if (im) {
+                                       g_assert (io + l <= class->vtable_size);
                                        if (im->slot < 0)
                                                im->slot = io + l;
                                        if (!(im->flags & METHOD_ATTRIBUTE_ABSTRACT)) {
@@ -468,6 +474,7 @@ mono_class_init (MonoClass *class)
                                        if (!strcmp(cm->name, m1->name) && 
                                            mono_metadata_signature_equal (cm->signature, m1->signature)) {
                                                cm->slot = k->methods [j]->slot;
+                                               g_assert (cm->slot < class->vtable_size);
                                                break;
                                        }
                                }
index 90de313f3faeef22150008f2dad6306aa43b8f97..117c0eac103d6eb8ff84de449a71999e17874aa4 100644 (file)
@@ -75,11 +75,11 @@ static gint32 convert_family(MonoAddressFamily mono_family)
        case AddressFamily_InterNetworkV6:
                family=AF_INET6;
                break;
-               
+#ifdef AF_IRDA 
        case AddressFamily_Irda:
                family=AF_IRDA;
                break;
-
+#endif
        default:
                g_warning("System.Net.Sockets.AddressFamily has unknown value 0x%x", mono_family);
        }
@@ -124,10 +124,11 @@ static MonoAddressFamily convert_to_mono_family(guint16 af_family)
                family=AddressFamily_InterNetworkV6;
                break;
                
+#ifdef AF_IRDA 
        case AF_IRDA:
                family=AddressFamily_Irda;
                break;
-
+#endif
        default:
                g_warning("unknown address family 0x%x", af_family);
        }