ume.c \
\
stage1.c \
- m_debuglog.c \
- ${VG_ARCH}/jmp_with_stack.c
+ m_debuglog.c
valgrind_DEPENDENCIES =
valgrind_LDFLAGS=-static -g
valgrind_LDADD=
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
+++ /dev/null
-
-/*
- 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
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
+++ /dev/null
-
-/*
- 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
-}
*/
#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"
}
+/* 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.
*/
#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"
}
+/* 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.
}
}
+/*------------------------------------------------------------*/
+/*--- 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 ---*/
/*------------------------------------------------------------*/
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 ---*/
/*------------------------------------------------------------*/
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
+++ /dev/null
-
-/*
- 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