2004-07-02 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mono / mini / tramp-x86.c
index 1a5de180ed019f4cfa7162e189590b6889c61206..51b1f0a28ef79ccb82c05ebbdea94853fb8c7688 100644 (file)
@@ -124,19 +124,12 @@ x86_magic_trampoline (int eax, int ecx, int edx, int esi, int edi,
 
                        /* The first part of the condition means an icall without a wrapper */
                        if ((!target_ji && m->addr) || mono_method_same_domain (ji, target_ji)) {
-                               gboolean do_patch = TRUE;
-
-#ifdef HAVE_VALGRIND_MEMCHECK_H
-                               if (RUNNING_ON_VALGRIND)
-                                       do_patch = FALSE;
-#endif
-
-                               if (do_patch) {
+                               if (!mono_running_on_valgrind ()) {
                                        InterlockedExchange ((gint32*)(code + 2), (guint)addr - ((guint)code + 1) - 5);
 
 #ifdef HAVE_VALGRIND_MEMCHECK_H
                                        /* Tell valgrind to recompile the patched code */
-                                       VALGRIND_DISCARD_TRANSLATIONS (code + 2, code + 6);
+                                       //VALGRIND_DISCARD_TRANSLATIONS (code + 2, code + 6);
 #endif
                                }
                        }
@@ -211,14 +204,7 @@ x86_class_init_trampoline (int eax, int ecx, int edx, int esi, int edi,
 
        code -= 5;
        if (code [0] == 0xe8) {
-               gboolean do_patch = TRUE;
-
-#ifdef HAVE_VALGRIND_MEMCHECK_H
-               if (RUNNING_ON_VALGRIND)
-                       do_patch = FALSE;
-#endif
-
-               if (do_patch) {
+               if (!mono_running_on_valgrind ()) {
                        guint32 ops;
                        /*
                         * Thread safe code patching using the algorithm from the paper
@@ -295,10 +281,10 @@ create_trampoline_code (MonoTrampolineType tramp_type)
        else
                x86_push_membase (buf, X86_ESP, 16);
 
-       x86_push_reg (buf, X86_EBX);
-       x86_push_reg (buf, X86_EDI);
-       x86_push_reg (buf, X86_ESI);
        x86_push_reg (buf, X86_EBP);
+       x86_push_reg (buf, X86_ESI);
+       x86_push_reg (buf, X86_EDI);
+       x86_push_reg (buf, X86_EBX);
 
        /* save method info */
        x86_push_membase (buf, X86_ESP, 32);
@@ -344,10 +330,11 @@ create_trampoline_code (MonoTrampolineType tramp_type)
        /* discard method info */
        x86_pop_reg (buf, X86_ESI);
        /* restore caller saved regs */
-       x86_pop_reg (buf, X86_EBP);
-       x86_pop_reg (buf, X86_ESI);
-       x86_pop_reg (buf, X86_EDI);
        x86_pop_reg (buf, X86_EBX);
+       x86_pop_reg (buf, X86_EDI);
+       x86_pop_reg (buf, X86_ESI);
+       x86_pop_reg (buf, X86_EBP);
+
        /* discard save IP */
        x86_alu_reg_imm (buf, X86_ADD, X86_ESP, 4);             
        /* restore LMF end */