Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Molaro <lupus@oddwiz.org>2002-02-01 14:22:35 +0300
committerPaolo Molaro <lupus@oddwiz.org>2002-02-01 14:22:35 +0300
commit4163d85e9598b783774634fa63dcc94f0fb93fba (patch)
tree9ac85db3e0d0be41796c51179637471c58c421f3
parent15ded645a59e3e193dd84e718a4c7abf9b023e77 (diff)
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. 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
-rw-r--r--mono/arch/ChangeLog5
-rw-r--r--mono/arch/ppc/tramp.c11
-rw-r--r--mono/arch/x86/tramp.c14
-rw-r--r--mono/interpreter/ChangeLog6
-rw-r--r--mono/interpreter/interp.c59
-rw-r--r--mono/interpreter/interp.h1
-rw-r--r--mono/metadata/ChangeLog6
-rw-r--r--mono/metadata/class.c9
-rw-r--r--mono/metadata/socket-io.c7
9 files changed, 102 insertions, 16 deletions
diff --git a/mono/arch/ChangeLog b/mono/arch/ChangeLog
index 2be310938b3..7c572e75abb 100644
--- a/mono/arch/ChangeLog
+++ b/mono/arch/ChangeLog
@@ -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
diff --git a/mono/arch/ppc/tramp.c b/mono/arch/ppc/tramp.c
index 8d7efae81e5..871686e3a99 100644
--- a/mono/arch/ppc/tramp.c
+++ b/mono/arch/ppc/tramp.c
@@ -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;
+}
+
diff --git a/mono/arch/x86/tramp.c b/mono/arch/x86/tramp.c
index a94a8630317..93e2664497e 100644
--- a/mono/arch/x86/tramp.c
+++ b/mono/arch/x86/tramp.c
@@ -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));
+}
diff --git a/mono/interpreter/ChangeLog b/mono/interpreter/ChangeLog
index 46bdc43b789..6441215c771 100644
--- a/mono/interpreter/ChangeLog
+++ b/mono/interpreter/ChangeLog
@@ -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
diff --git a/mono/interpreter/interp.c b/mono/interpreter/interp.c
index 30e3517ebcd..26dac2014ee 100644
--- a/mono/interpreter/interp.c
+++ b/mono/interpreter/interp.c
@@ -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}
};
diff --git a/mono/interpreter/interp.h b/mono/interpreter/interp.h
index d6e2ebebbc7..da619ca6ac1 100644
--- a/mono/interpreter/interp.h
+++ b/mono/interpreter/interp.h
@@ -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);
diff --git a/mono/metadata/ChangeLog b/mono/metadata/ChangeLog
index 8e9d7271503..595d837b5b9 100644
--- a/mono/metadata/ChangeLog
+++ b/mono/metadata/ChangeLog
@@ -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
diff --git a/mono/metadata/class.c b/mono/metadata/class.c
index 8b1f9e12810..ce6cd34a15b 100644
--- a/mono/metadata/class.c
+++ b/mono/metadata/class.c
@@ -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;
}
}
diff --git a/mono/metadata/socket-io.c b/mono/metadata/socket-io.c
index 90de313f3fa..117c0eac103 100644
--- a/mono/metadata/socket-io.c
+++ b/mono/metadata/socket-io.c
@@ -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);
}