]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Moved call_on_new_stack_0_1 and jump_and_switch_stacks to better places.
authorNicholas Nethercote <njn@valgrind.org>
Sat, 18 Jun 2005 15:54:25 +0000 (15:54 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Sat, 18 Jun 2005 15:54:25 +0000 (15:54 +0000)
This enabled the removal of $ARCH/jmp_with_stack.c, hurrah!

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3938

coregrind/Makefile.am
coregrind/amd64/Makefile.am
coregrind/amd64/jmp_with_stack.c [deleted file]
coregrind/arm/Makefile.am
coregrind/arm/jmp_with_stack.c [deleted file]
coregrind/m_syswrap/syswrap-amd64-linux.c
coregrind/m_syswrap/syswrap-x86-linux.c
coregrind/ume.c
coregrind/ume.h
coregrind/x86/Makefile.am
coregrind/x86/jmp_with_stack.c [deleted file]

index 41061011168387390f5da7002377210d087f704f..be6ea6799f41a1bdd51f389210dbe41843e76c87 100644 (file)
@@ -87,8 +87,7 @@ valgrind_SOURCES = \
        ume.c \
        \
        stage1.c \
-       m_debuglog.c \
-       ${VG_ARCH}/jmp_with_stack.c 
+       m_debuglog.c
 valgrind_DEPENDENCIES =
 valgrind_LDFLAGS=-static -g
 valgrind_LDADD=
index 5453d083c10aac1d07f183bcd20a6d2a507c2f27..ff0495287550671057d9a343989e09beca3a8c6c 100644 (file)
@@ -7,8 +7,7 @@ BUILT_SOURCES = stage2.lds
 CLEANFILES = stage2.lds
 
 libarch_a_SOURCES = \
-       cpuid.S \
-       jmp_with_stack.c
+       cpuid.S
 
 # Extract ld's default linker script and hack it to our needs
 stage2.lds: Makefile
diff --git a/coregrind/amd64/jmp_with_stack.c b/coregrind/amd64/jmp_with_stack.c
deleted file mode 100644 (file)
index 1b7033e..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-
-/*
-   This file is part of Valgrind, a dynamic binary instrumentation
-   framework.
-
-   Copyright (C) 2000-2005 Julian Seward 
-      jseward@acm.org
-
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307, USA.
-
-   The GNU General Public License is contained in the file COPYING.
-*/
-
-#include "ume.h"
-
-
-#define ZERO_ALL_INT_REGS \
-   "   movq $0, %rax\n"  \
-   "   movq $0, %rbx\n"  \
-   "   movq $0, %rcx\n"  \
-   "   movq $0, %rdx\n"  \
-   "   movq $0, %rsi\n"  \
-   "   movq $0, %rdi\n"  \
-   "   movq $0, %rbp\n"  \
-   "   movq $0, %r8\n"   \
-   "   movq $0, %r9\n"   \
-   "   movq $0, %r10\n"  \
-   "   movq $0, %r11\n"  \
-   "   movq $0, %r12\n"  \
-   "   movq $0, %r13\n"  \
-   "   movq $0, %r14\n"  \
-   "   movq $0, %r15\n"
-
-
-/* Jump to 'dst', but first set the stack pointer to 'stack'.  Also,
-   clear all the integer registers before entering 'dst'.  It's
-   important that the stack pointer is set to exactly 'stack' and not
-   (eg) stack - apparently_harmless_looking_small_offset.  Basically
-   because the code at 'dst' might be wanting to scan the area above
-   'stack' (viz, the auxv array), and putting spurious words on the
-   stack confuses it.
-*/
-/*
-__attribute__((noreturn))
-void jump_and_switch_stacks ( Addr stack, Addr dst );
-
-  %rdi == stack
-  %rsi == dst
-*/
-asm(
-".global jump_and_switch_stacks\n"
-"jump_and_switch_stacks:\n"
-"   movq   %rdi, %rsp\n"  /* set stack */
-"   pushq  %rsi\n"        /* f to stack*/
-    ZERO_ALL_INT_REGS
-"   ret\n"                /* jump to f */
-"   ud2\n"                /* should never get here */
-);
-
-
-
-/* Call f(arg1), but first switch stacks, using 'stack' as the new
-   stack, and use 'retaddr' as f's return-to address.  Also, clear all
-   the integer registers before entering f.*/
-/*
-__attribute__((noreturn))
-void call_on_new_stack_0_1 ( Addr stack,
-                            Addr retaddr,
-                            void (*f)(Word),
-                             Word arg1 );
-   %rdi == stack
-   %rsi == retaddr
-   %rdx == f
-   %rcx == arg1
-*/
-asm(
-".global call_on_new_stack_0_1\n"
-"call_on_new_stack_0_1:\n"
-"   movq   %rdi, %rsp\n"  /* set stack */
-"   pushq  %rsi\n"        /* retaddr to stack */
-"   pushq  %rdx\n"        /* f to stack*/
-"   pushq  %rcx\n"        /* arg1 to stack*/
-    ZERO_ALL_INT_REGS
-"   popq   %rdi\n"        /* arg1 to correct arg reg */
-"   ret\n"                /* jump to f */
-"   ud2\n"                /* should never get here */
-);
-
-
-#undef ZERO_ALL_INT_REGS
index 1735781220b9a26f8cdd6bf85ea31ccba5caefb3..3b0144aafa370eba04913166a360096dfea74c6e 100644 (file)
@@ -6,8 +6,7 @@ noinst_LIBRARIES = libarch.a
 BUILT_SOURCES = stage2.lds
 CLEANFILES = stage2.lds
 
-libarch_a_SOURCES = \
-       jmp_with_stack.c
+libarch_a_SOURCES =
 
 # Extract ld's default linker script and hack it to our needs
 stage2.lds: Makefile
diff --git a/coregrind/arm/jmp_with_stack.c b/coregrind/arm/jmp_with_stack.c
deleted file mode 100644 (file)
index 63e2a22..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-
-/*
-   This file is part of Valgrind, a dynamic binary instrumentation
-   framework.
-
-   Copyright (C) 2000-2005 Julian Seward 
-      jseward@acm.org
-
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307, USA.
-
-   The GNU General Public License is contained in the file COPYING.
-*/
-
-#include "ume.h"
-
-void jmp_with_stack(Addr eip, Addr esp)
-{
-   // XXX: temporary only
-extern int printf (__const char *__restrict __format, ...);
-extern void exit (int __status);
-   printf("jmp_with_stack: argh\n");
-   exit(1);
-
-   // XXX: see x86/jmp_with_stack.c for how to implement this
-} 
index d59dcea21050f785752b6919dcbaa36142015c3b..31df7e2efaa575680634bdefbdb89e5fd1538e06 100644 (file)
@@ -29,7 +29,6 @@
 */
 
 #include "core.h"
-#include "ume.h"                /* for jmp_with_stack */
 #include "pub_core_debuglog.h"
 #include "pub_core_aspacemgr.h"
 #include "pub_core_options.h"
@@ -197,6 +196,44 @@ static void run_a_thread_NORETURN ( Word tidW )
 }
 
 
