|
From: <sv...@va...> - 2005-12-05 14:27:07
|
Author: sewardj
Date: 2005-12-05 14:26:59 +0000 (Mon, 05 Dec 2005)
New Revision: 5284
Log:
Get back to a buildable state, at least.
Modified:
branches/FNWRAP/coregrind/m_clientstate.c
branches/FNWRAP/coregrind/m_debuginfo/symtab.c
branches/FNWRAP/coregrind/m_main.c
branches/FNWRAP/coregrind/m_mallocfree.c
branches/FNWRAP/coregrind/m_redir.c
branches/FNWRAP/coregrind/m_replacemalloc/vg_replace_malloc.c
branches/FNWRAP/coregrind/m_translate.c
branches/FNWRAP/coregrind/pub_core_clientstate.h
branches/FNWRAP/coregrind/pub_core_debuginfo.h
branches/FNWRAP/coregrind/pub_core_redir.h
branches/FNWRAP/coregrind/vg_preloaded.c
branches/FNWRAP/include/pub_tool_debuginfo.h
branches/FNWRAP/include/pub_tool_redir.h
branches/FNWRAP/memcheck/mac_replace_strmem.c
Modified: branches/FNWRAP/coregrind/m_clientstate.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
--- branches/FNWRAP/coregrind/m_clientstate.c 2005-12-04 23:27:14 UTC (re=
v 5283)
+++ branches/FNWRAP/coregrind/m_clientstate.c 2005-12-05 14:26:59 UTC (re=
v 5284)
@@ -87,7 +87,11 @@
Int VG_(fd_soft_limit) =3D -1;
Int VG_(fd_hard_limit) =3D -1;
=20
+/* Useful addresses extracted from the client */
+/* Where is the __libc_freeres_wrapper routine we made? */
+Addr VG_(client___libc_freeres_wrapper) =3D 0;
=20
+
/*--------------------------------------------------------------------*/
/*--- end ---*/
/*--------------------------------------------------------------------*/
Modified: branches/FNWRAP/coregrind/m_debuginfo/symtab.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
--- branches/FNWRAP/coregrind/m_debuginfo/symtab.c 2005-12-04 23:27:14 UT=
C (rev 5283)
+++ branches/FNWRAP/coregrind/m_debuginfo/symtab.c 2005-12-05 14:26:59 UT=
C (rev 5284)
@@ -29,6 +29,11 @@
The GNU General Public License is contained in the file COPYING.
*/
=20
+/*
+ Stabs reader greatly improved by Nick Nethercote, Apr 02.
+*/
+
+
#include "pub_core_basics.h"
#include "pub_core_threadstate.h"
#include "pub_core_debuginfo.h"
@@ -221,34 +226,6 @@
=20
=20
/*------------------------------------------------------------*/
-/*--- ---*/
-/*------------------------------------------------------------*/
-
-/* Majorly rewritten Sun 3 Feb 02 to enable loading symbols from
- dlopen()ed libraries, which is something that KDE3 does a lot.
-
- Stabs reader greatly improved by Nick Nethercote, Apr 02.
-*/
-
-static void freeSegInfo ( SegInfo* si )
-{
- struct strchunk *chunk, *next;
- vg_assert(si !=3D NULL);
- if (si->filename) VG_(arena_free)(VG_AR_SYMTAB, si->filename);
- if (si->symtab) VG_(arena_free)(VG_AR_SYMTAB, si->symtab);
- if (si->loctab) VG_(arena_free)(VG_AR_SYMTAB, si->loctab);
- if (si->scopetab) VG_(arena_free)(VG_AR_SYMTAB, si->scopetab);
- if (si->cfisi) VG_(arena_free)(VG_AR_SYMTAB, si->cfisi);
-
- for(chunk =3D si->strchunks; chunk !=3D NULL; chunk =3D next) {
- next =3D chunk->next;
- VG_(arena_free)(VG_AR_SYMTAB, chunk);
- }
- VG_(arena_free)(VG_AR_SYMTAB, si);
-}
-
-
-/*------------------------------------------------------------*/
/*--- Adding stuff ---*/
/*------------------------------------------------------------*/
=20
@@ -1213,18 +1190,6 @@
vg_assert(sym_name[0] !=3D 0);
name =3D ML_(addStr) ( si, sym_name, -1 );
vg_assert(name !=3D NULL);
-
- /*
- * Is this symbol a magic valgrind-intercept symbol? If so,
- * hand this off to the redir module. =20
- *
- * Note: this function can change the symbol name just added to
- * the string table. Importantly, it never makes it bigger.
- */
- if (do_intercepts) {
- VG_(maybe_redir_or_notify)( name, sym_addr );
- }
-
risym.addr =3D sym_addr;
risym.size =3D sym->st_size;
risym.name =3D name;
@@ -1775,6 +1740,24 @@
return si;
}
=20
+static void freeSegInfo ( SegInfo* si )
+{
+ struct strchunk *chunk, *next;
+ vg_assert(si !=3D NULL);
+ if (si->filename) VG_(arena_free)(VG_AR_SYMTAB, si->filename);
+ if (si->symtab) VG_(arena_free)(VG_AR_SYMTAB, si->symtab);
+ if (si->loctab) VG_(arena_free)(VG_AR_SYMTAB, si->loctab);
+ if (si->scopetab) VG_(arena_free)(VG_AR_SYMTAB, si->scopetab);
+ if (si->cfisi) VG_(arena_free)(VG_AR_SYMTAB, si->cfisi);
+
+ for(chunk =3D si->strchunks; chunk !=3D NULL; chunk =3D next) {
+ next =3D chunk->next;
+ VG_(arena_free)(VG_AR_SYMTAB, chunk);
+ }
+ VG_(arena_free)(VG_AR_SYMTAB, si);
+}
+
+
SegInfo *VG_(read_seg_symbols) ( Addr seg_addr, SizeT seg_len,
OffT seg_offset, const Char* seg_filena=
me)
{
@@ -1797,8 +1780,8 @@
canonicaliseScopetab ( si );
canonicaliseCfiSI ( si );
=20
- /* do redirects */
- VG_(resolve_existing_redirs_with_seginfo)( si );
+ /* notify m_redir about it */
+ VG_(redir_notify_new_SegInfo)( si );
}
VGP_POPCC(VgpReadSyms);
=20
@@ -1827,6 +1810,7 @@
curr->filename ? curr->filename : (Char *)"???"=
);
vg_assert(*prev_next_ptr =3D=3D curr);
*prev_next_ptr =3D curr->next;
+ VG_(redir_notify_delete_SegInfo)( curr );
freeSegInfo(curr);
return;
}
@@ -1871,35 +1855,6 @@
}
=20
=20
-/* SLOW (Linear search). Try and map a symbol name to an address.
- Since this is searching in the direction opposite to which the
- table is designed we have no option but to do a complete linear
- scan of the table. Returns NULL if not found. */
-
-static Bool hacky_match ( Char* patt, Char* in_symtab )
-{
- Int plen =3D VG_(strlen)(patt);
- Char* p =3D VG_(strstr)(in_symtab, patt);
- if (p =3D=3D NULL) return False;
- if (p[plen] =3D=3D 0 || p[plen] =3D=3D '@') return True;
- return False;
-}
-
-Addr VG_(reverse_search_one_symtab) ( const SegInfo* si, const Char* nam=
e )
-{
- UInt i;
- for (i =3D 0; i < si->symtab_used; i++) {
- if (0)=20
- VG_(printf)("%p %s\n", si->symtab[i].addr, si->symtab[i].name)=
;
- // if (0 =3D=3D VG_(strcmp)(name, si->symtab[i].name))
- // return si->symtab[i].addr;
- if (hacky_match(name, si->symtab[i].name))
- return si->symtab[i].addr;
- }
- return (Addr)NULL;
-}
-
-
/* Search all symtabs that we know about to locate ptr. If found, set
*psi to the relevant SegInfo, and *symno to the symtab entry number
within that. If not found, *psi is set to NULL. */
@@ -2751,13 +2706,16 @@
=20
for(si =3D segInfo_list; si !=3D NULL; si =3D si->next) {
if (a >=3D si->start && a < (si->start + si->size)) {
+
if (0)
- VG_(printf)("addr=3D%p si=3D%p %s got=3D%p %d plt=3D%p %d data=3D%=
p %d bss=3D%p %d\n",
- a, si, si->filename,=20
- si->got_start, si->got_size,
- si->plt_start, si->plt_size,
- si->data_start, si->data_size,
- si->bss_start, si->bss_size);
+ VG_(printf)(
+ "addr=3D%p si=3D%p %s got=3D%p %d plt=3D%p %d data=3D%p =
%d bss=3D%p %d\n",
+ a, si, si->filename,=20
+ si->got_start, si->got_size,
+ si->plt_start, si->plt_size,
+ si->data_start, si->data_size,
+ si->bss_start, si->bss_size);
+
ret =3D Vg_SectText;
=20
if (a >=3D si->data_start && a < (si->data_start + si->data_size))
@@ -2774,6 +2732,24 @@
return ret;
}
=20
+Int VG_(seginfo_syms_howmany) ( const SegInfo *si )
+{
+ return si->symtab_used;
+}
+
+void VG_(seginfo_syms_getidx) ( const SegInfo *si,=20
+ Int idx,
+ /*OUT*/Addr* addr,
+ /*OUT*/UInt* size,
+ /*OUT*/HChar** name )
+{
+ vg_assert(idx >=3D 0 && idx < si->symtab_used);
+ if (addr) *addr =3D si->symtab[idx].addr;
+ if (size) *size =3D si->symtab[idx].size;
+ if (name) *name =3D (HChar*)si->symtab[idx].name;
+}
+
+
/*--------------------------------------------------------------------*/
/*--- end ---*/
/*--------------------------------------------------------------------*/
Modified: branches/FNWRAP/coregrind/m_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
--- branches/FNWRAP/coregrind/m_main.c 2005-12-04 23:27:14 UTC (rev 5283)
+++ branches/FNWRAP/coregrind/m_main.c 2005-12-05 14:26:59 UTC (rev 5284)
@@ -2314,7 +2314,7 @@
// p: aspacem [so can change ownership of sysinfo pages]
//--------------------------------------------------------------
VG_(debugLog)(1, "main", "Initialise redirects\n");
- VG_(setup_code_redirect_table)();
+ VG_(redir_initialise)();
=20
//--------------------------------------------------------------
// Allow GDB attach
@@ -2690,13 +2690,13 @@
*/
static void final_tidyup(ThreadId tid)
{
- Addr __libc_freeres_wrapper;
+ Addr __libc_freeres_wrapper =3D VG_(client___libc_freeres_wrapper);
=20
vg_assert(VG_(is_running_thread)(tid));
=20
if ( !VG_(needs).libc_freeres ||
!VG_(clo_run_libc_freeres) ||
- 0 =3D=3D (__libc_freeres_wrapper =3D VG_(get_libc_freeres_wrappe=
r)()) )
+ 0 =3D=3D __libc_freeres_wrapper )
return; /* can't/won't do it */
=20
if (VG_(clo_verbosity) > 2 ||
@@ -2705,7 +2705,7 @@
VG_(message)(Vg_DebugMsg,=20
"Caught __NR_exit; running __libc_freeres()");
=20
- /* point thread context to point to libc_freeres_wrapper */
+ /* set thread context to point to libc_freeres_wrapper */
VG_(set_IP)(tid, __libc_freeres_wrapper);
// XXX should we use a special stack?
=20
Modified: branches/FNWRAP/coregrind/m_mallocfree.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
--- branches/FNWRAP/coregrind/m_mallocfree.c 2005-12-04 23:27:14 UTC (rev=
5283)
+++ branches/FNWRAP/coregrind/m_mallocfree.c 2005-12-05 14:26:59 UTC (rev=
5284)
@@ -1058,9 +1058,8 @@
=20
b =3D get_payload_block(a, ptr);
=20
-# ifdef DEBUG_MALLOC
- vg_assert(blockSane(a, b));
-# endif
+if (aid !=3D VG_AR_CLIENT)
+vg_assert(blockSane(a, b));
=20
b_bszB =3D get_bszB(b);
b_pszB =3D bszB_to_pszB(a, b_bszB);
@@ -1070,6 +1069,9 @@
=20
a->bytes_on_loan -=3D b_pszB;
=20
+if (aid !=3D VG_AR_CLIENT)
+VG_(memset)(ptr, 0xDD, (SizeT)b_pszB);
+
// Put this chunk back on a list somewhere.
b_listno =3D pszB_to_listNo(b_pszB);
mkFreeBlock( a, b, b_bszB, b_listno );
Modified: branches/FNWRAP/coregrind/m_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
--- branches/FNWRAP/coregrind/m_redir.c 2005-12-04 23:27:14 UTC (rev 5283=
)
+++ branches/FNWRAP/coregrind/m_redir.c 2005-12-05 14:26:59 UTC (rev 5284=
)
@@ -43,6 +43,7 @@
#include "pub_core_trampoline.h"
#include "pub_core_transtab.h"
#include "pub_core_tooliface.h" // VG_(needs).malloc_replacement
+#include "pub_core_aspacemgr.h" // VG_(am_find_nsegment)
=20
/*------------------------------------------------------------*/
/*--- Semantics ---*/
@@ -154,6 +155,11 @@
#define TRACE_REDIR(format, args...) \
if (VG_(clo_trace_redir)) { VG_(message)(Vg_DebugMsg, format, ## args=
); }
=20
+static void* symtab_alloc(SizeT);
+static void symtab_free(void*);
+static HChar* symtab_strdup(HChar*);
+static Bool is_plausible_guest_addr(Addr);
+
/*------------------------------------------------------------*/
/*--- REDIRECTION SPECIFICATIONS ---*/
/*------------------------------------------------------------*/
@@ -219,6 +225,16 @@
/*--- NOTIFICATIONS ---*/
/*------------------------------------------------------------*/
=20
+static=20
+void generate_and_add_actives (=20
+ /* spec list and the owning TopSpec */
+ Spec* specs,=20
+ TopSpec* parent_spec,
+ /* seginfo and the owning TopSpec */
+ SegInfo* si,
+ TopSpec* parent_sym=20
+ );
+
/* Notify m_redir of the arrival of a new SegInfo. This is fairly
complex, but the net effect is to (1) add a new entry to the
topspecs list, and (2) figure out what new binding are now active,
@@ -228,9 +244,13 @@
=20
void VG_(redir_notify_new_SegInfo)( SegInfo* newsi )
{
- TopSpec* ts, newts;
+ Bool ok;
+ Int i, nsyms;
+ Spec* specList;
+ Spec* spec;
+ TopSpec* ts;
+ TopSpec* newts;
HChar* sym_name;
- UInt sym_size;
Addr sym_addr;
HChar demangled_sopatt[N_DEMANGLED];
HChar demangled_fnpatt[N_DEMANGLED];
@@ -295,16 +315,19 @@
/* Case (1) */
for (ts =3D topSpecs; ts; ts =3D ts->next) {
if (ts->seginfo)
- generate_and_add_actives( specList,newts, ts->seginfo );
+ generate_and_add_actives( specList, newts,
+ ts->seginfo, ts );
}
=09
/* Case (2) */
for (ts =3D topSpecs; ts; ts =3D ts->next) {
- generate_and_add_actives( ts->specs,ts, newsi );
+ generate_and_add_actives( ts->specs, ts,=20
+ newsi, newts );
}
=20
/* Case (3) */
- generate_and_add_actives( specList,newts, newsi );
+ generate_and_add_actives( specList, newts,=20
+ newsi, newts );
=20
/* Finally, add the new TopSpec. */
newts->next =3D topSpecs;
@@ -320,18 +343,28 @@
would thereby arise, don't add it, but do complain. */
=20
static=20
-void generate_and_add_actives ( Spec* specs, void* parent_topspec,
- SegInfo* si )
+void generate_and_add_actives (=20
+ /* spec list and the owning TopSpec */
+ Spec* specs,=20
+ TopSpec* parent_spec,
+ /* seginfo and the owning TopSpec */
+ SegInfo* si,
+ TopSpec* parent_sym=20
+ )
{
Spec* sp;
Bool anyMark;
Active act;
+ Int nsyms, i;
+ Addr sym_addr;
+ HChar* sym_name;
=20
/* First figure out which of the specs match the seginfo's
soname. */
anyMark =3D False;
for (sp =3D specs; sp; sp =3D sp->next) {
- sp->mark =3D VG_(string_match)( sp->from_sopatt, si->soname );
+ sp->mark =3D VG_(string_match)( sp->from_sopatt,=20
+ VG_(seginfo_soname)(si) );
anyMark =3D anyMark || sp->mark;
}
=20
@@ -351,8 +384,8 @@
/* got a new binding. Add to collection. */
act.from_addr =3D sym_addr;
act.to_addr =3D sp->to_addr;
- act.parent_spec =3D parent_topspec;
- act.parent_sym =3D si;
+ act.parent_spec =3D parent_spec;
+ act.parent_sym =3D parent_sym;
maybe_add_active( act );
}
}
@@ -362,7 +395,7 @@
=20
/* Add an act (passed by value; is copied here) and deal with
conflicting bindings. */
-static void add_to_active ( Active act )
+static void maybe_add_active ( Active act )
{
Active* old =3D VG_(OSet_Lookup)( activeSet, &act.from_addr );
if (old) {
@@ -378,7 +411,7 @@
/* COMPLAIN if new and old parents differ */
}
} else {
- Active* a =3D VG_(OSet_AllocNode)(active, sizeof(Active));
+ Active* a =3D VG_(OSet_AllocNode)(activeSet, sizeof(Active));
vg_assert(a);
*a =3D act;
VG_(OSet_Insert)(activeSet, a);
@@ -394,6 +427,9 @@
{
TopSpec* ts;
OSet* tmpSet;
+ Active* act;
+ Bool delMe;
+ Addr* addrP;
=20
vg_assert(delsi);
=20
@@ -406,8 +442,8 @@
=20
/* Traverse the actives, copying the addresses of those we intend
to delete into tmpSet. */
- tmpSet =3D VG_(OSet_Create, 0/*keyOff*/, NULL/*fastCmp*/,
- symtab_alloc, symtab_free);
+ tmpSet =3D VG_(OSet_Create)( 0/*keyOff*/, NULL/*fastCmp*/,
+ symtab_alloc, symtab_free);
=20
ts->mark =3D True;
=20
@@ -429,45 +465,101 @@
activeSet. */
VG_(OSet_ResetIter)( tmpSet );
while ( (addrP =3D VG_(OSet_Next)(tmpSet)) ) {
- VG_(OSet_Remove)( activeSet, *addrP );
- VG_(OSet_FreeNode)( activeSet, *addrP );
+ VG_(OSet_Remove)( activeSet, addrP );
+ VG_(OSet_FreeNode)( activeSet, addrP );
}
=20
VG_(OSet_Destroy)( tmpSet );
}
=20
=20
-//////////////////////////////////////////////////////////////////
-//////////////////////////////////////////////////////////////////
+/*------------------------------------------------------------*/
+/*--- QUERIES (really the whole point of this module) ---*/
+/*------------------------------------------------------------*/
=20
-static void* symtab_alloc(SizeT n)
+/* This is the crucial redirection function. It answers the question:
+ should this code address be redirected somewhere else? It's used
+ just before translating a basic block. */
+Addr VG_(redir_do_lookup) ( Addr orig )
{
- return VG_(arena_malloc)(VG_AR_SYMTAB, n);
+ Spec* r =3D VG_(OSet_Lookup)(activeSet, &orig);
+ if (r =3D=3D NULL)
+ return orig;
+
+ vg_assert(r->to_addr !=3D 0);
+ return r->to_addr;
}
=20
-static void symtab_free(void* p)
+
+/*------------------------------------------------------------*/
+/*--- INITIALISATION ---*/
+/*------------------------------------------------------------*/
+
+/* Add a never-delete-me Active. */
+
+__attribute__((unused)) /* only used on amd64 */
+static void add_hardwired_active ( Addr from, Addr to )
{
- return VG_(arena_free)(VG_AR_SYMTAB, p);
+ Active act;
+ act.from_addr =3D from;
+ act.to_addr =3D to;
+ act.parent_spec =3D NULL;
+ act.parent_sym =3D NULL;
+ maybe_add_active( act );
}
=20
+
+/* Add a never-delete-me Spec. This is a bit of a kludge. On the
+ assumption that this is called only at startup, only handle the
+ case where topSpecs is completely empty, or if it isn't, it has
+ just one entry and that is the one with NULL seginfo -- that is the
+ entry that holds these initial specs. */
+
+__attribute__((unused)) /* not used on all platforms */
+static void add_hardwired_spec ( HChar* sopatt, HChar* fnpatt, Addr to_a=
ddr )
+{
+ Spec* spec =3D symtab_alloc(sizeof(Spec));
+ vg_assert(spec);
+
+ if (topSpecs =3D=3D NULL) {
+ topSpecs =3D symtab_alloc(sizeof(TopSpec));
+ vg_assert(topSpecs);
+ topSpecs->next =3D NULL;
+ topSpecs->seginfo =3D NULL;
+ topSpecs->specs =3D NULL;
+ topSpecs->mark =3D False;
+ }
+
+ vg_assert(topSpecs !=3D NULL);
+ vg_assert(topSpecs->next =3D=3D NULL);
+ vg_assert(topSpecs->seginfo =3D=3D NULL);
+
+ spec->from_sopatt =3D sopatt;
+ spec->from_fnpatt =3D fnpatt;
+ spec->to_addr =3D to_addr;
+ spec->mark =3D False; /* not significant */
+
+ spec->next =3D topSpecs->specs;
+ topSpecs->specs =3D spec;
+}
+
+
/* Initialise the redir system, and create the initial Spec list and
for amd64-linux a couple of permanent active mappings. The initial
Specs are not converted into Actives yet, on the (checked)
assumption that no SegInfos have so far been created, and so when
they are created, that will happen. */
=20
-void VG_(redir_init) ( void )
+void VG_(redir_initialise) ( void )
{
+ // Assert that there are no SegInfos so far
vg_assert( VG_(next_seginfo)(NULL) =3D=3D NULL );
=20
- // Initialise spec list.
- specs =3D NULL;
-
// Initialise active mapping.
- active =3D VG_(OSet_Create)(offsetof(Active, from_addr),
- NULL, // Use fast comparison
- symtab_alloc,
- symtab_free);
+ activeSet =3D VG_(OSet_Create)(offsetof(Active, from_addr),
+ NULL, // Use fast comparison
+ symtab_alloc,
+ symtab_free);
=20
// The rest of this function just adds initial Specs. =20
=20
@@ -475,30 +567,26 @@
/* Redirect _dl_sysinfo_int80, which is glibc's default system call
routine, to our copy so that the special sysinfo unwind hack in
m_stacktrace.c will kick in. */
- add_to_specs(
- Spec{NULL,=20
- "soname:ld-linux.so.2", "_dl_sysinfo_int80",
- (Addr)&VG_(x86_linux_REDIR_FOR__dl_sysinfo_int80),
- NULL}
+ add_hardwired_spec(
+ "ld-linux.so.2", "_dl_sysinfo_int80",
+ (Addr)&VG_(x86_linux_REDIR_FOR__dl_sysinfo_int80)=20
);
/* If we're using memcheck, use this intercept right from the
start, otherwise ld.so (glibc-2.3.5) makes a lot of noise. */
if (0=3D=3DVG_(strcmp)("Memcheck", VG_(details).name)) {
- add_to_specs(
- Spec{NULL,
- "soname:ld-linux.so.2", "index",
- (Addr)&VG_(x86_linux_REDIR_FOR_index),
- NULL}
+ add_hardwired_spec(
+ "ld-linux.so.2", "index",
+ (Addr)&VG_(x86_linux_REDIR_FOR_index)
);
}
=20
# elif defined(VGP_amd64_linux)
/* Redirect vsyscalls to local versions */
- add_to_actives(
+ add_hardwired_active(
0xFFFFFFFFFF600000ULL,
(Addr)&VG_(amd64_linux_REDIR_FOR_vgettimeofday)=20
);
- add_to_actives(=20
+ add_hardwired_active(=20
0xFFFFFFFFFF600400ULL,
(Addr)&VG_(amd64_linux_REDIR_FOR_vtime)=20
);
@@ -507,20 +595,14 @@
/* If we're using memcheck, use these intercepts right from
the start, otherwise ld.so makes a lot of noise. */
if (0=3D=3DVG_(strcmp)("Memcheck", VG_(details).name)) {
-
- add_to_specs(
- Spec{NULL,
- "soname:ld.so.1", "strlen",
- (Addr)&VG_(ppc32_linux_REDIR_FOR_strlen),
- NULL}
+ add_hardwired_spec(
+ "ld.so.1", "strlen",
+ (Addr)&VG_(ppc32_linux_REDIR_FOR_strlen),
); =20
- add_to_specs(
- Spec{NULL,
- "soname:ld.so.1", "strcmp",
- (Addr)&VG_(ppc32_linux_REDIR_FOR_strcmp),
- NULL}
+ add_hardwired_spec(
+ "soname:ld.so.1", "strcmp",
+ (Addr)&VG_(ppc32_linux_REDIR_FOR_strcmp),
);
-
}
=20
# elif defined(VGP_ppc64_linux)
@@ -535,199 +617,6 @@
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
=20
-static Bool soname_matches(const Char *pattern, const Char* soname)
-{
- // pattern must start with "soname:"
- vg_assert(NULL !=3D pattern);
- vg_assert(0 =3D=3D VG_(strncmp)(pattern, "soname:", 7));
-
- if (NULL =3D=3D soname)
- return False;
- =20
- return VG_(string_match)(pattern + 7, soname);
-}
-
-// Prepends redir to the unresolved list.
-static void add_redir_to_unresolved_list(Spec *redir)
-{
- redir->next =3D specs;
- specs =3D redir;
-}
-
-static void add_redir_to_resolved_list(Spec *redir, Bool need_discard)
-{
- vg_assert(redir->from_addr);
-
- TRACE_REDIR(" redir resolved (%s:%s=3D%p -> %p)",=20
- redir->from_lib, redir->from_sym, redir->from_addr,
- redir->to_addr);
-
- vg_assert(redir->to_addr !=3D 0);
-
- if (need_discard) {
- /* For some given (from, to) redir, the "from" function got
- loaded before the .so containing "to" became available so
- we need to discard any existing translations involving
- the "from" function.
-
- 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 requires a complete search through all of
- them.
- */
- TRACE_REDIR("Discarding translation due to redirect of already =
loaded function" );
- TRACE_REDIR(" %s:%s(%p) -> %p)", redir->from_lib, redir->from=
_sym,
- redir->from_addr, redir->to_=
addr );
- VG_(discard_translations)((Addr64)redir->from_addr, 1,=20
- "add_redir_to_resolved_list");
- }
-
- // This entails a possible double OSet lookup -- one for Contains(=
),
- // one for Insert(). If we had OSet_InsertIfNonDup() we could do =
it
- // with one lookup.
- if ( ! VG_(OSet_Contains)(active, &redir->from_addr) ) {
- VG_(OSet_Insert)(active, redir);
- } else {
- TRACE_REDIR(" redir %s:%s:%p->%p duplicated\n",
- redir->from_lib, redir->from_sym, redir->from_addr,
- redir->to_addr);
- // jrs 20 Nov 05: causes this: m_mallocfree.c:170
- // (mk_plain_bszB): Assertion 'bszB !=3D 0' failed.
- // Perhaps it is an invalid free? Disable for now
- // XXX leak?
- //VG_(arena_free)(VG_AR_SYMTAB, redir);
- }
-}
-
-// Resolve a redir using si if possible. Returns True if it succeeded.
-static Bool resolve_redir_with_seginfo(Spec *redir, const SegInfo *si)
-{
- Bool ok;
-
- vg_assert(si !=3D NULL);
- vg_assert(redir->from_addr =3D=3D 0 );
- vg_assert(redir->from_sym !=3D NULL);
-
- // Resolved if the soname matches and we find the symbol.
- ok =3D soname_matches(redir->from_lib, VG_(seginfo_soname)(si));
- if (ok) {
- redir->from_addr =3D VG_(reverse_search_one_symtab)(si, redir->fro=
m_sym);
- ok =3D ( redir->from_addr =3D=3D 0 ? False : True );
- }
- return ok; =20
-}
-
-// Resolve a redir using any SegInfo if possible. This is called whenev=
er
-// a new sym-to-addr redir is created. It covers the case where a
-// replacement function is loaded after its replacee.
-static Bool resolve_redir_with_existing_seginfos(Spec *redir)
-{
- const SegInfo *si;
-
- for (si =3D VG_(next_seginfo)(NULL);=20
- si !=3D NULL;=20
- si =3D VG_(next_seginfo)(si))
- {
- if (resolve_redir_with_seginfo(redir, si))
- return True;
- }
- return False;
-}
-
-// Resolve as many unresolved redirs as possible with this SegInfo. Thi=
s
-// should be called when a new SegInfo symtab is loaded. It covers the =
case
-// where a replacee function is loaded after its replacement function.
-void VG_(resolve_existing_redirs_with_seginfo)(SegInfo *si)
-{
- Spec **prevp =3D &specs;
- Spec *redir, *next;
-
- TRACE_REDIR("Just loaded %s (soname=3D%s),",
- VG_(seginfo_filename)(si), VG_(seginfo_soname)(si));
- TRACE_REDIR(" resolving any unresolved redirs with it");
-
- // Visit each unresolved redir - if it becomes resolved, then
- // move it from the unresolved list to the resolved list.
- for (redir =3D specs; redir !=3D NULL; redir =3D next) {
- next =3D redir->next;
-
- if (resolve_redir_with_seginfo(redir, si)) {
- *prevp =3D next;
- redir->next =3D NULL;
- add_redir_to_resolved_list(redir, False);
- } else
- prevp =3D &redir->next;
- }
-
- TRACE_REDIR(" Finished resolving");
-}
-
-/* Redirect a function at from_addr to a function at to_addr */
-__attribute__((unused)) // It is used, but not on all platforms...
-static void add_redirect_addr_to_addr( Addr from_addr, Addr to_addr )
-{
- Spec* redir =3D VG_(OSet_AllocNode)(active,
- sizeof(Spec));
- vg_assert(0 !=3D from_addr && 0 !=3D to_addr);
-
- redir->from_lib =3D NULL;
- redir->from_sym =3D NULL;
- redir->from_addr =3D from_addr;
-
- redir->to_addr =3D to_addr;
-
- TRACE_REDIR("REDIRECT addr to addr: %p to %p", from_addr, to_addr);
-
- // This redirection is already resolved, put it straight in the list.
- add_redir_to_resolved_list(redir, True);
-}
-
-/* Redirect a lib/symbol reference to a function at addr */
-static void add_redirect_sym_to_addr(
- const Char *from_lib, const Char *from_sym, Addr to_addr
-)
-{
- Spec* redir =3D VG_(OSet_AllocNode)(active,
- sizeof(Spec));
- vg_assert(from_lib && from_sym && 0 !=3D to_addr);
-
- redir->from_lib =3D VG_(arena_strdup)(VG_AR_SYMTAB, from_lib);
- redir->from_sym =3D VG_(arena_strdup)(VG_AR_SYMTAB, from_sym);
- redir->from_addr =3D 0;
- redir->to_addr =3D to_addr;
-
- TRACE_REDIR("REDIR sym to addr: %s:%s to %p", from_lib, from_sym, to_=
addr);
-
- // Check against all existing segments to see if this redirection
- // can be resolved immediately (as will be the case when the replacem=
ent
- // function is loaded after the replacee). Then add it to the
- // appropriate list.
- if (resolve_redir_with_existing_seginfos(redir)) {
- add_redir_to_resolved_list(redir, True);
- } else {
- add_redir_to_unresolved_list(redir);
- }
-}
-
-/* If address 'a' is being redirected, return the redirected-to
- address. */
-Addr VG_(code_redirect)(Addr a)
-{
- Spec* r =3D VG_(OSet_Lookup)(active, &a);
- if (r =3D=3D NULL)
- return a;
-
- vg_assert(r->to_addr !=3D 0);
-
- return r->to_addr;
-}
-
static void* symtab_alloc(SizeT n)
{
return VG_(arena_malloc)(VG_AR_SYMTAB, n);
@@ -738,182 +627,57 @@
return VG_(arena_free)(VG_AR_SYMTAB, p);
}
=20
-void VG_(setup_code_redirect_table) ( void )
+static HChar* symtab_strdup(HChar* str)
{
- // Initialise active list.
- active =3D VG_(OSet_Create)(offsetof(Spec, from_addr),
- NULL, // Use fast comparison
- symtab_alloc,
-} symtab_free));
-
-
-/* Z-decode a symbol into library:func form, eg=20
- =20
- _vgi_libcZdsoZd6__ZdlPv --> libc.so.6:_ZdlPv
-
- Uses the Z-encoding scheme described in pub_core_redir.h.
- Returns True if demangle OK, False otherwise.
-*/
-static Bool Z_decode(const Char* symbol, Char* result, Int nbytes)
-{
-# define EMIT(ch) \
- do { \
- if (j >=3D nbytes) \
- result[j-1] =3D 0; \
- else \
- result[j++] =3D ch; \
- } while (0)
-
- Bool error =3D False;
- Int i, j =3D 0;
- Int len =3D VG_(strlen)(symbol);
- if (0) VG_(printf)("idm: %s\n", symbol);
-
- i =3D VG_REPLACE_FUNCTION_PREFIX_LEN;
-
- /* Chew though the Z-encoded soname part. */
- while (True) {
-
- if (i >=3D len)=20
- break;
-
- if (symbol[i] =3D=3D '_')
- /* We found the underscore following the Z-encoded soname.
- Just copy the rest literally. */
- break;
-
- if (symbol[i] !=3D 'Z') {
- EMIT(symbol[i]);
- i++;
- continue;
- }
-
- /* We've got a Z-escape. Act accordingly. */
- i++;
- if (i >=3D len) {
- /* Hmm, Z right at the end. Something's wrong. */
- error =3D True;
- EMIT('Z');
- break;
- }
- switch (symbol[i]) {
- case 'a': EMIT('*'); break;
- case 'p': EMIT('+'); break;
- case 'c': EMIT(':'); break;
- case 'd': EMIT('.'); break;
- case 'u': EMIT('_'); break;
- case 'h': EMIT('-'); break;
- case 's': EMIT(' '); break;
- case 'Z': EMIT('Z'); break;
- default: error =3D True; EMIT('Z'); EMIT(symbol[i]); break;
- }
- i++;
- }
-
- if (error || i >=3D len || symbol[i] !=3D '_') {
- /* Something's wrong. Give up. */
- VG_(message)(Vg_UserMsg, "intercept: error demangling: %s", symbol=
);
- EMIT(0);
- return False;
- }
-
- /* Copy the rest of the string verbatim. */
- i++;
- EMIT(':');
- while (True) {
- if (i >=3D len)
- break;
- EMIT(symbol[i]);
- i++;
- }
-
- EMIT(0);
- if (0) VG_(printf)("%s\n", result);
- return True;
-
-# undef EMIT
+ return VG_(arena_strdup)(VG_AR_SYMTAB, str);
}
=20
-// Nb: this can change the string pointed to by 'symbol'.
-static void handle_replacement_function( Char* symbol, Addr addr )
+/* Really this should be merged with translations_allowable_from_seg
+ in m_translate. */
+static Bool is_plausible_guest_addr(Addr a)
{
- Bool ok;
- Int len =3D VG_(strlen)(symbol) + 1 - VG_REPLACE_FUNCTION_PREFIX_LE=
N;
- Char *lib =3D VG_(arena_malloc)(VG_AR_SYMTAB, len+8);
- Char *func;
-
- // Put "soname:" at the start of lib
- VG_(strcpy)(lib, "soname:");
-
- ok =3D Z_decode(symbol, lib+7, len);
- if (ok) {
- // lib is "soname:<libname>:<fnname>". Split the string at the 2n=
d ':'.
- func =3D lib + VG_(strlen)(lib)-1;
- while(*func !=3D ':') func--;
- *func =3D '\0';
- func++; // Move past the '\0'
-
- // Now lib is "soname:<libname>" and func is "<fnname>".
- if (0) VG_(printf)("lib A%sZ, func A%sZ\n", lib, func);
- add_redirect_sym_to_addr(lib, func, addr);
-
- // Overwrite the given Z-encoded name with just the fnname.
- VG_(strcpy)(symbol, func);
- }
-
- VG_(arena_free)(VG_AR_SYMTAB, lib);
+ NSegment* seg =3D VG_(am_find_nsegment)(a);
+ return seg !=3D NULL
+ && (seg->kind =3D=3D SkAnonC || seg->kind =3D=3D SkFileC)
+ && (seg->hasX || seg->hasR); /* crude x86-specific hack */
}
=20
-static Addr __libc_freeres_wrapper =3D 0;
+//////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////
=20
-Addr VG_(get_libc_freeres_wrapper)(void)
-{
- return __libc_freeres_wrapper;
-}
=20
// This is specifically for stringifying VG_(x) function names. We
// need to do two macroexpansions to get the VG_ macro expanded before
// stringifying.
-#define _STR(x) #x
-#define STR(x) _STR(x)
-
-static void handle_load_notifier( Char* symbol, Addr addr )
-{
- if (VG_(strcmp)(symbol, STR(VG_NOTIFY_ON_LOAD(freeres))) =3D=3D 0)
- __libc_freeres_wrapper =3D addr;
+//zz #define _STR(x) #x
+//zz #define STR(x) _STR(x)
+//zz=20
+//zz static void handle_load_notifier( Char* symbol, Addr addr )
+//zz {
+//zz if (VG_(strcmp)(symbol, STR(VG_NOTIFY_ON_LOAD(freeres))) =3D=3D =
0)
+//zz VG_(client___libc_freeres_wrapper) =3D addr;
// else
// if (VG_(strcmp)(symbol, STR(VG_WRAPPER(pthread_startfunc_wrapper))) =3D=
=3D 0)
// VG_(pthread_startfunc_wrapper)((Addr)(si->offset + sym->st_value))=
;
- else
- vg_assert2(0, "unrecognised load notification function: %s", symbo=
l);
-}
+//zz else
+//zz vg_assert2(0, "unrecognised load notification function: %s", =
symbol);
+//zz }
+//zz=20
+//zz static Bool is_replacement_function(Char* s)
+//zz {
+//zz return (0 =3D=3D VG_(strncmp)(s,
+//zz VG_REPLACE_FUNCTION_PREFIX,
+//zz VG_REPLACE_FUNCTION_PREFIX_LEN));
+//zz }
+//zz=20
+//zz static Bool is_load_notifier(Char* s)
+//zz {
+//zz return (0 =3D=3D VG_(strncmp)(s,
+//zz VG_NOTIFY_ON_LOAD_PREFIX,
+//zz VG_NOTIFY_ON_LOAD_PREFIX_LEN));
+//zz }
=20
-static Bool is_replacement_function(Char* s)
-{
- return (0 =3D=3D VG_(strncmp)(s,
- VG_REPLACE_FUNCTION_PREFIX,
- VG_REPLACE_FUNCTION_PREFIX_LEN));
-}
=20
-static Bool is_load_notifier(Char* s)
-{
- return (0 =3D=3D VG_(strncmp)(s,
- VG_NOTIFY_ON_LOAD_PREFIX,
- VG_NOTIFY_ON_LOAD_PREFIX_LEN));
-}
-
-// Call this for each symbol loaded. It determines if we need to do
-// anything special with it. It can modify 'symbol' in-place.
-void VG_(maybe_redir_or_notify) ( Char* symbol, Addr addr )
-{
- if (is_replacement_function(symbol))
- handle_replacement_function(symbol, addr);
- else=20
- if (is_load_notifier(symbol))
- handle_load_notifier(symbol, addr);
-}
-
-
/*------------------------------------------------------------*/
/*--- THE DEMANGLER ---*/
/*------------------------------------------------------------*/
@@ -945,8 +709,11 @@
} \
} while (0)
=20
- vg_assert(solen > 0);
- vg_assert(fnlen > 0);
+ Bool error, oflow, valid, fn_is_encoded;
+ Int soi, fni, i;
+
+ vg_assert(soLen > 0);
+ vg_assert(fnLen > 0);
error =3D False;
oflow =3D False;
soi =3D 0;
@@ -985,7 +752,7 @@
=20
/* We've got a Z-escape. */
i++;
- switch (symbol[i]) {
+ switch (sym[i]) {
case 'a': EMITSO('*'); break;
case 'p': EMITSO('+'); break;
case 'c': EMITSO(':'); break;
@@ -994,6 +761,7 @@
case 'h': EMITSO('-'); break;
case 's': EMITSO(' '); break;
case 'Z': EMITSO('Z'); break;
+ case 'A': EMITSO('@'); break;
default: error =3D True; goto out;
}
i++;
@@ -1030,7 +798,7 @@
=20
/* We've got a Z-escape. */
i++;
- switch (symbol[i]) {
+ switch (sym[i]) {
case 'a': EMITFN('*'); break;
case 'p': EMITFN('+'); break;
case 'c': EMITFN(':'); break;
@@ -1039,6 +807,7 @@
case 'h': EMITFN('-'); break;
case 's': EMITFN(' '); break;
case 'Z': EMITFN('Z'); break;
+ case 'A': EMITFN('@'); break;
default: error =3D True; goto out;
}
i++;
@@ -1050,12 +819,12 @@
=20
if (error) {
/* Something's wrong. Give up. */
- VG_(message)(Vg_UserMsg, "m_redir: error demangling: %s", symbol);
+ VG_(message)(Vg_UserMsg, "m_redir: error demangling: %s", sym);
return False;
}
if (oflow) {
/* It didn't fit. Give up. */
- VG_(message)(Vg_UserMsg, "m_debuginfo: oflow demangling: %s", symb=
ol);
+ VG_(message)(Vg_UserMsg, "m_debuginfo: oflow demangling: %s", sym)=
;
return False;
}
=20
Modified: branches/FNWRAP/coregrind/m_replacemalloc/vg_replace_malloc.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
--- branches/FNWRAP/coregrind/m_replacemalloc/vg_replace_malloc.c 2005-12=
-04 23:27:14 UTC (rev 5283)
+++ branches/FNWRAP/coregrind/m_replacemalloc/vg_replace_malloc.c 2005-12=
-05 14:26:59 UTC (rev 5284)
@@ -50,7 +50,7 @@
#include "pub_core_basics.h"
#include "pub_core_debuginfo.h" // needed for pub_core_redir.h :(
#include "pub_core_mallocfree.h" // for VG_MIN_MALLOC_SZB, VG_AR_CLIE=
NT
-#include "pub_core_redir.h" // for VG_REPLACE_FUNCTION
+#include "pub_core_redir.h" // for VG_REDIRECT_FUNCTION_*
#include "pub_core_replacemalloc.h"
=20
/* Some handy Z-encoded names */
@@ -91,10 +91,11 @@
__builtin_delete, calloc, realloc, memalign, and friends.
=20
None of these functions are called directly - they are not meant to
- be found by the dynamic linker. But ALL client calls to malloc() and
- friends wind up here eventually. They get called because vg_replace_=
malloc
- installs a bunch of code redirects which causes Valgrind to use these
- functions rather than the ones they're replacing.
+ be found by the dynamic linker. But ALL client calls to malloc()
+ and friends wind up here eventually. They get called because
+ vg_replace_malloc installs a bunch of code redirects which causes
+ Valgrind to use these functions rather than the ones they're
+ replacing.
*/
=20
/* Generate a replacement for 'fnname' in object 'soname', which calls
@@ -102,8 +103,8 @@
*/
#define ALLOC_or_NULL(soname, fnname, vg_replacement) \
\
- void* VG_REPLACE_FUNCTION(soname,fnname) (SizeT n); \
- void* VG_REPLACE_FUNCTION(soname,fnname) (SizeT n) \
+ void* VG_REDIRECT_FUNCTION_ZU(soname,fnname) (SizeT n); \
+ void* VG_REDIRECT_FUNCTION_ZU(soname,fnname) (SizeT n) \
{ \
void* v; \
\
@@ -122,8 +123,8 @@
*/
#define ALLOC_or_BOMB(soname, fnname, vg_replacement) \
\
- void* VG_REPLACE_FUNCTION(soname,fnname) (SizeT n); \
- void* VG_REPLACE_FUNCTION(soname,fnname) (SizeT n) \
+ void* VG_REDIRECT_FUNCTION_ZU(soname,fnname) (SizeT n); \
+ void* VG_REDIRECT_FUNCTION_ZU(soname,fnname) (SizeT n) \
{ \
void* v; \
\
@@ -220,8 +221,8 @@
*/
#define FREE(soname, fnname, vg_replacement) \
\
- void VG_REPLACE_FUNCTION(soname,fnname) (void *p); \
- void VG_REPLACE_FUNCTION(soname,fnname) (void *p) \
+ void VG_REDIRECT_FUNCTION_ZU(soname,fnname) (void *p); \
+ void VG_REDIRECT_FUNCTION_ZU(soname,fnname) (void *p) \
{ \
MALLOC_TRACE(#vg_replacement "(%p)", p ); \
if (p =3D=3D NULL) \
@@ -263,8 +264,8 @@
=20
#define CALLOC(soname, fnname) \
\
- void* VG_REPLACE_FUNCTION(soname,fnname) ( SizeT nmemb, SizeT size );=
\
- void* VG_REPLACE_FUNCTION(soname,fnname) ( SizeT nmemb, SizeT size ) =
\
+ void* VG_REDIRECT_FUNCTION_ZU(soname,fnname) ( SizeT nmemb, SizeT siz=
e ); \
+ void* VG_REDIRECT_FUNCTION_ZU(soname,fnname) ( SizeT nmemb, SizeT siz=
e ) \
{ \
void* v; \
\
@@ -281,8 +282,8 @@
=20
#define REALLOC(soname, fnname) \
\
- void* VG_REPLACE_FUNCTION(soname,fnname) ( void* ptrV, SizeT new_size=
);\
- void* VG_REPLACE_FUNCTION(soname,fnname) ( void* ptrV, SizeT new_size=
) \
+ void* VG_REDIRECT_FUNCTION_ZU(soname,fnname) ( void* ptrV, SizeT new_=
size );\
+ void* VG_REDIRECT_FUNCTION_ZU(soname,fnname) ( void* ptrV, SizeT new_=
size ) \
{ \
void* v; \
\
@@ -291,9 +292,9 @@
if (ptrV =3D=3D NULL) \
/* We need to call a malloc-like function; so let's use \
one which we know exists. */ \
- return VG_REPLACE_FUNCTION(libcZdsoZa,malloc) (new_size); \
+ return VG_REDIRECT_FUNCTION_ZU(libcZdsoZa,malloc) (new_size); \
if (new_size <=3D 0) { \
- VG_REPLACE_FUNCTION(libcZdsoZa,free)(ptrV); \
+ VG_REDIRECT_FUNCTION_ZU(libcZdsoZa,free)(ptrV); \
MALLOC_TRACE(" =3D 0"); \
return NULL; \
} \
@@ -308,8 +309,8 @@
=20
#define MEMALIGN(soname, fnname) \
\
- void* VG_REPLACE_FUNCTION(soname,fnname) ( SizeT alignment, SizeT n )=
; \
- void* VG_REPLACE_FUNCTION(soname,fnname) ( SizeT alignment, SizeT n )=
\
+ void* VG_REDIRECT_FUNCTION_ZU(soname,fnname) ( SizeT alignment, SizeT=
n ); \
+ void* VG_REDIRECT_FUNCTION_ZU(soname,fnname) ( SizeT alignment, SizeT=
n ) \
{ \
void* v; \
\
@@ -334,10 +335,10 @@
=20
#define VALLOC(soname, fnname) \
\
- void* VG_REPLACE_FUNCTION(soname,fnname) ( SizeT size ); \
- void* VG_REPLACE_FUNCTION(soname,fnname) ( SizeT size ) \
+ void* VG_REDIRECT_FUNCTION_ZU(soname,fnname) ( SizeT size ); \
+ void* VG_REDIRECT_FUNCTION_ZU(soname,fnname) ( SizeT size ) \
{ \
- return VG_REPLACE_FUNCTION(libcZdsoZa,memalign)(VKI_PAGE_SIZE, siz=
e); \
+ return VG_REDIRECT_FUNCTION_ZU(libcZdsoZa,memalign)(VKI_PAGE_SIZE,=
size); \
}
=20
VALLOC(m_libc_dot_so_star, valloc);
@@ -347,8 +348,8 @@
=20
#define MALLOPT(soname, fnname) \
\
- int VG_REPLACE_FUNCTION(soname, fnname) ( int cmd, int value ); \
- int VG_REPLACE_FUNCTION(soname, fnname) ( int cmd, int value ) \
+ int VG_REDIRECT_FUNCTION_ZU(soname, fnname) ( int cmd, int value ); \
+ int VG_REDIRECT_FUNCTION_ZU(soname, fnname) ( int cmd, int value ) \
{ \
/* In glibc-2.2.4, 1 denotes a successful return value for \
mallopt */ \
@@ -360,8 +361,10 @@
=20
#define POSIX_MEMALIGN(soname, fnname) \
\
- int VG_REPLACE_FUNCTION(soname, fnname) ( void **memptr, SizeT alignm=
ent, SizeT size ); \
- int VG_REPLACE_FUNCTION(soname, fnname) ( void **memptr, SizeT alignm=
ent, SizeT size ) \
+ int VG_REDIRECT_FUNCTION_ZU(soname, fnname) ( void **memptr, \
+ SizeT alignment, SizeT =
size ); \
+ int VG_REDIRECT_FUNCTION_ZU(soname, fnname) ( void **memptr, \
+ SizeT alignment, SizeT =
size ) \
{ \
void *mem; \
\
@@ -371,7 +374,7 @@
|| (alignment & (alignment - 1)) !=3D 0) \
return VKI_EINVAL; \
\
- mem =3D VG_REPLACE_FUNCTION(libcZdsoZa,memalign)(alignment, size);=
\
+ mem =3D VG_REDIRECT_FUNCTION_ZU(libcZdsoZa,memalign)(alignment, si=
ze); \
\
if (mem !=3D NULL) { \
*memptr =3D mem; \
@@ -386,8 +389,8 @@
=20
#define MALLOC_USABLE_SIZE(soname, fnname) \
\
- int VG_REPLACE_FUNCTION(soname, fnname) ( void* p ); \
- int VG_REPLACE_FUNCTION(soname, fnname) ( void* p ) \
+ int VG_REDIRECT_FUNCTION_ZU(soname, fnname) ( void* p ); \
+ int VG_REDIRECT_FUNCTION_ZU(soname, fnname) ( void* p ) \
{ \
SizeT pszB; \
\
@@ -417,8 +420,8 @@
=20
#define PANIC(soname, fnname) \
\
- void VG_REPLACE_FUNCTION(soname, fnname) ( void ); \
- void VG_REPLACE_FUNCTION(soname, fnname) ( void ) \
+ void VG_REDIRECT_FUNCTION_ZU(soname, fnname) ( void ); \
+ void VG_REDIRECT_FUNCTION_ZU(soname, fnname) ( void ) \
{ \
panic(#fnname); \
}
@@ -434,8 +437,8 @@
// doesn't know that the call to mallinfo fills in mi.
#define MALLINFO(soname, fnname) \
\
- struct vg_mallinfo VG_REPLACE_FUNCTION(soname, fnname) ( void ); \
- struct vg_mallinfo VG_REPLACE_FUNCTION(soname, fnname) ( void ) \
+ struct vg_mallinfo VG_REDIRECT_FUNCTION_ZU(soname, fnname) ( void ); =
\
+ struct vg_mallinfo VG_REDIRECT_FUNCTION_ZU(soname, fnname) ( void ) =
\
{ \
static struct vg_mallinfo mi; \
MALLOC_TRACE("mallinfo()"); \
Modified: branches/FNWRAP/coregrind/m_translate.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
--- branches/FNWRAP/coregrind/m_translate.c 2005-12-04 23:27:14 UTC (rev =
5283)
+++ branches/FNWRAP/coregrind/m_translate.c 2005-12-05 14:26:59 UTC (rev =
5284)
@@ -40,12 +40,12 @@
#include "pub_core_options.h"
#include "pub_core_profile.h"
=20
-#include "pub_core_debuginfo.h" // Needed for pub_core_redir :(
-#include "pub_core_redir.h" // For VG_(code_redirect)()
+#include "pub_core_debuginfo.h" // Needed for pub_core_redir [SegInf=
o]
+#include "pub_core_redir.h" // VG_(redir_do_lookup)
=20
-#include "pub_core_signals.h" // For VG_(synth_fault_{perms,mappin=
g})()
-#include "pub_core_stacks.h" // For VG_(unknown_SP_update)()
-#include "pub_core_tooliface.h" // For VG_(tdict)
+#include "pub_core_signals.h" // VG_(synth_fault_{perms,mapping})(=
)
+#include "pub_core_stacks.h" // VG_(unknown_SP_update)()
+#include "pub_core_tooliface.h" // VG_(tdict)
#include "pub_core_translate.h"
#include "pub_core_transtab.h"
=20
@@ -426,7 +426,7 @@
}
=20
/* Destination is redirected? */
- if (addr !=3D VG_(code_redirect)(addr))
+ if (addr !=3D VG_(redir_do_lookup)(addr))
goto dontchase;
=20
/* well, ok then. go on and chase. */
@@ -476,7 +476,7 @@
/* Look in the code redirect table to see if we should
translate an alternative address for orig_addr. */
if (allow_redirection) {
- redir =3D VG_(code_redirect)(orig_addr);
+ redir =3D VG_(redir_do_lookup)(orig_addr);
did_redirect =3D redir !=3D orig_addr;
} else {
redir =3D orig_addr;
Modified: branches/FNWRAP/coregrind/pub_core_clientstate.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
--- branches/FNWRAP/coregrind/pub_core_clientstate.h 2005-12-04 23:27:14 =
UTC (rev 5283)
+++ branches/FNWRAP/coregrind/pub_core_clientstate.h 2005-12-05 14:26:59 =
UTC (rev 5284)
@@ -78,6 +78,9 @@
extern Int VG_(fd_soft_limit);
extern Int VG_(fd_hard_limit);
=20
+/* Useful addresses extracted from the client */
+/* Where is the __libc_freeres_wrapper routine we made? */
+extern Addr VG_(client___libc_freeres_wrapper);
=20
#endif // __PUB_CORE_CLIENTSTATE_H
=20
Modified: branches/FNWRAP/coregrind/pub_core_debuginfo.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
--- branches/FNWRAP/coregrind/pub_core_debuginfo.h 2005-12-04 23:27:14 UT=
C (rev 5283)
+++ branches/FNWRAP/coregrind/pub_core_debuginfo.h 2005-12-05 14:26:59 UT=
C (rev 5284)
@@ -58,8 +58,6 @@
=20
extern Bool VG_(get_fnname_nodemangle)( Addr a, Char* fnname, Int n_fnna=
me );
=20
-extern Addr VG_(reverse_search_one_symtab) ( const SegInfo* si, const Ch=
ar* name );
-
extern Bool VG_(use_CFI_info) ( /*MOD*/Addr* ipP,
/*MOD*/Addr* spP,
/*MOD*/Addr* fpP,
Modified: branches/FNWRAP/coregrind/pub_core_redir.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
--- branches/FNWRAP/coregrind/pub_core_redir.h 2005-12-04 23:27:14 UTC (r=
ev 5283)
+++ branches/FNWRAP/coregrind/pub_core_redir.h 2005-12-05 14:26:59 UTC (r=
ev 5284)
@@ -43,35 +43,32 @@
=20
#include "pub_tool_redir.h"
=20
+
//--------------------------------------------------------------------
-// General
+// Notifications - by which we are told of state changes
//--------------------------------------------------------------------
=20
-// This module needs be told about all the symbols that get loaded, so=20
-// it can check if it needs to do anything special. This is the functio=
n
-// that does that checking. It modifies 'symbol' in-place by Z-decoding
-// it if necessary.
-void VG_(maybe_redir_or_notify) ( Char* symbol, Addr addr );
+/* Notify the module of a new SegInfo (called from m_debuginfo). */
+extern void VG_(redir_notify_new_SegInfo)( SegInfo* );
=20
-//--------------------------------------------------------------------
-// Code replacement
-//--------------------------------------------------------------------
+/* Notify the module of the disappearance of a SegInfo (also called
+ from m_debuginfo). */
+extern void VG_(redir_notify_delete_SegInfo)( SegInfo* );
=20
-// See include/pub_tool_redir.h for details on how to do code replacemen=
t.
+/* Initialise the module, and load initial "hardwired" redirects. */
+extern void VG_(redir_initialise)( void );
=20
-typedef struct _CodeRedirect CodeRedirect;
=20
-// This is the crucial redirection function. It answers the question:=20
-// should this code address be redirected somewhere else? It's used jus=
t
-// before translating a basic block.
-extern Addr VG_(code_redirect) ( Addr orig );
+//--------------------------------------------------------------------
+// Queries
+//--------------------------------------------------------------------
=20
-/* Set up some default redirects. */
-extern void VG_(setup_code_redirect_table) ( void );
+/* This is the crucial redirection function. It answers the question:
+ should this code address be redirected somewhere else? It's used
+ just before translating a basic block. */
+extern Addr VG_(redir_do_lookup) ( Addr orig );
=20
-extern void VG_(resolve_existing_redirs_with_seginfo)(SegInfo *si);
=20
-
//--------------------------------------------------------------------
// Loading notification
//--------------------------------------------------------------------
@@ -85,14 +82,27 @@
Functions named with this macro should be in client space, ie. in
vgpreload_<tool>.h or vgpreload_core.h. */
=20
-#define VG_NOTIFY_ON_LOAD(name) _vgw_##name
-#define VG_NOTIFY_ON_LOAD_PREFIX "_vgw_"
-#define VG_NOTIFY_ON_LOAD_PREFIX_LEN 5
+#define VG_NOTIFY_ON_LOAD(name) _vgnU_##name
+#define VG_NOTIFY_ON_LOAD_PREFIX "_vgnU_"
+#define VG_NOTIFY_ON_LOAD_PREFIX_LEN 6
=20
-// Called by m_main to get our __libc_freeres wrapper.
-extern Addr VG_(get_libc_freeres_wrapper)(void);
=20
//--------------------------------------------------------------------
+// Demangling of Z-encoded names
+//--------------------------------------------------------------------
+
+/* Demangle 'sym' into its soname and fnname parts, putting them in
+ the specified buffers. Returns a Bool indicating whether the
+ demangled failed or not. A failure can occur because the prefix
+ isn't recognised, the internal Z-escaping is wrong, or because one
+ or the other (or both) of the output buffers becomes full. */
+
+Bool VG_(maybe_Z_demangle) ( const HChar* sym,=20
+ /*OUT*/HChar* so, Int soLen,
+ /*OUT*/HChar* fn, Int fnLen );
+
+
+//--------------------------------------------------------------------
// Function wrapping
//--------------------------------------------------------------------
=20
Modified: branches/FNWRAP/coregrind/vg_preloaded.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
--- branches/FNWRAP/coregrind/vg_preloaded.c 2005-12-04 23:27:14 UTC (rev=
5283)
+++ branches/FNWRAP/coregrind/vg_preloaded.c 2005-12-05 14:26:59 UTC (rev=
5284)
@@ -71,6 +71,8 @@
/*--- end ---*/
/*--------------------------------------------------------------------*/
=20
+#if 0
+
#define PTH_FUNC(ret_ty, f, args...) \
ret_ty VG_REPLACE_FUNCTION(libpthreadZdsoZd0, f)(args); \
ret_ty VG_REPLACE_FUNCTION(libpthreadZdsoZd0, f)(args)
@@ -82,7 +84,6 @@
#include <stdio.h>
#include <pthread.h>
=20
-#if 1
PTH_FUNC(int, pthread_create, // pthread_create@*
pthread_t *thread, const pthread_attr_t *attr,
void *(*start) (void *), void *arg)
Modified: branches/FNWRAP/include/pub_tool_debuginfo.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
--- branches/FNWRAP/include/pub_tool_debuginfo.h 2005-12-04 23:27:14 UTC =
(rev 5283)
+++ branches/FNWRAP/include/pub_tool_debuginfo.h 2005-12-05 14:26:59 UTC =
(rev 5284)
@@ -122,7 +122,7 @@
extern void VG_(seginfo_syms_getidx) ( const SegInfo *si,=20
Int idx,
/*OUT*/Addr* addr,
- /*OUT*/UInt size,
+ /*OUT*/UInt* size,
/*OUT*/HChar** name );
=20
typedef
Modified: branches/FNWRAP/include/pub_tool_redir.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
--- branches/FNWRAP/include/pub_tool_redir.h 2005-12-04 23:27:14 UTC (rev=
5283)
+++ branches/FNWRAP/include/pub_tool_redir.h 2005-12-05 14:26:59 UTC (rev=
5284)
@@ -31,12 +31,12 @@
#ifndef __PUB_TOOL_REDIR_H
#define __PUB_TOOL_REDIR_H
=20
-/* The following macros facilitate function replacement, which is one fo=
rm
- of code replacement.
+/* The following macros facilitate function redirection (redirects).
=20
The general idea is: you can write a function like this:
=20
- ret_type VG_REPLACE_FUNCTION(zEncodedSoname, fnname) ( ... args ..=
. )
+ ret_type=20
+ VG_REDIRECT_FUNCTION_ZU(zEncodedSoname,fnname) ( .. args .. )
{
... body ...
}
@@ -44,53 +44,76 @@
zEncodedSoname should be a Z-encoded soname (see below for Z-encoding
details) and fnname should be an unencoded fn name. The resulting na=
me is
=20
- _vgi_zEncodedSoname_fnname
+ _vgrZU_zEncodedSoname_fnname
=20
- The "_vgi_" is a prefix that gets discarded upon decoding.
+ The "_vgrZU_" is a prefix that gets discarded upon decoding.
+
+ It is also possible to write
+
+ ret_type=20
+ VG_REDIRECT_FUNCTION_ZZ(zEncodedSoname,zEncodedFnname) ( .. args .=
. )
+ {
+ ... body ...
+ }
=20
- When it sees this name, the core's symbol-table reading machinery
- and redirection machinery will conspire to cause calls to the functio=
n
- 'fnname' in object with soname 'zEncodedSoname' to actually be routed=
to
- the function written here. We use this below to define dozens of
- replacements of malloc, free, etc.
+ which means precisely the same, but the function name is also
+ Z-encoded. This can sometimes be necessary. In this case the
+ resulting function name is
=20
+ _vgrZZ_zEncodedSoname_zEncodedFnname
+
+ When it sees this either such name, the core's symbol-table reading
+ machinery and redirection machinery first Z-decode the soname and=20
+ if necessary the fnname. They are encoded so that they may include
+ arbitrary characters, and in particular they may contain '*', which
+ acts as a wildcard.
+
+ They then will conspire to cause calls to any function matching
+ 'fnname' in any object whose soname matches 'soname' to actually be
+ routed to this function. This is used in Valgrind to define dozens
+ of replacements of malloc, free, etc.
+
The soname must be a Z-encoded bit of text because sonames can
- contain dots etc which are not valid symbol names. But don't Z-encod=
e
- the function name, since it will already be a valid symbol name, and =
the
- Z-encoding might screw up the C++ demangling.
+ contain dots etc which are not valid symbol names. The function
+ name may or may not be Z-encoded: to include wildcards it has to be,
+ but Z-encoding C++ function names which are themselves already mangle=
d
+ using Zs in some way is tedious and error prone, so the _ZU variant
+ allows them not to be Z-encoded.
=20
- Note that the soname can contain '*' as a wildcard meaning "match
- anything".
+ Note that the soname "NONE" is specially interpreted to match any
+ shared object which doesn't have a soname.
=20
Note also that the replacement function should probably (must be?) in
client space, so it runs on the simulated CPU. So it must be in
either vgpreload_<tool>.so or vgpreload_core.so. It also only works
with functions in shared objects, I think.
=20
- It is important that the Z-encoded soname contains no unencoded=20
- underscores, since the intercept-handlers in vg_symtab2.c detect
- the end of the soname by looking for the first trailing underscore.
+ It is important that the Z-encoded names contain no unencoded
+ underscores, since the intercept-handlers in m_redir.c detect the
+ end of the soname by looking for the first trailing underscore.
=20
- Z-encoding details: the scheme is like GHC's. It is just about
- readable enough to make a preprocessor unnecessary. First the "_vgi_=
"
- prefix is added, and then the following characters are transformed.
+ Z-encoding details: the scheme is like GHC's. It is just about
+ readable enough to make a preprocessor unnecessary. First the
+ "_vgrZU_" or "_vgrZZ_" prefix is added, and then the following
+ characters are transformed.
=20
- * --> Za ('a' for "asterisk")
- + --> Zp
- : --> Zc
- . --> Zd
- _ --> Zu
- - --> Zh ('h' for...
[truncated message content] |