2005-12-12 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mono / mini / mini-trampolines.c
index 8ae36a17d774600fd0988e2b7d4a2d551846724d..45dff5640a3224cb0656d5453cfd6c55f8073372 100644 (file)
@@ -14,7 +14,7 @@
 #include "mini.h"
 
 /**
- * magic_trampoline:
+ * mono_magic_trampoline:
  *
  *   This trampoline handles calls from JITted code.
  */
@@ -27,11 +27,8 @@ mono_magic_trampoline (gssize *regs, guint8 *code, MonoMethod *m, guint8* tramp)
        addr = mono_compile_method (m);
        g_assert (addr);
 
-       //printf ("ENTER: %s\n", mono_method_full_name (m, TRUE));
-
        /* the method was jumped to */
        if (!code)
-               /* FIXME: Optimize the case when the call is from a delegate wrapper */
                return addr;
 
        vtable_slot = mono_arch_get_vcall_slot_addr (code, (gpointer*)regs);
@@ -43,7 +40,7 @@ mono_magic_trampoline (gssize *regs, guint8 *code, MonoMethod *m, guint8* tramp)
                g_assert (*vtable_slot);
 
                if (mono_aot_is_got_entry (code, (guint8*)vtable_slot) || mono_domain_owns_vtable_slot (mono_domain_get (), vtable_slot))
-                       *vtable_slot = addr;
+                       *vtable_slot = mono_get_addr_from_ftnptr (addr);
        }
        else {
                /* Patch calling code */
@@ -51,7 +48,7 @@ mono_magic_trampoline (gssize *regs, guint8 *code, MonoMethod *m, guint8* tramp)
                MonoJitInfo *ji = 
                        mono_jit_info_table_find (mono_domain_get (), code);
                MonoJitInfo *target_ji = 
-                       mono_jit_info_table_find (mono_domain_get (), addr);
+                       mono_jit_info_table_find (mono_domain_get (), mono_get_addr_from_ftnptr (addr));
 
                if (mono_method_same_domain (ji, target_ji))
                        mono_arch_patch_callsite (code, addr);
@@ -61,7 +58,7 @@ mono_magic_trampoline (gssize *regs, guint8 *code, MonoMethod *m, guint8* tramp)
 }
 
 /*
- * aot_trampoline:
+ * mono_aot_trampoline:
  *
  *   This trampoline handles calls made from AOT code. We try to bypass the 
  * normal JIT compilation logic to avoid loading the metadata for the method.
@@ -78,9 +75,9 @@ mono_aot_trampoline (gssize *regs, guint8 *code, guint8 *token_info,
        gpointer *vtable_slot;
        gboolean is_got_entry;
 
-       image = *(gpointer*)token_info;
+       image = *(gpointer*)(gpointer)token_info;
        token_info += sizeof (gpointer);
-       token = *(guint32*)token_info;
+       token = *(guint32*)(gpointer)token_info;
 
        addr = mono_aot_get_method_from_token (mono_domain_get (), image, token);
        if (!addr) {
@@ -135,3 +132,26 @@ mono_class_init_trampoline (gssize *regs, guint8 *code, MonoVTable *vtable, guin
        if (!mono_running_on_valgrind ())
                mono_arch_nullify_class_init_trampoline (code, regs);
 }
+
+#ifdef MONO_ARCH_HAVE_CREATE_DELEGATE_TRAMPOLINE
+
+/**
+ * mono_delegate_trampoline:
+ *
+ *   This trampoline handles calls made from the delegate invoke wrapper. It patches
+ * the function address inside the delegate.
+ */
+gpointer
+mono_delegate_trampoline (gssize *regs, guint8 *code, MonoMethod *m, guint8* tramp)
+{
+       gpointer addr;
+
+       addr = mono_compile_method (m);
+       g_assert (addr);
+
+       mono_arch_patch_delegate_trampoline (code, tramp, regs, addr);
+
+       return addr;
+}
+
+#endif