+/* Call f(arg1), but first switch stacks, using 'stack' as the new
+   stack, and use 'retaddr' as f's return-to address.  Also, clear all
+   the integer registers before entering f.  */
+__attribute__((noreturn))
+void call_on_new_stack_0_1 ( Addr stack,
+                            Addr retaddr,
+                            void (*f)(Word),
+                             Word arg1 );
+// %rdi == stack
+// %rsi == retaddr
+// %rdx == f
+// %rcx == arg1
+asm(
+"call_on_new_stack_0_1:\n"
+"   movq   %rdi, %rsp\n"   // set stack
+"   pushq  %rsi\n"         // retaddr to stack
+"   pushq  %rdx\n"         // f to stack
+"   pushq  %rcx\n"         // arg1 to stack
+"   movq $0, %rax\n"       // zero all GP regs
+"   movq $0, %rbx\n" 
+"   movq $0, %rcx\n"
+"   movq $0, %rdx\n"
+"   movq $0, %rsi\n"
+"   movq $0, %rdi\n"
+"   movq $0, %rbp\n"
+"   movq $0, %r8\n"
+"   movq $0, %r9\n"
+"   movq $0, %r10\n"
+"   movq $0, %r11\n"
+"   movq $0, %r12\n"
+"   movq $0, %r13\n"
+"   movq $0, %r14\n"
+"   movq $0, %r15\n"
+"   popq   %rdi\n"         // arg1 to correct arg reg
+"   ret\n"                 // jump to f
+"   ud2\n"                 // should never get here
+);
+
 /*
    Allocate a stack for the main thread, and run it all the way to the
    end.  
index 759abe584fdb5d549f2a828861c2192bcbbb5266..e800393f71cea82af7d73f028477fb4bd0669014 100644 (file)
@@ -34,7 +34,6 @@
 */
 
 #include "core.h"
