2005-12-23 Dick Porter <dick@ximian.com>
[mono.git] / mono / metadata / icall.c
index a71d5d6bfd5c43e6f4b7ce8ab1dfdf2884f4d306..da21fd65346f5d30c5499742710ebbb63641b04a 100644 (file)
@@ -957,6 +957,26 @@ ves_icall_ModuleBuilder_build_metadata (MonoReflectionModuleBuilder *mb)
        mono_image_build_metadata (mb);
 }
 
+static gboolean
+get_caller (MonoMethod *m, gint32 no, gint32 ilo, gboolean managed, gpointer data)
+{
+       MonoMethod **dest = data;
+
+       /* skip unmanaged frames */
+       if (!managed)
+               return FALSE;
+
+       if (m == *dest) {
+               *dest = NULL;
+               return FALSE;
+       }
+       if (!(*dest)) {
+               *dest = m;
+               return TRUE;
+       }
+       return FALSE;
+}
+
 static MonoReflectionType *
 type_from_name (const char *str, MonoBoolean ignoreCase)
 {
@@ -979,10 +999,26 @@ type_from_name (const char *str, MonoBoolean ignoreCase)
        if (info.assembly.name) {
                assembly = mono_assembly_load (&info.assembly, NULL, NULL);
        } else {
-               MonoReflectionAssembly *refass;
+               MonoMethod *m = mono_method_get_last_managed ();
+               MonoMethod *dest = m;
 
-               refass = ves_icall_System_Reflection_Assembly_GetCallingAssembly  ();
-               assembly = refass->assembly;
+               mono_stack_walk_no_il (get_caller, &dest);
+               if (!dest)
+                       dest = m;
+
+               /*
+                * FIXME: mono_method_get_last_managed() sometimes returns NULL, thus
+                *        causing ves_icall_System_Reflection_Assembly_GetCallingAssembly()
+                *        to crash.  This only seems to happen in some strange remoting
+                *        scenarios and I was unable to figure out what's happening there.
+                *        Dec 10, 2005 - Martin.
+                */
+
+               if (dest)
+                       assembly = dest->klass->image->assembly;
+               else {
+                       g_warning (G_STRLOC);
+               }
        }
 
        if (assembly)
@@ -3007,6 +3043,8 @@ ves_icall_Type_GetMethodsByName (MonoReflectionType *type, MonoString *name, gui
                compare_func = (ignore_case) ? g_strcasecmp : strcmp;
        }
 
+       mono_class_setup_vtable (klass);
+
        if (klass->vtable_size >= sizeof (method_slots_default) * 8) {
                method_slots = g_new0 (guint32, klass->vtable_size / 32 + 1);
        } else {
@@ -3476,10 +3514,12 @@ ves_icall_System_Reflection_Assembly_InternalGetType (MonoReflectionAssembly *as
        gchar *str;
        MonoType *type = NULL;
        MonoTypeNameParse info;
-       gboolean type_resolve = FALSE;
+       gboolean type_resolve;
 
        MONO_ARCH_SAVE_REGS;
 
+       /* On MS.NET, this does not fire a TypeResolve event */
+       type_resolve = TRUE;
        str = mono_string_to_utf8 (name);
        /*g_print ("requested type %s in %s\n", str, assembly->assembly->aname.name);*/
        if (!mono_reflection_parse_type (str, &info)) {
@@ -4077,26 +4117,6 @@ ves_icall_System_Reflection_Assembly_GetExecutingAssembly (void)
 }
 
 
-static gboolean
-get_caller (MonoMethod *m, gint32 no, gint32 ilo, gboolean managed, gpointer data)
-{
-       MonoMethod **dest = data;
-
-       /* skip unmanaged frames */
-       if (!managed)
-               return FALSE;
-
-       if (m == *dest) {
-               *dest = NULL;
-               return FALSE;
-       }
-       if (!(*dest)) {
-               *dest = m;
-               return TRUE;
-       }
-       return FALSE;
-}
-
 static MonoReflectionAssembly*
 ves_icall_System_Reflection_Assembly_GetEntryAssembly (void)
 {
@@ -4110,7 +4130,6 @@ ves_icall_System_Reflection_Assembly_GetEntryAssembly (void)
        return mono_assembly_get_object (domain, domain->entry_assembly);
 }
 
-
 static MonoReflectionAssembly*
 ves_icall_System_Reflection_Assembly_GetCallingAssembly (void)
 {
@@ -4146,6 +4165,9 @@ ves_icall_System_MonoType_getFullName (MonoReflectionType *object, gboolean full
        if (!name)
                return NULL;
 
+       if (full_name && (object->type->type == MONO_TYPE_VAR || object->type->type == MONO_TYPE_MVAR))
+               return NULL;
+
        res = mono_string_new (domain, name);
        g_free (name);
 
@@ -6892,17 +6914,20 @@ static const IcallEntry interlocked_icalls [] = {
 
 static const IcallEntry mutex_icalls [] = {
        {"CreateMutex_internal(bool,string,bool&)", ves_icall_System_Threading_Mutex_CreateMutex_internal},
+       {"OpenMutex_internal(string,System.Security.AccessControl.MutexRights,System.IO.MonoIOError&)", ves_icall_System_Threading_Mutex_OpenMutex_internal},
        {"ReleaseMutex_internal(intptr)", ves_icall_System_Threading_Mutex_ReleaseMutex_internal}
 };
 
 static const IcallEntry semaphore_icalls [] = {
        {"CreateSemaphore_internal(int,int,string,bool&)", ves_icall_System_Threading_Semaphore_CreateSemaphore_internal},
+       {"OpenSemaphore_internal(string,System.Security.AccessControl.SemaphoreRights,System.IO.MonoIOError&)", ves_icall_System_Threading_Semaphore_OpenSemaphore_internal},
        {"ReleaseSemaphore_internal(intptr,int,bool&)", ves_icall_System_Threading_Semaphore_ReleaseSemaphore_internal}
 };
 
 static const IcallEntry nativeevents_icalls [] = {
        {"CloseEvent_internal", ves_icall_System_Threading_Events_CloseEvent_internal},
-       {"CreateEvent_internal", ves_icall_System_Threading_Events_CreateEvent_internal},
+       {"CreateEvent_internal(bool,bool,string,bool&)", ves_icall_System_Threading_Events_CreateEvent_internal},
+       {"OpenEvent_internal(string,System.Security.AccessControl.EventWaitHandleRights,System.IO.MonoIOError&)", ves_icall_System_Threading_Events_OpenEvent_internal},
        {"ResetEvent_internal",  ves_icall_System_Threading_Events_ResetEvent_internal},
        {"SetEvent_internal",    ves_icall_System_Threading_Events_SetEvent_internal}
 };