|
From: <sv...@va...> - 2005-04-02 15:53:05
|
Author: tom
Date: 2005-04-02 16:53:01 +0100 (Sat, 02 Apr 2005)
New Revision: 3503
Added:
trunk/coregrind/amd64-linux/core_platform.c
trunk/coregrind/x86-linux/core_platform.c
Modified:
trunk/coregrind/amd64-linux/Makefile.am
trunk/coregrind/core.h
trunk/coregrind/vg_main.c
trunk/coregrind/vg_redir.c
trunk/coregrind/vg_symtab2.c
trunk/coregrind/x86-linux/Makefile.am
Log:
Add VGP_(setup_redirects) to the platform specific layers and use
it to setup vsyscall redirects on amd64 and the _dl_sysinfo_int80
redirect on x86.
Modified: trunk/coregrind/amd64-linux/Makefile.am
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/amd64-linux/Makefile.am 2005-04-02 15:04:15 UTC (rev =
3502)
+++ trunk/coregrind/amd64-linux/Makefile.am 2005-04-02 15:53:01 UTC (rev =
3503)
@@ -11,6 +11,7 @@
=20
=20
libplatform_a_SOURCES =3D \
+ core_platform.c \
ldt.c \
syscall.S \
syscalls.c
Added: trunk/coregrind/amd64-linux/core_platform.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/amd64-linux/core_platform.c 2005-04-02 15:04:15 UTC (=
rev 3502)
+++ trunk/coregrind/amd64-linux/core_platform.c 2005-04-02 15:53:01 UTC (=
rev 3503)
@@ -0,0 +1,28 @@
+#include "core.h"
+
+/* Rerouted entry point for __NR_gettimeofday */
+static void amd64_linux_rerouted__vgettimeofday(void)
+{
+asm(
+" movq $96, %rax\n"
+" syscall\n"
+);
+}
+
+/* Rerouted entry point for __NR_time */
+static void amd64_linux_rerouted__vtime(void)
+{
+asm(
+" movq $201, %rax\n"
+" syscall\n"
+);
+}
+
+void VGP_(setup_redirects)(void)
+{
+ /* Redirect vsyscalls to local versions */
+ VG_(add_redirect_addr_to_addr)(0xFFFFFFFFFF600000ULL,
+ (Addr)amd64_linux_rerouted__vgettimeof=
day);
+ VG_(add_redirect_addr_to_addr)(0xFFFFFFFFFF600400ULL,
+ (Addr)amd64_linux_rerouted__vtime);
+}
Modified: trunk/coregrind/core.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/core.h 2005-04-02 15:04:15 UTC (rev 3502)
+++ trunk/coregrind/core.h 2005-04-02 15:53:01 UTC (rev 3503)
@@ -915,8 +915,10 @@
/* Redirection machinery */
extern Addr VG_(code_redirect) ( Addr orig );
=20
-extern void VG_(add_redirect_addr)(const Char *from_lib, const Char *fro=
m_sym,
- Addr to_addr);
+extern void VG_(add_redirect_sym_to_addr)(const Char *from_lib,
+ const Char *from_sym,
+ Addr to_addr);
+extern void VG_(add_redirect_addr_to_addr)(Addr from_addr, Addr to_addr)=
;
extern void VG_(resolve_seg_redirs)(SegInfo *si);
extern Bool VG_(resolve_redir)(CodeRedirect *redir, const SegInfo *si);
=20
@@ -1777,6 +1779,10 @@
struct vki_ucontext *uc,
Bool restart);
=20
+/*
+ Do any platform specific redirects.
+ */
+extern void VGP_(setup_redirects)(void);
=20
///* -------------------------------------------------------------------=
--
// Thread modelling
Modified: trunk/coregrind/vg_main.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/vg_main.c 2005-04-02 15:04:15 UTC (rev 3502)
+++ trunk/coregrind/vg_main.c 2005-04-02 15:53:01 UTC (rev 3503)
@@ -2724,6 +2724,7 @@
// p: init_tt_tc [so it can call VG_(search_transtab) safely]
//--------------------------------------------------------------
VG_(setup_code_redirect_table)();
+ VGP_(setup_redirects)();
=20
//--------------------------------------------------------------
// Verbosity message
Modified: trunk/coregrind/vg_redir.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/vg_redir.c 2005-04-02 15:04:15 UTC (rev 3502)
+++ trunk/coregrind/vg_redir.c 2005-04-02 15:53:01 UTC (rev 3503)
@@ -132,6 +132,76 @@
return from_resolved(redir) && to_resolved(redir);
}
=20
+static void add_resolved(CodeRedirect *redir)
+{
+ switch(redir->type) {
+ case R_REDIRECT:
+ if (VG_(clo_trace_redir)) {
+ VG_(message)(Vg_DebugMsg, " redir resolved (%s:%s=3D%p -> ",
+ redir->from_lib, redir->from_sym, redir->from_addr=
);
+ VG_(message)(Vg_DebugMsg, " %s:%s=3D%p)",
+ redir->to_lib, redir->to_sym, redir->to_addr);
+ }
+
+ if (VG_(search_transtab)(NULL, (Addr64)redir->from_addr, False)) {
+ /* For some given (from, to) redir, the "from" function got
+ called before the .so containing "to" became available. We
+ know this because there is already a translation for the
+ entry point of the original "from". So the redirect will
+ never actually take effect unless that translation is
+ discarded. =20
+
+ Note, we only really need to discard the first bb of the
+ old entry point, and so we avoid the problem of having to
+ figure out how big that bb was -- since it is at least 1
+ byte of original code, we can just pass 1 as the original
+ size to invalidate_translations() and it will indeed get
+ rid of the translation.=20
+
+ Note, this is potentially expensive -- discarding
+ translations causes complete unchaining. =20
+ */
+ if (VG_(clo_verbosity) > 2 && VG_(clo_trace_redir)) {
+ VG_(message)(Vg_UserMsg, =20
+ "Discarding translation due to redirect of alre=
ady called function" );
+ VG_(message)(Vg_UserMsg,
+ " %s (%p -> %p)",
+ redir->from_sym, redir->from_addr, redir->to_ad=
dr );
+ }
+ VG_(discard_translations)((Addr64)redir->from_addr, 1);
+ }
+
+ {
+ CodeRedirect *r =3D VG_(SkipList_Find_Exact)(&sk_resolved_redir=
, &redir->from_addr);
+
+ if (r =3D=3D NULL)
+ VG_(SkipList_Insert)(&sk_resolved_redir, redir);
+ else {
+ /* XXX leak redir */
+ if (VG_(clo_trace_redir))
+ VG_(message)(Vg_DebugMsg, " redir %s:%s:%p->%s:%s:%p dup=
licated\n",
+ redir->from_lib, redir->from_sym, redir->fro=
m_addr,
+ redir->to_lib, redir->to_sym, redir->to_addr=
);
+ }
+ }
+ break;
+
+ case R_WRAPPER:
+ if (VG_(clo_trace_redir)) {
+ VG_(message)(Vg_DebugMsg, " wrapper resolved (%s:%s=3D%p -> wr=
apper)",
+ redir->from_lib, redir->from_sym, redir->from_addr=
);
+ }
+
+ /* XXX redir leaked */
+ //VG_(wrap_function)(redir->from_addr, redir->wrapper);
+ break;
+
+ case R_CLIENT_WRAPPER:
+ VG_(core_panic)("not implemented");
+ break;
+ }
+}
+
/* Resolve a redir using si if possible, and add it to the resolved
list */
Bool VG_(resolve_redir)(CodeRedirect *redir, const SegInfo *si)
@@ -186,75 +256,8 @@
redir->from_lib, redir->from_sym, redir->from_addr,=20
redir->to_lib, redir->to_sym, redir->to_addr);
=20
- if (resolved) {
- switch(redir->type) {
- case R_REDIRECT:
- if (VG_(clo_trace_redir)) {
- VG_(message)(Vg_DebugMsg, " redir resolved (%s:%s=3D%p -> ",
- redir->from_lib, redir->from_sym, redir->from_addr);
- VG_(message)(Vg_DebugMsg, " %s:%s=3D%p)",
- redir->to_lib, redir->to_sym, redir->to_addr);
- }
+ if (resolved) add_resolved(redir);
=20
- if (VG_(search_transtab)(NULL, (Addr64)redir->from_addr, False)) {
- /* For some given (from, to) redir, the "from" function got
- called before the .so containing "to" became available. We
- know this because there is already a translation for the
- entry point of the original "from". So the redirect will
- never actually take effect unless that translation is
- discarded. =20
-
- Note, we only really need to discard the first bb of the
- old entry point, and so we avoid the problem of having to
- figure out how big that bb was -- since it is at least 1
- byte of original code, we can just pass 1 as the original
- size to invalidate_translations() and it will indeed get
- rid of the translation.=20
-
- Note, this is potentially expensive -- discarding
- translations causes complete unchaining. =20
- */
- if (VG_(clo_verbosity) > 2 && VG_(clo_trace_redir)) {
- VG_(message)(Vg_UserMsg, =20
- "Discarding translation due to redirect of already called functio=
n" );
- VG_(message)(Vg_UserMsg,
- " %s (%p -> %p)",
- redir->from_sym, redir->from_addr, redir->to_addr );
- }
- VG_(discard_translations)((Addr64)redir->from_addr, 1);
- }
-
- {
- CodeRedirect *r =3D VG_(SkipList_Find_Exact)(&sk_resolved_redir, &r=
edir->from_addr);
-
- if (r =3D=3D NULL)
- VG_(SkipList_Insert)(&sk_resolved_redir, redir);
- else {
- /* XXX leak redir */
- if (VG_(clo_trace_redir))
- VG_(message)(Vg_DebugMsg, " redir %s:%s:%p->%s:%s:%p duplicated\n",
- redir->from_lib, redir->from_sym, redir->from_addr,
- redir->to_lib, redir->to_sym, redir->to_addr);
- }
- }
- break;
-
- case R_WRAPPER:
- if (VG_(clo_trace_redir)) {
- VG_(message)(Vg_DebugMsg, " wrapper resolved (%s:%s=3D%p -> wrappe=
r)",
- redir->from_lib, redir->from_sym, redir->from_addr);
- }
-
- /* XXX redir leaked */
- //VG_(wrap_function)(redir->from_addr, redir->wrapper);
- break;
-
- case R_CLIENT_WRAPPER:
- VG_(core_panic)("not implemented");
- break;
- }
- }
-
return resolved;
}
=20
@@ -285,8 +288,8 @@
}
=20
/* Redirect a lib/symbol reference to a function at lib/symbol */
-static void add_redirect_sym(const Char *from_lib, const Char *from_sym,
- const Char *to_lib, const Char *to_sym)
+static void add_redirect_sym_to_sym(const Char *from_lib, const Char *fr=
om_sym,
+ const Char *to_lib, const Char *to_sym)
{
CodeRedirect *redir =3D VG_(SkipNode_Alloc)(&sk_resolved_redir);
=20
@@ -315,8 +318,8 @@
}
=20
/* Redirect a lib/symbol reference to a function at addr */
-void VG_(add_redirect_addr)(const Char *from_lib, const Char *from_sym,
- Addr to_addr)
+void VG_(add_redirect_sym_to_addr)(const Char *from_lib, const Char *fro=
m_sym,
+ Addr to_addr)
{
CodeRedirect *redir =3D VG_(SkipNode_Alloc)(&sk_resolved_redir);
=20
@@ -330,6 +333,11 @@
redir->to_sym =3D NULL;
redir->to_addr =3D to_addr;
=20
+ if (VG_(clo_verbosity) >=3D 2 && VG_(clo_trace_redir))
+ VG_(message)(Vg_UserMsg,=20
+ "REDIRECT %s(%s) to %p",
+ from_lib, from_sym, to_addr);
+
/* Check against all existing segments to see if this redirection
can be resolved immediately */
if (!VG_(resolve_redir_allsegs)(redir)) {
@@ -339,6 +347,29 @@
}
}
=20
+/* Redirect a function at from_addr to a function at to_addr */
+void VG_(add_redirect_addr_to_addr)(Addr from_addr, Addr to_addr)
+{
+ CodeRedirect *redir =3D VG_(SkipNode_Alloc)(&sk_resolved_redir);
+
+ redir->type =3D R_REDIRECT;
+
+ redir->from_lib =3D NULL;
+ redir->from_sym =3D NULL;
+ redir->from_addr =3D from_addr;
+
+ redir->to_lib =3D NULL;
+ redir->to_sym =3D NULL;
+ redir->to_addr =3D to_addr;
+
+ if (VG_(clo_verbosity) >=3D 2 && VG_(clo_trace_redir))
+ VG_(message)(Vg_UserMsg,=20
+ "REDIRECT %p to %p",
+ from_addr, to_addr);
+
+ add_resolved(redir);
+}
+
CodeRedirect *VG_(add_wrapper)(const Char *from_lib, const Char *from_sy=
m,
const FuncWrapper *wrapper)
{
@@ -371,45 +402,12 @@
return redir;
}
=20
-/* HACK! This should be done properly (see ~/NOTES.txt) */
-#ifdef __amd64__
-/* Rerouted entry points for __NR_vgettimeofday and __NR_vtime.
- 96 =3D=3D __NR_gettimeofday
- 201 =3D=3D __NR_time
-*/
-static void amd64_linux_rerouted__vgettimeofday(void)
-{
-asm(
-" movq $96, %rax\n"
-" syscall\n"
-);
-}
-
-static void amd64_linux_rerouted__vtime(void)
-{
-asm(
-" movq $201, %rax\n"
-" syscall\n"
-);
-}
-#endif
-
/* If address 'a' is being redirected, return the redirected-to
address. */
Addr VG_(code_redirect)(Addr a)
{
CodeRedirect* r;
=20
-#ifdef __amd64__
- /* HACK. Reroute the amd64-linux vsyscalls. This should be moved
- out of here into an amd64-linux specific initialisation routine.
- */
- if (a =3D=3D 0xFFFFFFFFFF600000ULL)
- return (Addr)amd64_linux_rerouted__vgettimeofday;
- if (a =3D=3D 0xFFFFFFFFFF600400ULL)
- return (Addr)amd64_linux_rerouted__vtime;
-#endif
-
r =3D VG_(SkipList_Find_Exact)(&sk_resolved_redir, &a);
if (r =3D=3D NULL)
return a;
@@ -421,41 +419,34 @@
=20
void VG_(setup_code_redirect_table) ( void )
{
- /* Redirect _dl_sysinfo_int80, which is glibc's default system call
- routine, to the routine in our trampoline page so that the
- special sysinfo unwind hack in vg_execontext.c will kick in.
- */
- VG_(add_redirect_addr)("soname:ld-linux.so.2", "_dl_sysinfo_int80",
- VG_(client_trampoline_code)+VG_(tramp_syscall_offset));
- =20
/* 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.
*/
- add_redirect_sym("soname:libc.so.6", "stpcpy",
- "*vgpreload_memcheck.so*", "stpcpy");
+ add_redirect_sym_to_sym("soname:libc.so.6", "stpcpy",
+ "*vgpreload_memcheck.so*", "stpcpy");
=20
- add_redirect_sym("soname:libc.so.6", "strlen",
- "*vgpreload_memcheck.so*", "strlen");
+ add_redirect_sym_to_sym("soname:libc.so.6", "strlen",
+ "*vgpreload_memcheck.so*", "strlen");
=20
- add_redirect_sym("soname:libc.so.6", "strnlen",
- "*vgpreload_memcheck.so*", "strnlen");
+ add_redirect_sym_to_sym("soname:libc.so.6", "strnlen",
+ "*vgpreload_memcheck.so*", "strnlen");
=20
- add_redirect_sym("soname:ld-linux.so.2", "stpcpy",
- "*vgpreload_memcheck.so*", "stpcpy");
- add_redirect_sym("soname:libc.so.6", "stpcpy",
- "*vgpreload_memcheck.so*", "stpcpy");
+ add_redirect_sym_to_sym("soname:ld-linux.so.2", "stpcpy",
+ "*vgpreload_memcheck.so*", "stpcpy");
+ add_redirect_sym_to_sym("soname:libc.so.6", "stpcpy",
+ "*vgpreload_memcheck.so*", "stpcpy");
=20
- add_redirect_sym("soname:libc.so.6", "strchr",
- "*vgpreload_memcheck.so*", "strchr");
- add_redirect_sym("soname:ld-linux.so.2", "strchr",
- "*vgpreload_memcheck.so*", "strchr");
+ add_redirect_sym_to_sym("soname:libc.so.6", "strchr",
+ "*vgpreload_memcheck.so*", "strchr");
+ add_redirect_sym_to_sym("soname:ld-linux.so.2", "strchr",
+ "*vgpreload_memcheck.so*", "strchr");
=20
- add_redirect_sym("soname:libc.so.6", "strchrnul",
- "*vgpreload_memcheck.so*", "glibc232_strchrnul");
+ add_redirect_sym_to_sym("soname:libc.so.6", "strchrnul",
+ "*vgpreload_memcheck.so*", "glibc232_strchrnu=
l");
=20
- add_redirect_sym("soname:libc.so.6", "rawmemchr",
- "*vgpreload_memcheck.so*", "glibc232_rawmemchr");
+ add_redirect_sym_to_sym("soname:libc.so.6", "rawmemchr",
+ "*vgpreload_memcheck.so*", "glibc232_rawmemch=
r");
}
=20
=20
Modified: trunk/coregrind/vg_symtab2.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/vg_symtab2.c 2005-04-02 15:04:15 UTC (rev 3502)
+++ trunk/coregrind/vg_symtab2.c 2005-04-02 15:53:01 UTC (rev 3503)
@@ -865,7 +865,7 @@
while(*func !=3D ':') func--;
*func =3D '\0';
=20
- VG_(add_redirect_addr)(lib, func+1, si->offset + sym->st_value);
+ VG_(add_redirect_sym_to_addr)(lib, func+1, si->offset + sym->st_value=
);
VG_(arena_free)(VG_AR_SYMTAB, lib);
}
=20
Modified: trunk/coregrind/x86-linux/Makefile.am
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/x86-linux/Makefile.am 2005-04-02 15:04:15 UTC (rev 35=
02)
+++ trunk/coregrind/x86-linux/Makefile.am 2005-04-02 15:53:01 UTC (rev 35=
03)
@@ -11,6 +11,7 @@
=20
=20
libplatform_a_SOURCES =3D \
+ core_platform.c \
ldt.c \
syscall.S \
syscalls.c
Added: trunk/coregrind/x86-linux/core_platform.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/x86-linux/core_platform.c 2005-04-02 15:04:15 UTC (re=
v 3502)
+++ trunk/coregrind/x86-linux/core_platform.c 2005-04-02 15:53:01 UTC (re=
v 3503)
@@ -0,0 +1,11 @@
+#include "core.h"
+
+void VGP_(setup_redirects)(void)
+{
+ /* Redirect _dl_sysinfo_int80, which is glibc's default system call
+ routine, to the routine in our trampoline page so that the
+ special sysinfo unwind hack in vg_execontext.c will kick in.
+ */
+ VG_(add_redirect_sym_to_addr)("soname:ld-linux.so.2", "_dl_sysinfo_in=
t80",
+ VG_(client_trampoline_code)+VG_(tramp_s=
yscall_offset));
+}
|