-#include "ume.h"                /* for jmp_with_stack */
 #include "pub_core_debuglog.h"
 #include "pub_core_aspacemgr.h"
 #include "pub_core_options.h"
@@ -203,6 +202,37 @@ static void run_a_thread_NORETURN ( Word tidW )
 }
 
 
+/* Call f(arg1), but first switch stacks, using 'stack' as the new
+   stack, and use 'retaddr' as f's return-to address.  Also, clear all
+   the integer registers before entering f.*/
+__attribute__((noreturn))
+void call_on_new_stack_0_1 ( Addr stack,
+                            Addr retaddr,
+                            void (*f)(Word),
+                             Word arg1 );
+//  4(%esp) == stack
+//  8(%esp) == retaddr
+// 12(%esp) == f
+// 16(%esp) == arg1
+asm(
+"call_on_new_stack_0_1:\n"
+"   movl %esp, %esi\n"     // remember old stack pointer
+"   movl 4(%esi), %esp\n"  // set stack
+"   pushl 16(%esi)\n"      // arg1 to stack
+"   pushl  8(%esi)\n"      // retaddr to stack
+"   pushl 12(%esi)\n"      // f to stack
+"   movl $0, %eax\n"       // zero all GP regs
+"   movl $0, %ebx\n"
+"   movl $0, %ecx\n"
+"   movl $0, %edx\n"
+"   movl $0, %esi\n"
+"   movl $0, %edi\n"
+"   movl $0, %ebp\n"
+"   ret\n"                 // jump to f
+"   ud2\n"                 // should never get here
+);
+
+
 /*
    Allocate a stack for the main thread, and run it all the way to the
    end.  
index e3b38a238df087c02e9ecbfad4383a757e51fc37..983dfe8a1a994497f8f8acb085eec590c97c697b 100644 (file)
@@ -121,6 +121,61 @@ void foreach_map(int (*fn)(char *start, char *end,
    }
 }
 
+/*------------------------------------------------------------*/
+/*--- Stack switching                                      ---*/
+/*------------------------------------------------------------*/
+
+// __attribute__((noreturn))
+// void jump_and_switch_stacks ( Addr stack, Addr dst );
+#if defined(VGA_x86)
+// 4(%esp) == stack
+// 8(%esp) == dst
+asm(
+".global jump_and_switch_stacks\n"
+"jump_and_switch_stacks:\n"
+"   movl   %esp, %esi\n"      // remember old stack pointer
+"   movl   4(%esi), %esp\n"   // set stack
+"   pushl  8(%esi)\n"         // dst to stack
+"   movl $0, %eax\n"          // zero all GP regs
+"   movl $0, %ebx\n"
+"   movl $0, %ecx\n"
+"   movl $0, %edx\n"
+"   movl $0, %esi\n"
+"   movl $0, %edi\n"
+"   movl $0, %ebp\n"
+"   ret\n"                    // jump to dst
+"   ud2\n"                    // should never get here
+);
+#elif defined(VGA_amd64)
+// %rdi == stack
+// %rsi == dst
+asm(
+".global jump_and_switch_stacks\n"
+"jump_and_switch_stacks:\n"
+"   movq   %rdi, %rsp\n"   // set stack
+"   pushq  %rsi\n"         // dst to stack
+"   movq $0, %rax\n"       // zero all GP regs
+"   movq $0, %rbx\n"
+"   movq $0, %rcx\n"
+"   movq $0, %rdx\n"
+"   movq $0, %rsi\n"
+"   movq $0, %rdi\n"
+"   movq $0, %rbp\n"
+"   movq $0, %r8\n"\
+"   movq $0, %r9\n"\
+"   movq $0, %r10\n"
+"   movq $0, %r11\n"
+"   movq $0, %r12\n"
+"   movq $0, %r13\n"
+"   movq $0, %r14\n"
+"   movq $0, %r15\n"
+"   ret\n"                 // jump to dst
+"   ud2\n"                 // should never get here
+);
+#else
+#  error Unknown architecture
+#endif
+
 /*------------------------------------------------------------*/
 /*--- Finding auxv on the stack                            ---*/
 /*------------------------------------------------------------*/
