2003-09-04 Sebastien Pouliot <spouliot@videotron.ca>
[mono.git] / mono / mini / jit-icalls.c
index 4f6791ec119508ddaf088c298bb47aa915ad410a..02b3dd9b42949b37c6c804ef1813238337b20162 100644 (file)
@@ -17,9 +17,7 @@ mono_ldftn (MonoMethod *method)
 
        MONO_ARCH_SAVE_REGS;
 
-       EnterCriticalSection (metadata_section);
        addr = mono_compile_method (method);
-       LeaveCriticalSection (metadata_section);
 
        return addr;
 }
@@ -77,7 +75,7 @@ helper_stelem_ref (MonoArray *array, int index, MonoObject *val)
 static gint64 
 mono_llmult (gint64 a, gint64 b)
 {
-       MONO_ARCH_SAVE_REGS;
+       /* no need, no exceptions: MONO_ARCH_SAVE_REGS;*/
        return a * b;
 }
 
@@ -182,6 +180,9 @@ mono_llmult_ovf (guint32 al, gint32 ah, guint32 bl, gint32 bh)
 
        res += t1;
 
+       if (res < 0)
+               goto raise_exception;
+
        if (sign < 0)
                return -res;
        else
@@ -229,7 +230,7 @@ mono_lshl (guint64 a, gint32 shamt)
 {
        guint64 res;
 
-       MONO_ARCH_SAVE_REGS;
+       /* no need, no exceptions: MONO_ARCH_SAVE_REGS;*/
        res = a << shamt;
 
        /*printf ("TESTL %lld << %d = %lld\n", a, shamt, res);*/
@@ -242,7 +243,7 @@ mono_lshr_un (guint64 a, gint32 shamt)
 {
        guint64 res;
 
-       MONO_ARCH_SAVE_REGS;
+       /* no need, no exceptions: MONO_ARCH_SAVE_REGS;*/
        res = a >> shamt;
 
        /*printf ("TESTR %lld >> %d = %lld\n", a, shamt, res);*/
@@ -255,7 +256,7 @@ mono_lshr (gint64 a, gint32 shamt)
 {
        gint64 res;
 
-       MONO_ARCH_SAVE_REGS;
+       /* no need, no exceptions: MONO_ARCH_SAVE_REGS;*/
        res = a >> shamt;
 
        /*printf ("TESTR %lld >> %d = %lld\n", a, shamt, res);*/
@@ -274,7 +275,7 @@ ves_array_element_address (MonoArray *this, ...)
 {
        MonoClass *class;
        va_list ap;
-       int i, ind, esize;
+       int i, ind, esize, realidx;
        gpointer ea;
 
        MONO_ARCH_SAVE_REGS;
@@ -285,20 +286,23 @@ ves_array_element_address (MonoArray *this, ...)
 
        class = this->obj.vtable->klass;
 
-       ind = va_arg(ap, int);
        g_assert (this->bounds != NULL);
 
-       ind -= this->bounds [0].lower_bound;
+       esize = mono_array_element_size (class);
+       ind = va_arg(ap, int);
+       ind -= (int)this->bounds [0].lower_bound;
+       if ((guint32)ind >= (guint32)this->bounds [0].length)
+               mono_raise_exception (mono_get_exception_index_out_of_range ());
        for (i = 1; i < class->rank; i++) {
-               ind = ind*this->bounds [i].length + va_arg(ap, int) -
-                       this->bounds [i].lower_bound;;
+               realidx = va_arg(ap, int) - (int)this->bounds [i].lower_bound;
+               if ((guint32)realidx >= (guint32)this->bounds [i].length)
+                       mono_raise_exception (mono_get_exception_index_out_of_range ());
+               ind *= this->bounds [i].length;
+               ind += realidx;
        }
+       esize *= ind;
 
-       if (ind >= this->max_length)
-               mono_raise_exception (mono_get_exception_index_out_of_range ());
-
-       esize = mono_array_element_size (class);
-       ea = (gpointer*)((char*)this->vector + (ind * esize));
+       ea = (gpointer*)((char*)this->vector + esize);
 
        va_end(ap);
 
@@ -345,6 +349,7 @@ static gpointer
 mono_class_static_field_address (MonoDomain *domain, MonoClassField *field)
 {
        MonoVTable *vtable;
+       gpointer addr;
        
        MONO_ARCH_SAVE_REGS;
 
@@ -353,11 +358,17 @@ mono_class_static_field_address (MonoDomain *domain, MonoClassField *field)
        mono_class_init (field->parent);
 
        vtable = mono_class_vtable (domain, field->parent);
+       if (!vtable->initialized)
+               mono_runtime_class_init (vtable);
 
        //printf ("SFLDA1 %p\n", (char*)vtable->data + field->offset);
 
+       if (!domain->thread_static_fields || !(addr = g_hash_table_lookup (domain->thread_static_fields, field)))
+               addr = (char*)vtable->data + field->offset;
+       else
+               addr = mono_threads_get_static_data (GPOINTER_TO_UINT (addr));
        
-       return (char*)vtable->data + field->offset;
+       return addr;
 }
 
 static gpointer
@@ -376,14 +387,14 @@ mono_ldtoken_wrapper (MonoImage *image, int token)
 static guint64
 mono_fconv_u8 (double v)
 {
-       MONO_ARCH_SAVE_REGS;
+       /* no need, no exceptions: MONO_ARCH_SAVE_REGS;*/
        return (guint64)v;
 }
 
 static guint32
 mono_fconv_u4 (double v)
 {
-       MONO_ARCH_SAVE_REGS;
+       /* no need, no exceptions: MONO_ARCH_SAVE_REGS;*/
        return (guint32)v;
 }