2009-12-09 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mono / metadata / icall.c
index 6842bb4c01b4329500602201cfd6be0a3351e931..20e4ebb4ff0c51a7bf6899d5350010f065f15166 100644 (file)
@@ -24,7 +24,7 @@
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
-#if defined (PLATFORM_WIN32)
+#if defined (HOST_WIN32)
 #include <stdlib.h>
 #endif
 
@@ -75,8 +75,7 @@
 #include <mono/utils/mono-string.h>
 #include <mono/utils/mono-error-internals.h>
 
-
-#if defined (PLATFORM_WIN32)
+#if defined (HOST_WIN32)
 #include <windows.h>
 #include <shlobj.h>
 #endif
@@ -4182,7 +4181,7 @@ ves_icall_System_Reflection_Assembly_get_code_base (MonoReflectionAssembly *asse
 
        replace_shadow_path (domain, dirname, &absolute);
        g_free (dirname);
-#if PLATFORM_WIN32
+#if HOST_WIN32
        {
                gint i;
                for (i = strlen (absolute) - 1; i >= 0; i--)
@@ -4194,7 +4193,7 @@ ves_icall_System_Reflection_Assembly_get_code_base (MonoReflectionAssembly *asse
                uri = g_filename_to_uri (absolute, NULL, NULL);
        } else {
                const char *prepend = "file://";
-#if PLATFORM_WIN32
+#if HOST_WIN32
                if (*absolute == '/' && *(absolute + 1) == '/') {
                        prepend = "file:";
                } else {
@@ -4703,7 +4702,8 @@ ves_icall_GetCurrentMethod (void)
 {
        MonoMethod *m = mono_method_get_last_managed ();
 
-       MONO_ARCH_SAVE_REGS;
+       while (m->is_inflated)
+               m = ((MonoMethodInflated*)m)->declaring;
 
        return mono_method_get_object (mono_domain_get (), m, NULL);
 }
@@ -4870,7 +4870,7 @@ fill_reflection_assembly_name (MonoDomain *domain, MonoReflectionAssemblyName *a
 
                codebase = g_strdup (absolute);
 
-#if PLATFORM_WIN32
+#if HOST_WIN32
                {
                        gint i;
                        for (i = strlen (codebase) - 1; i >= 0; i--)
@@ -5281,7 +5281,7 @@ ves_icall_System_Reflection_Module_GetGuidInternal (MonoReflectionModule *module
 static gpointer
 ves_icall_System_Reflection_Module_GetHINSTANCE (MonoReflectionModule *module)
 {
-#ifdef PLATFORM_WIN32
+#ifdef HOST_WIN32
        if (module->image && module->image->is_module_handle)
                return module->image->raw_data;
 #endif
@@ -5763,7 +5763,7 @@ ves_icall_System_Delegate_SetMulticastInvoke (MonoDelegate *this)
  */
 #define FILETIME_ADJUST ((guint64)504911232000000000LL)
 
-#ifdef PLATFORM_WIN32
+#ifdef HOST_WIN32
 /* convert a SYSTEMTIME which is of the form "last thursday in october" to a real date */
 static void
 convert_to_absolute_date(SYSTEMTIME *date)
@@ -5793,7 +5793,7 @@ convert_to_absolute_date(SYSTEMTIME *date)
 }
 #endif
 
-#ifndef PLATFORM_WIN32
+#ifndef HOST_WIN32
 /*
  * Return's the offset from GMT of a local time.
  * 
@@ -5833,7 +5833,7 @@ gmt_offset(struct tm *tm, time_t t)
 static guint32
 ves_icall_System_CurrentSystemTimeZone_GetTimeZoneData (guint32 year, MonoArray **data, MonoArray **names)
 {
-#ifndef PLATFORM_WIN32
+#ifndef HOST_WIN32
        MonoDomain *domain = mono_domain_get ();
        struct tm start, tt;
        time_t t;
@@ -6137,7 +6137,7 @@ ves_icall_System_Environment_get_UserName (void)
 static MonoString *
 ves_icall_System_Environment_get_MachineName (void)
 {
-#if defined (PLATFORM_WIN32)
+#if defined (HOST_WIN32)
        gunichar2 *buf;
        guint32 len;
        MonoString *result;
@@ -6169,7 +6169,7 @@ ves_icall_System_Environment_get_MachineName (void)
 static int
 ves_icall_System_Environment_get_Platform (void)
 {
-#if defined (PLATFORM_WIN32)
+#if defined (TARGET_WIN32)
        /* Win32NT */
        return 2;
 #elif defined(__MACH__)
@@ -6197,7 +6197,7 @@ ves_icall_System_Environment_get_NewLine (void)
 {
        MONO_ARCH_SAVE_REGS;
 
-#if defined (PLATFORM_WIN32)
+#if defined (HOST_WIN32)
        return mono_string_new (mono_domain_get (), "\r\n");
 #else
        return mono_string_new (mono_domain_get (), "\n");
@@ -6248,7 +6248,7 @@ char **environ;
 static MonoArray *
 ves_icall_System_Environment_GetEnvironmentVariableNames (void)
 {
-#ifdef PLATFORM_WIN32
+#ifdef HOST_WIN32
        MonoArray *names;
        MonoDomain *domain;
        MonoString *str;
@@ -6341,8 +6341,8 @@ static void
 ves_icall_System_Environment_InternalSetEnvironmentVariable (MonoString *name, MonoString *value)
 {
        MonoError error;
+#ifdef HOST_WIN32
 
-#ifdef PLATFORM_WIN32
        gunichar2 *utf16_name, *utf16_value;
 #else
        gchar *utf8_name, *utf8_value;
@@ -6350,7 +6350,7 @@ ves_icall_System_Environment_InternalSetEnvironmentVariable (MonoString *name, M
 
        MONO_ARCH_SAVE_REGS;
        
-#ifdef PLATFORM_WIN32
+#ifdef HOST_WIN32
        utf16_name = mono_string_to_utf16 (name);
        if ((value == NULL) || (mono_string_length (value) == 0) || (mono_string_chars (value)[0] == 0)) {
                SetEnvironmentVariable (utf16_name, NULL);
@@ -6412,7 +6412,7 @@ ves_icall_System_Environment_GetGacPath (void)
 static MonoString*
 ves_icall_System_Environment_GetWindowsFolderPath (int folder)
 {
-#if defined (PLATFORM_WIN32)
+#if defined (HOST_WIN32)
        #ifndef CSIDL_FLAG_CREATE
                #define CSIDL_FLAG_CREATE       0x8000
        #endif
@@ -6585,7 +6585,7 @@ ves_icall_System_Environment_get_HasShutdownStarted (void)
 static void
 ves_icall_System_Environment_BroadcastSettingChange (void)
 {
-#ifdef PLATFORM_WIN32
+#ifdef HOST_WIN32
        SendMessageTimeout (HWND_BROADCAST, WM_SETTINGCHANGE, NULL, L"Environment", SMTO_ABORTIFHUNG, 2000, 0);
 #endif
 }
@@ -6764,7 +6764,7 @@ ves_icall_System_Configuration_DefaultConfig_get_machine_config_path (void)
 
        path = g_build_path (G_DIR_SEPARATOR_S, mono_get_config_dir (), "mono", mono_get_runtime_info ()->framework_version, "machine.config", NULL);
 
-#if defined (PLATFORM_WIN32)
+#if defined (HOST_WIN32)
        /* Avoid mixing '/' and '\\' */
        {
                gint i;
@@ -6804,7 +6804,7 @@ ves_icall_System_Web_Util_ICalls_get_machine_install_dir (void)
 
        path = g_path_get_dirname (mono_get_config_dir ());
 
-#if defined (PLATFORM_WIN32)
+#if defined (HOST_WIN32)
        /* Avoid mixing '/' and '\\' */
        {
                gint i;
@@ -6856,10 +6856,10 @@ ves_icall_System_Diagnostics_Debugger_IsAttached_internal (void)
 static void
 ves_icall_System_Diagnostics_DefaultTraceListener_WriteWindowsDebugString (MonoString *message)
 {
-#if defined (PLATFORM_WIN32)
+#if defined (HOST_WIN32)
        OutputDebugString (mono_string_chars (message));
 #else
-       g_warning ("WriteWindowsDebugString called and PLATFORM_WIN32 not defined!\n");
+       g_warning ("WriteWindowsDebugString called and HOST_WIN32 not defined!\n");
 #endif
 }
 
@@ -6883,7 +6883,7 @@ ves_icall_System_Activator_CreateInstanceInternal (MonoReflectionType *type)
 }
 
 static MonoReflectionMethod *
-ves_icall_MonoMethod_get_base_definition (MonoReflectionMethod *m)
+ves_icall_MonoMethod_get_base_method (MonoReflectionMethod *m, gboolean definition)
 {
        MonoClass *klass, *parent;
        MonoMethod *method = m->method;
@@ -6903,13 +6903,19 @@ ves_icall_MonoMethod_get_base_definition (MonoReflectionMethod *m)
        if (klass->generic_class)
                klass = klass->generic_class->container_class;
 
-       /* At the end of the loop, klass points to the eldest class that has this virtual function slot. */
-       for (parent = klass->parent; parent != NULL; parent = parent->parent) {
-               mono_class_setup_vtable (parent);
-               if (parent->vtable_size <= method->slot)
-                       break;
-               klass = parent;
-       }               
+       if (definition) {
+               /* At the end of the loop, klass points to the eldest class that has this virtual function slot. */
+               for (parent = klass->parent; parent != NULL; parent = parent->parent) {
+                       mono_class_setup_vtable (parent);
+                       if (parent->vtable_size <= method->slot)
+                               break;
+                       klass = parent;
+               }
+       } else {
+               klass = klass->parent;
+               if (!klass)
+                       return m;
+       }
 
        if (klass == method->klass)
                return m;
@@ -6954,16 +6960,6 @@ mono_ArgIterator_Setup (MonoArgIterator *iter, char* argsp, char* start)
                iter->args = start;
        } else {
                iter->args = argsp + sizeof (gpointer);
-#ifndef MONO_ARCH_REGPARMS
-               {
-               guint32 i, arg_size;
-               gint32 align;
-               for (i = 0; i < iter->sig->sentinelpos; ++i) {
-                       arg_size = mono_type_stack_size (iter->sig->params [i], &align);
-                       iter->args = (char*)iter->args + arg_size;
-               }
-               }
-#endif
        }
        iter->num_args = iter->sig->param_count - iter->sig->sentinelpos;
 
@@ -7828,7 +7824,7 @@ mono_create_icall_signature (const char *sigstr)
        res = mono_metadata_signature_alloc (mono_defaults.corlib, len - 1);
        res->pinvoke = 1;
 
-#ifdef PLATFORM_WIN32
+#ifdef HOST_WIN32
        /* 
         * Under windows, the default pinvoke calling convention is STDCALL but
         * we need CDECL.