From 243713971ce7ea50fad27d231fed8dd981da30f7 Mon Sep 17 00:00:00 2001 From: Julian Seward Date: Wed, 2 Mar 2005 14:06:08 +0000 Subject: [PATCH] Minimal, horrible hacks needed to make vsyscalls work on amd64. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3259 --- coregrind/amd64/helpers.S | 8 ++++---- coregrind/vg_main.c | 6 +++--- coregrind/vg_symtab2.c | 17 ++++++++++++++--- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/coregrind/amd64/helpers.S b/coregrind/amd64/helpers.S index 50c4f4553..fc05795fa 100644 --- a/coregrind/amd64/helpers.S +++ b/coregrind/amd64/helpers.S @@ -27,7 +27,6 @@ The GNU General Public License is contained in the file COPYING. */ -#if 0 #include "core_asm.h" /* ------------------ SIMULATED CPU HELPERS ------------------ */ @@ -69,8 +68,10 @@ sigreturn_start: # We can point our sysinfo stuff here .align 16 -syscall_start: - int $0x80 +syscall_start: + /* Rerouted entry point for __NR_vgettimeofday */ + movq $96 /*__NR_gettimeofday*/, %rax + syscall ret tramp_code_end: @@ -86,7 +87,6 @@ VG_(tramp_syscall_offset): /* Let the linker know we don't need an executable stack */ .section .note.GNU-stack,"",@progbits -#endif ##--------------------------------------------------------------------## ##--- end ---## diff --git a/coregrind/vg_main.c b/coregrind/vg_main.c index 0dc668219..46d3683b6 100644 --- a/coregrind/vg_main.c +++ b/coregrind/vg_main.c @@ -1121,7 +1121,7 @@ static Addr setup_client_stack(void* init_sp, // XXX: what architectures is this necessary for? x86 yes, PPC no, others ? // Perhaps a per-arch VGA_NEEDS_TRAMPOLINE constant is necessary? -#ifdef __x86__ +#if defined(__i386__) || defined(__amd64__) /* --- trampoline page --- */ VG_(memcpy)( (void *)VG_(client_trampoline_code), &VG_(trampoline_code_start), VG_(trampoline_code_length) ); @@ -1690,7 +1690,7 @@ static void process_cmd_line_options( UInt* client_auxv, const char* toolname ) // XXX: what architectures is this necessary for? x86 yes, PPC no, others ? #ifdef __x86__ { - Int *auxp; + Word *auxp; for (auxp = client_auxv; auxp[0] != AT_NULL; auxp += 2) { switch(auxp[0]) { case AT_SYSINFO: @@ -2669,7 +2669,7 @@ int main(int argc, char **argv) VG_(parse_procselfmaps) ( build_segment_map_callback ); /* everything */ sp_at_startup___global_arg = 0; -#ifdef __i386__ +#if defined(__i386__) || defined(__amd64__) //-------------------------------------------------------------- // Protect client trampoline page (which is also sysinfo stuff) // p: segment stuff [otherwise get seg faults...] diff --git a/coregrind/vg_symtab2.c b/coregrind/vg_symtab2.c index 67e65cb24..d2d46b693 100644 --- a/coregrind/vg_symtab2.c +++ b/coregrind/vg_symtab2.c @@ -2197,7 +2197,7 @@ Char* VG_(describe_eip)(Addr eip, Char* buf, Int n_buf) Bool know_objname = VG_(get_objname)(eip, buf_obj, M_VG_ERRTXT); Bool know_srcloc = VG_(get_filename_linenum)(eip, buf_srcloc, M_VG_ERRTXT, &lineno); - VG_(sprintf)(ibuf,"0x%x: ", eip); + VG_(sprintf)(ibuf,"0x%llx: ", (ULong)eip); APPEND(ibuf); if (know_fnname) { APPEND(buf_fn); @@ -2495,7 +2495,7 @@ static void add_redirect_sym(const Char *from_lib, const Char *from_sym, } } -/* Redirect a lib/symbol reference to a function at lib/symbol */ +/* Redirect a lib/symbol reference to an addr */ static void add_redirect_addr(const Char *from_lib, const Char *from_sym, Addr to_addr) { @@ -2525,6 +2525,17 @@ Addr VG_(code_redirect)(Addr a) { CodeRedirect *r = VG_(SkipList_Find)(&sk_resolved_redir, &a); +#ifdef __amd64__ + /* HACK. 0xFFFFFFFFFF600000 is the entry point for + __NR_vgettimeofday. Therefore the code at + VG_(client_trampoline_code)+VG_(tramp_syscall_offset) + must be the magic conversion code to turn it into a normal + __NR_gettimeofday call. + */ + if (a == 0xFFFFFFFFFF600000ULL) + return VG_(client_trampoline_code)+VG_(tramp_syscall_offset); +#endif + if (r == NULL || r->from_addr != a) return a; @@ -2561,7 +2572,7 @@ void VG_(setup_code_redirect_table) ( void ) add_redirect_addr("soname:ld-linux.so.2", "_dl_sysinfo_int80", VG_(client_trampoline_code)+VG_(tramp_syscall_offset)); #endif - + /* Overenthusiastic use of PLT bypassing by the glibc people also means we need to patch the following functions to our own implementations of said, in mac_replace_strmem.c.