Wed May 8 12:06:14 CEST 2002 Paolo Molaro <lupus@ximian.com>
[mono.git] / mono / metadata / icall.c
index f0031fe2e7f956e4e90948db0aacdb0b692ad947..cd140f804176b67c6eedcfe0519218d6f6c7a103 100644 (file)
@@ -31,6 +31,7 @@
 #include <mono/metadata/tokentype.h>
 #include <mono/metadata/unicode.h>
 #include <mono/metadata/appdomain.h>
+#include <mono/metadata/gc.h>
 #include <mono/metadata/rand.h>
 #include <mono/metadata/sysmath.h>
 #include <mono/metadata/debug-symfile.h>
@@ -1297,7 +1298,7 @@ ves_icall_Type_GetMethods (MonoReflectionType *type, guint32 bflags)
        MonoMethod *method;
        MonoObject *member;
        int i, len, match;
-
+               
        domain = ((MonoObject *)type)->vtable->domain;
        klass = startklass = mono_class_from_mono_type (type->type);
 
@@ -1344,6 +1345,7 @@ handle_parent:
        for (; tmp; tmp = tmp->next, ++i)
                mono_array_set (res, gpointer, i, tmp->data);
        g_slist_free (l);
+
        return res;
 }
 
@@ -1601,6 +1603,7 @@ ves_icall_System_Reflection_Assembly_GetType (MonoReflectionAssembly *assembly,
                g_list_free (info.modifiers);
                if (throwOnError) /* uhm: this is a parse error, though... */
                        mono_raise_exception (mono_get_exception_type_load ());
+               /*g_print ("failed parse\n");*/
                return NULL;
        }
 
@@ -1610,9 +1613,10 @@ ves_icall_System_Reflection_Assembly_GetType (MonoReflectionAssembly *assembly,
        if (!type) {
                if (throwOnError)
                        mono_raise_exception (mono_get_exception_type_load ());
+               /* g_print ("failed find\n"); */
                return NULL;
        }
-       /*g_print ("got it\n");*/
+       /* g_print ("got it\n"); */
        return mono_type_get_object (domain, type);
 
 }
@@ -1644,6 +1648,18 @@ ves_icall_System_MonoType_getFullName (MonoReflectionType *object)
        return res;
 }
 
+static void
+ves_icall_System_Reflection_Assembly_FillName (MonoReflectionAssembly *assembly, MonoReflectionAssemblyName *aname)
+{
+       MonoAssemblyName *name = &assembly->assembly->aname;
+
+       if (strcmp (name->name, "corlib") == 0)
+               aname->name = mono_string_new (mono_object_domain (assembly), "mscorlib");
+       else
+               aname->name = mono_string_new (mono_object_domain (assembly), name->name);
+       aname->major = name->major;
+}
+
 static MonoArray*
 ves_icall_System_Reflection_Assembly_GetTypes (MonoReflectionAssembly *assembly, MonoBoolean exportedOnly)
 {
@@ -1700,6 +1716,7 @@ ves_icall_ModuleBuilder_create_modified_type (MonoReflectionTypeBuilder *tb, Mon
                        }
                        isbyref = 1;
                        p++;
+                       g_free (str);
                        return mono_type_get_object (mono_domain_get (), &klass->this_arg);
                        break;
                case '*':
@@ -1799,8 +1816,16 @@ ves_icall_System_CurrentTimeZone_GetTimeZoneData (guint32 year, MonoArray **data
        start.tm_year = year-1900;
 
        t = mktime (&start);
-       gmtoff = start.tm_gmtoff;
-
+#if defined (HAVE_TIMEZONE)
+#define gmt_offset(x) (-1 * (((timezone / 60 / 60) - daylight) * 100))
+#elif defined (HAVE_TM_GMTOFF)
+#define gmt_offset(x) x.tm_gmtoff
+#else
+#error Neither HAVE_TIMEZONE nor HAVE_TM_GMTOFF defined. Rerun autoheader, autoconf, etc.
+#endif
+       
+       gmtoff = gmt_offset (start);
+       
        MONO_CHECK_ARG_NULL (data);
        MONO_CHECK_ARG_NULL (names);
 
@@ -1814,7 +1839,8 @@ ves_icall_System_CurrentTimeZone_GetTimeZoneData (guint32 year, MonoArray **data
                tt = *localtime (&t);
 
                /* Daylight saving starts or ends here. */
-               if (tt.tm_gmtoff != gmtoff) {
+               if (gmt_offset (tt) != gmtoff) {
+                       char tzone[10];
                        struct tm tt1;
                        time_t t1;
 
@@ -1823,33 +1849,35 @@ ves_icall_System_CurrentTimeZone_GetTimeZoneData (guint32 year, MonoArray **data
                        do {
                                t1 -= 3600;
                                tt1 = *localtime (&t1);
-                       } while (tt1.tm_gmtoff != gmtoff);
+                       } while (gmt_offset (tt1) != gmtoff);
 
                        /* Try to find the exact minute when daylight saving starts/ends. */
                        do {
                                t1 += 60;
                                tt1 = *localtime (&t1);
-                       } while (tt1.tm_gmtoff == gmtoff);
-
+                       } while (gmt_offset (tt1) == gmtoff);
+                       
+                       strftime (tzone, 10, "%Z", &tt);
+                       
                        /* Write data, if we're already in daylight saving, we're done. */
                        if (is_daylight) {
-                               mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tt.tm_zone));
+                               mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tzone));
                                mono_array_set ((*data), gint64, 1, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
                                return 1;
                        } else {
-                               mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tt.tm_zone));
+                               mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tzone));
                                mono_array_set ((*data), gint64, 0, ((gint64)t1 + EPOCH_ADJUST) * 10000000L);
                                is_daylight = 1;
                        }
 
                        /* This is only set once when we enter daylight saving. */
                        mono_array_set ((*data), gint64, 2, (gint64)gmtoff * 10000000L);
