* test-9.il: New test, test instaniating a class
[mono.git] / mono / metadata / icall.c
index d7f1a64b056e270f57cd43b1ec5af0f9ec74ae71..594b1bbddb366cc5ae0f0e5cfb525a24d7681a79 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <mono/metadata/object.h>
 #include <mono/metadata/threads.h>
+#include <mono/metadata/monitor.h>
 #include <mono/metadata/reflection.h>
 #include <mono/metadata/assembly.h>
 #include <mono/metadata/tabledefs.h>
@@ -49,6 +50,7 @@
 
 static MonoReflectionAssembly* ves_icall_System_Reflection_Assembly_GetCallingAssembly (void);
 
+
 static MonoString *
 mono_double_ToStringImpl (double value)
 {
@@ -768,6 +770,14 @@ ves_icall_AssemblyBuilder_getDataChunk (MonoReflectionAssemblyBuilder *assb, Mon
        return count;
 }
 
+static void
+ves_icall_AssemblyBuilder_build_metadata (MonoReflectionAssemblyBuilder *assb)
+{
+       MONO_ARCH_SAVE_REGS;
+
+       mono_image_build_metadata (assb);
+}
+
 static MonoReflectionType*
 ves_icall_type_from_name (MonoString *name,
                          MonoBoolean throwOnError,
@@ -806,24 +816,6 @@ ves_icall_type_from_name (MonoString *name,
        if (!info.assembly.name && !type) /* try mscorlib */
                type = mono_reflection_get_type (NULL, &info, ignoreCase);
 
-       if (!type) {
-               MonoReflectionAssembly *assembly;
-               char *fullName;
-
-               if (info.name_space)
-                       fullName = g_strdup_printf ("%s.%s", info.name_space, info.name);
-               else
-                       fullName = g_strdup (info.name);
-               assembly = 
-                       mono_domain_try_type_resolve (
-                               mono_domain_get (),
-                               (MonoObject*)mono_string_new (mono_domain_get (), fullName));
-               if (assembly)
-                       type = mono_reflection_get_type (assembly->assembly->image, 
-                                                                                        &info, ignoreCase);
-               g_free (fullName);
-       }
-
        g_free (str);
        g_list_free (info.modifiers);
        g_list_free (info.nested);
@@ -1427,7 +1419,9 @@ ves_icall_InternalExecute (MonoReflectionMethod *method, MonoObject *this, MonoA
                                        } else 
                                                *((gpointer *)this + k->fields [i].offset) = val;
                                
-                                       g_assert (result);
+                                       out_args = mono_array_new (domain, mono_defaults.object_class, 0);
+                                       *outArgs = out_args;
+
                                        g_free (str);
                                        return NULL;
                                }
@@ -2263,7 +2257,7 @@ static MonoObject*
 ves_icall_System_Reflection_Assembly_GetFilesInternal (MonoReflectionAssembly *assembly, MonoString *name) 
 {
        MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_FILE];
-       MonoArray *result;
+       MonoArray *result = NULL;
        int i;
        const char *val;
        char *n;
@@ -2346,7 +2340,9 @@ ves_icall_System_Reflection_Assembly_GetEntryAssembly (void)
 
        MONO_ARCH_SAVE_REGS;
 
-       g_assert (domain->entry_assembly);
+       if (!domain->entry_assembly)
+               domain = mono_root_domain;
+
        return mono_assembly_get_object (domain, domain->entry_assembly);
 }
 
@@ -2576,6 +2572,7 @@ ves_icall_System_CurrentTimeZone_GetTimeZoneData (guint32 year, MonoArray **data
 
        long int gmtoff;
        int is_daylight = 0, day;
+       char tzone[10];
 
        MONO_ARCH_SAVE_REGS;
 
@@ -2612,7 +2609,6 @@ ves_icall_System_CurrentTimeZone_GetTimeZoneData (guint32 year, MonoArray **data
 
                /* Daylight saving starts or ends here. */
                if (gmt_offset (tt) != gmtoff) {
-                       char tzone[10];
                        struct tm tt1;
                        time_t t1;
 
@@ -2651,6 +2647,17 @@ ves_icall_System_CurrentTimeZone_GetTimeZoneData (guint32 year, MonoArray **data
 
                gmtoff = gmt_offset (tt);
        }
+
+       if (!is_daylight) {
+               strftime (tzone, 10, "%Z", &tt);
+               mono_array_set ((*names), gpointer, 0, mono_string_new (domain, tzone));
+               mono_array_set ((*names), gpointer, 1, mono_string_new (domain, tzone));
+               mono_array_set ((*data), gint64, 0, 0);
+               mono_array_set ((*data), gint64, 1, 0);
+               mono_array_set ((*data), gint64, 2, (gint64) gmtoff * 10000000L);
+               mono_array_set ((*data), gint64, 3, 0);
+       }
+
        return 1;
 #else
        MonoDomain *domain = mono_domain_get ();
@@ -2976,6 +2983,36 @@ ves_icall_IsTransparentProxy (MonoObject *proxy)
        return 0;
 }
 
+static void
+ves_icall_System_Runtime_Activation_ActivationServices_EnableProxyActivation (MonoReflectionType *type, MonoBoolean enable)
+{
+       MonoClass *klass;
+       MonoVTable* vtable;
+
+       MONO_ARCH_SAVE_REGS;
+
+       klass = mono_class_from_mono_type (type->type);
+       vtable = mono_class_vtable (mono_domain_get (), klass);
+
+       if (enable) vtable->remote = 1;
+       else vtable->remote = 0;
+}
+
+static MonoObject *
+ves_icall_System_Runtime_Activation_ActivationServices_AllocateUninitializedClassInstance (MonoReflectionType *type)
+{
+       MonoClass *klass;
+       MonoDomain *domain;
+       
+       MONO_ARCH_SAVE_REGS;
+
+       domain = mono_object_domain (type);
+       klass = mono_class_from_mono_type (type->type);
+
+       // Bypass remoting object creation check
+       return mono_object_new_alloc_specific (mono_class_vtable (domain, klass));
+}
+
 static MonoObject *
 ves_icall_System_Runtime_Serialization_FormatterServices_GetUninitializedObject_Internal (MonoReflectionType *type)
 {
@@ -3014,15 +3051,28 @@ ves_icall_RuntimeMethod_GetFunctionPointer (MonoMethod *method)
        return mono_compile_method (method);
 }
 
-char * mono_cfg_dir = "";
+char const * mono_cfg_dir = "";
 
 void    
-mono_install_get_config_dir()
-{       
+mono_install_get_config_dir (void)
+{
+#ifdef PLATFORM_WIN32
+  int i;
+#endif
+
   mono_cfg_dir = getenv ("MONO_CFG_DIR");
 
-  if (!mono_cfg_dir)
-    mono_cfg_dir = MONO_CFG_DIR; 
+  if (!mono_cfg_dir) {
+#ifndef PLATFORM_WIN32
+    mono_cfg_dir = MONO_CFG_DIR;
+#else
+    mono_cfg_dir = g_strdup (MONO_CFG_DIR);
+    for (i = strlen (mono_cfg_dir) - 1; i >= 0; i--) {
+        if (mono_cfg_dir [i] == '/')
+            mono_cfg_dir [i] = '\\';
+    }
+#endif
+  }
 }
 
 
@@ -3218,8 +3268,13 @@ static gconstpointer icall_map [] = {
        "System.AppDomain::getFriendlyName", ves_icall_System_AppDomain_getFriendlyName,
        "System.AppDomain::GetAssemblies", ves_icall_System_AppDomain_GetAssemblies,
        "System.AppDomain::LoadAssembly", ves_icall_System_AppDomain_LoadAssembly,
-       "System.AppDomain::Unload", ves_icall_System_AppDomain_Unload,
+       "System.AppDomain::InternalUnload", ves_icall_System_AppDomain_InternalUnload,
        "System.AppDomain::ExecuteAssembly", ves_icall_System_AppDomain_ExecuteAssembly,
+       "System.AppDomain::InternalSetDomain", ves_icall_System_AppDomain_InternalSetDomain,
+       "System.AppDomain::InternalSetDomainByID", ves_icall_System_AppDomain_InternalSetDomainByID,
+       "System.AppDomain::InternalSetContext", ves_icall_System_AppDomain_InternalSetContext,
+       "System.AppDomain::InternalGetContext", ves_icall_System_AppDomain_InternalGetContext,
+       "System.AppDomain::InternalGetDefaultContext", ves_icall_System_AppDomain_InternalGetDefaultContext,
 
        /*
         * System.AppDomainSetup
@@ -3268,6 +3323,7 @@ static gconstpointer icall_map [] = {
        "System.Reflection.Emit.AssemblyBuilder::getUSIndex", mono_image_insert_string,
        "System.Reflection.Emit.AssemblyBuilder::getToken", ves_icall_AssemblyBuilder_getToken,
        "System.Reflection.Emit.AssemblyBuilder::basic_init", mono_image_basic_init,
+       "System.Reflection.Emit.AssemblyBuilder::build_metadata", ves_icall_AssemblyBuilder_build_metadata,
 
        /*
         * Reflection stuff.
@@ -3557,6 +3613,9 @@ static gconstpointer icall_map [] = {
        /*
         * System.Math
         */
+       "System.Math::Floor", ves_icall_System_Math_Floor,
+       "System.Math::Round", ves_icall_System_Math_Round,
+       "System.Math::Round2", ves_icall_System_Math_Round2,
        "System.Math::Sin", ves_icall_System_Math_Sin,
         "System.Math::Cos", ves_icall_System_Math_Cos,
         "System.Math::Tan", ves_icall_System_Math_Tan,
@@ -3595,6 +3654,14 @@ static gconstpointer icall_map [] = {
        "System.Runtime.Remoting.RemotingServices::IsTransparentProxy",
        ves_icall_IsTransparentProxy,
 
+       /*
+        * System.Runtime.Remoting.Activation
+        */     
+       "System.Runtime.Remoting.Activation.ActivationServices::AllocateUninitializedClassInstance",
+       ves_icall_System_Runtime_Activation_ActivationServices_AllocateUninitializedClassInstance,
+       "System.Runtime.Remoting.Activation.ActivationServices::EnableProxyActivation",
+       ves_icall_System_Runtime_Activation_ActivationServices_EnableProxyActivation,
+
        /*
         * System.Runtime.Remoting.Messaging
         */     
@@ -3604,7 +3671,7 @@ static gconstpointer icall_map [] = {
        /*
         * System.Runtime.Remoting.Proxies
         */     
-       "System.Runtime.Remoting.Proxies.RealProxy::GetTransparentProxy", 
+       "System.Runtime.Remoting.Proxies.RealProxy::InternalGetTransparentProxy", 
        ves_icall_Remoting_RealProxy_GetTransparentProxy,
 
        /*
@@ -3661,6 +3728,9 @@ static gconstpointer icall_map [] = {
        "System.Reflection.Assembly::MonoDebugger_GetMethod",
        ves_icall_MonoDebugger_GetMethod,
 
+       "System.Reflection.Assembly::MonoDebugger_GetMethodToken",
+       ves_icall_MonoDebugger_GetMethodToken,
+
        "System.Reflection.Assembly::MonoDebugger_GetLocalTypeFromSignature",
        ves_icall_MonoDebugger_GetLocalTypeFromSignature,