index 39818e204d6a07c4e09da814ac8b548556ccdba9..a2679c7b78214f5301d146e9bd0f1b15142862ae 100644 (file)
@@ -54,23 +54,14 @@ void foreach_map(int (*fn)(char *start, char *end,
    because the code at 'dst' might be wanting to scan the area above
    'stack' (viz, the auxv array), and putting spurious words on the
    stack confuses it.
+
+   This is only exported so that vgtest_ume.c can use it.
 */
 extern
 __attribute__((noreturn))
 void jump_and_switch_stacks ( Addr stack, Addr dst );
 
 
-/* Call f(arg1), but first switch stacks, using 'stack' as the new
-   stack, and use 'retaddr' as f's return-to address.  Also, clear all
-   the integer registers before entering f.*/
-extern
-__attribute__((noreturn))
-void call_on_new_stack_0_1 ( Addr stack,
-                            Addr retaddr,
-                            void (*f)(Word),
-                             Word arg1 );
-
-
 /*------------------------------------------------------------*/
 /*--- Loading ELF files                                    ---*/
 /*------------------------------------------------------------*/
index 6ed6d13caac68fb61cb4f8f64b07f43626bdbd4f..72a381fb37216671464f199877d9467390fa1f99 100644 (file)
@@ -7,8 +7,7 @@ BUILT_SOURCES = stage2.lds
 CLEANFILES = stage2.lds
 
 libarch_a_SOURCES = \
-       cpuid.S \
-       jmp_with_stack.c
+       cpuid.S
 
 # Extract ld's default linker script and hack it to our needs
 stage2.lds: Makefile
diff --git a/coregrind/x86/jmp_with_stack.c b/coregrind/x86/jmp_with_stack.c
deleted file mode 100644 (file)
index 17ce451..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-
-/*
-   This file is part of Valgrind, a dynamic binary instrumentation
-   framework.
-
-   Copyright (C) 2000-2005 Julian Seward 
-      jseward@acm.org
-
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307, USA.
-
-   The GNU General Public License is contained in the file COPYING.
-*/
-
-#include "ume.h"
-
-
-#define ZERO_ALL_INT_REGS \
-   "   movl $0, %eax\n"  \
-   "   movl $0, %ebx\n"  \
-   "   movl $0, %ecx\n"  \
-   "   movl $0, %edx\n"  \
-   "   movl $0, %esi\n"  \
-   "   movl $0, %edi\n"  \
-   "   movl $0, %ebp\n"
-
-
-/* Jump to 'dst', but first set the stack pointer to 'stack'.  Also,
-   clear all the integer registers before entering 'dst'.  It's
-   important that the stack pointer is set to exactly 'stack' and not
-   (eg) stack - apparently_harmless_looking_small_offset.  Basically
-   because the code at 'dst' might be wanting to scan the area above
-   'stack' (viz, the auxv array), and putting spurious words on the
-   stack confuses it.
-*/
-/*
-__attribute__((noreturn))
-void jump_and_switch_stacks ( Addr stack, Addr dst );
-
-   4(%esp) == stack
-   8(%esp) == f
-*/
-asm(
-".global jump_and_switch_stacks\n"
-"jump_and_switch_stacks:\n"
-"   movl   %esp, %esi\n"    /* remember old stack pointer */
-"   movl   4(%esi), %esp\n" /* set stack */
-"   pushl  8(%esi)\n"       /* f to stack*/
-    ZERO_ALL_INT_REGS
-"   ret\n"                  /* jump to f */
-"   ud2\n"                  /* should never get here */
-);
-
-
-
-/* Call f(arg1), but first switch stacks, using 'stack' as the new
-   stack, and use 'retaddr' as f's return-to address.  Also, clear all
-   the integer registers before entering f.*/
-/*
-__attribute__((noreturn))
-void call_on_new_stack_0_1 ( Addr stack,
-                            Addr retaddr,
-                            void (*f)(Word),
-                             Word arg1 );
-    4(%esp) == stack
-    8(%esp) == retaddr
-   12(%esp) == f
-   16(%esp) == arg1
-*/
-asm(
-".global call_on_new_stack_0_1\n"
-"call_on_new_stack_0_1:\n"
-"   movl %esp, %esi\n"      /* remember old stack pointer */
-"   movl 4(%esi), %esp\n"   /* set stack */
-"   pushl 16(%esi)\n"       /* arg1 to stack */
-"   pushl  8(%esi)\n"       /* retaddr to stack */
-"   pushl 12(%esi)\n"       /* f to stack */
-    ZERO_ALL_INT_REGS
-"   ret\n"                  /* jump to f */
-"   ud2\n"                  /* should never get here */
-);
-
-
-#undef ZERO_ALL_INT_REGS