-                       mono_array_set ((*data), gint64, 3, (gint64)(tt.tm_gmtoff - gmtoff) * 10000000L);
+                       mono_array_set ((*data), gint64, 3, (gint64)(gmt_offset (tt) - gmtoff) * 10000000L);
 
-                       gmtoff = tt.tm_gmtoff;
+                       gmtoff = gmt_offset (tt);
                }
 
-               gmtoff = tt.tm_gmtoff;
+               gmtoff = gmt_offset (tt);
        }
        return 1;
 #else
@@ -2061,10 +2089,11 @@ ves_icall_System_Environment_GetEnvironmentVariableNames (void)
        return names;
 }
 
-static MonoString *
-ves_icall_System_Environment_GetCommandLine (void)
+static void
+ves_icall_System_Environment_Exit (int result)
 {
-       return NULL;    /* FIXME */
+       /* we may need to do some cleanup here... */
+       exit (result);
 }
 
 static void
@@ -2089,6 +2118,7 @@ ves_icall_IsTransparentProxy (MonoObject *proxy)
        return 0;
 }
 
+
 /* icall map */
 
 static gconstpointer icall_map [] = {
@@ -2124,40 +2154,40 @@ static gconstpointer icall_map [] = {
         * System.String
         */
        
-       "System.String::.ctor(char*)", mono_string_Internal_ctor_charp,
-       "System.String::.ctor(char*,uint,uint)", mono_string_Internal_ctor_charp_int_int,
-       "System.String::.ctor(sbyte*)", mono_string_Internal_ctor_sbytep,
-       "System.String::.ctor(sbyte*,uint,uint)", mono_string_Internal_ctor_sbytep_int_int,
-       "System.String::.ctor(sbyte*,uint,uint,System.Text.Encoding)", mono_string_Internal_ctor_encoding,
-       "System.String::.ctor(char[])", mono_string_Internal_ctor_chara,
-       "System.String::.ctor(char[],uint,uint)", mono_string_Internal_ctor_chara_int_int,
-       "System.String::.ctor(char,uint)", mono_string_Internal_ctor_char_int,
-       "System.String::InternalEquals", mono_string_InternalEquals,
-       "System.String::InternalJoin", mono_string_InternalJoin,
-       "System.String::InternalInsert", mono_string_InternalInsert,
-       "System.String::InternalReplace(char,char)", mono_string_InternalReplaceChar,
-       "System.String::InternalReplace(string,string)", mono_string_InternalReplaceStr,
-       "System.String::InternalRemove", mono_string_InternalRemove,
-       "System.String::InternalCopyTo", mono_string_InternalCopyTo,
-       "System.String::InternalSplit", mono_string_InternalSplit,
-       "System.String::InternalTrim", mono_string_InternalTrim,
-       "System.String::InternalIndexOf(char,uint,uint)", mono_string_InternalIndexOfChar,
-       "System.String::InternalIndexOf(string,uint,uint)", mono_string_InternalIndexOfStr,
-       "System.String::InternalIndexOfAny", mono_string_InternalIndexOfAny,
-       "System.String::InternalLastIndexOf(char,uint,uint)", mono_string_InternalLastIndexOfChar,
-       "System.String::InternalLastIndexOf(string,uint,uint)", mono_string_InternalLastIndexOfStr,
-       "System.String::InternalLastIndexOfAny", mono_string_InternalLastIndexOfAny,
-       "System.String::InternalPad", mono_string_InternalPad,
-       "System.String::InternalToLower", mono_string_InternalToLower,
-       "System.String::InternalToUpper", mono_string_InternalToUpper,
-       "System.String::InternalAllocateStr", mono_string_InternalAllocateStr,
-       "System.String::InternalStrcpy(string,uint,string)", mono_string_InternalStrcpyStr,
-       "System.String::InternalStrcpy(string,uint,string,uint,uint)", mono_string_InternalStrcpyStrN,
-       "System.String::InternalIntern", mono_string_intern,
-       "System.String::InternalIsInterned", mono_string_is_interned,
-       "System.String::InternalCompare(string,uint,string,uint,uint,bool)", mono_string_InternalCompareStrN,
-       "System.String::GetHashCode", mono_string_GetHashCode,
-       "System.String::get_Chars", mono_string_get_Chars,
+       "System.String::.ctor(char*)", ves_icall_System_String_ctor_charp,
+       "System.String::.ctor(char*,uint,uint)", ves_icall_System_String_ctor_charp_int_int,
+       "System.String::.ctor(sbyte*)", ves_icall_System_String_ctor_sbytep,
+       "System.String::.ctor(sbyte*,uint,uint)", ves_icall_System_String_ctor_sbytep_int_int,
+       "System.String::.ctor(sbyte*,uint,uint,System.Text.Encoding)", ves_icall_System_String_ctor_encoding,
+       "System.String::.ctor(char[])", ves_icall_System_String_ctor_chara,
+       "System.String::.ctor(char[],uint,uint)", ves_icall_System_String_ctor_chara_int_int,
+       "System.String::.ctor(char,uint)", ves_icall_System_String_ctor_char_int,
+       "System.String::InternalEquals", ves_icall_System_String_InternalEquals,
+       "System.String::InternalJoin", ves_icall_System_String_InternalJoin,
+       "System.String::InternalInsert", ves_icall_System_String_InternalInsert,
+       "System.String::InternalReplace(char,char)", ves_icall_System_String_InternalReplace_Char,
+       "System.String::InternalReplace(string,string)", ves_icall_System_String_InternalReplace_Str,
+       "System.String::InternalRemove", ves_icall_System_String_InternalRemove,
+       "System.String::InternalCopyTo", ves_icall_System_String_InternalCopyTo,
+       "System.String::InternalSplit", ves_icall_System_String_InternalSplit,
+       "System.String::InternalTrim", ves_icall_System_String_InternalTrim,
+       "System.String::InternalIndexOf(char,uint,uint)", ves_icall_System_String_InternalIndexOf_Char,
+       "System.String::InternalIndexOf(string,uint,uint)", ves_icall_System_String_InternalIndexOf_Str,
+       "System.String::InternalIndexOfAny", ves_icall_System_String_InternalIndexOfAny,
+       "System.String::InternalLastIndexOf(char,uint,uint)", ves_icall_System_String_InternalLastIndexOf_Char,
+       "System.String::InternalLastIndexOf(string,uint,uint)", ves_icall_System_String_InternalLastIndexOf_Str,
+       "System.String::InternalLastIndexOfAny", ves_icall_System_String_InternalLastIndexOfAny,
+       "System.String::InternalPad", ves_icall_System_String_InternalPad,
+       "System.String::InternalToLower", ves_icall_System_String_InternalToLower,
+       "System.String::InternalToUpper", ves_icall_System_String_InternalToUpper,
+       "System.String::InternalAllocateStr", ves_icall_System_String_InternalAllocateStr,
+       "System.String::InternalStrcpy(string,uint,string)", ves_icall_System_String_InternalStrcpy_Str,
+       "System.String::InternalStrcpy(string,uint,string,uint,uint)", ves_icall_System_String_InternalStrcpy_StrN,
+       "System.String::InternalIntern", ves_icall_System_String_InternalIntern,
+       "System.String::InternalIsInterned", ves_icall_System_String_InternalIsInterned,
+       "System.String::InternalCompare(string,uint,string,uint,uint,bool)", ves_icall_System_String_InternalCompareStr_N,
+       "System.String::GetHashCode", ves_icall_System_String_GetHashCode,
+       "System.String::get_Chars", ves_icall_System_String_get_Chars,
 
        /*
         * System.AppDomain
@@ -2268,6 +2298,7 @@ static gconstpointer icall_map [] = {
         * System.Threading
         */
        "System.Threading.Thread::Thread_internal", ves_icall_System_Threading_Thread_Thread_internal,
+       "System.Threading.Thread::Thread_free_internal", ves_icall_System_Threading_Thread_Thread_free_internal,
        "System.Threading.Thread::Start_internal", ves_icall_System_Threading_Thread_Start_internal,
        "System.Threading.Thread::Sleep_internal", ves_icall_System_Threading_Thread_Sleep_internal,
        "System.Threading.Thread::CurrentThread_internal", ves_icall_System_Threading_Thread_CurrentThread_internal,
@@ -2299,8 +2330,10 @@ static gconstpointer icall_map [] = {
        "System.Runtime.InteropServices.Marshal::PtrToStringAuto", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAuto,
        "System.Runtime.InteropServices.Marshal::GetLastWin32Error", ves_icall_System_Runtime_InteropServices_Marshal_GetLastWin32Error,
 
+       "System.Reflection.Assembly::LoadFrom", ves_icall_System_Reflection_Assembly_LoadFrom,
        "System.Reflection.Assembly::GetType", ves_icall_System_Reflection_Assembly_GetType,
        "System.Reflection.Assembly::GetTypes", ves_icall_System_Reflection_Assembly_GetTypes,
+       "System.Reflection.Assembly::FillName", ves_icall_System_Reflection_Assembly_FillName,
        "System.Reflection.Assembly::get_code_base", ves_icall_System_Reflection_Assembly_get_code_base,
 
        /*
@@ -2374,12 +2407,22 @@ static gconstpointer icall_map [] = {
        "System.DateTime::GetNow", ves_icall_System_DateTime_GetNow,
        "System.CurrentTimeZone::GetTimeZoneData", ves_icall_System_CurrentTimeZone_GetTimeZoneData,
 
+       /*
+        * System.GC
+        */
+       "System.GC::InternalCollect", ves_icall_System_GC_InternalCollect,
+       "System.GC::GetTotalMemory", ves_icall_System_GC_GetTotalMemory,
+       "System.GC::KeepAlive", ves_icall_System_GC_KeepAlive,
+       "System.GC::ReRegisterForFinalize", ves_icall_System_GC_ReRegisterForFinalize,
+       "System.GC::SuppressFinalize", ves_icall_System_GC_SuppressFinalize,
+       "System.GC::WaitForPendingFinalizers", ves_icall_System_GC_WaitForPendingFinalizers,
+
        /*
         * System.Security.Cryptography calls
         */
 
         "System.Security.Cryptography.RNGCryptoServiceProvider::GetBytes", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_GetBytes,
-        "System.Security.Cryptography.RNG_CryptoServiceProvider::GetNonZeroBytes", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_GetNonZeroBytes,
+        "System.Security.Cryptography.RNGCryptoServiceProvider::GetNonZeroBytes", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_GetNonZeroBytes,
        
        /*
         * System.Buffer
@@ -2450,7 +2493,8 @@ static gconstpointer icall_map [] = {
        "System.Environment::get_NewLine", ves_icall_System_Environment_get_NewLine,
        "System.Environment::GetEnvironmentVariable", ves_icall_System_Environment_GetEnvironmentVariable,
        "System.Environment::GetEnvironmentVariableNames", ves_icall_System_Environment_GetEnvironmentVariableNames,
-       "System.Environment::GetCommandLine", ves_icall_System_Environment_GetCommandLine,
+       "System.Environment::GetCommandLineArgs", mono_runtime_get_main_args,
+       "System.Environment::Exit", ves_icall_System_Environment_Exit,
 
        /*
         * Mono.CSharp.Debugger