|
From: <sv...@va...> - 2005-12-02 14:28:34
|
Author: sewardj
Date: 2005-12-02 14:28:28 +0000 (Fri, 02 Dec 2005)
New Revision: 5266
Log:
Initial function wrapping hacks. Note, a work in progress - expect
borkage. Works well enough to intercept pthread_mutex_{lock,unlock}.
- Add a new auxiliary tt/tc structure for unredirected translations.
There's no getting around the problem that in this situation there
are going to have to be two different translations of function=20
wrapper entries -- the redirected and unredirected versions.
- Add a new client request to set this thread's NOREDIR pseudo-reg,
which causes the next entry into a redirected function to branch
to the unredirected version.
- Add scheduler stuff to catch such jumps and run the unredir'd
translations
- Add a couple of pthread-related wrappers for testing, in vg_preloaded.c
=20
Modified:
branches/FNWRAP/coregrind/m_debuginfo/symtab.c
branches/FNWRAP/coregrind/m_errormgr.c
branches/FNWRAP/coregrind/m_main.c
branches/FNWRAP/coregrind/m_scheduler/scheduler.c
branches/FNWRAP/coregrind/m_translate.c
branches/FNWRAP/coregrind/m_transtab.c
branches/FNWRAP/coregrind/pub_core_dispatch_asm.h
branches/FNWRAP/coregrind/pub_core_translate.h
branches/FNWRAP/coregrind/pub_core_transtab.h
branches/FNWRAP/coregrind/vg_preloaded.c
branches/FNWRAP/include/valgrind.h
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-02 13:29:07 UT=
C (rev 5265)
+++ branches/FNWRAP/coregrind/m_debuginfo/symtab.c 2005-12-02 14:28:28 UT=
C (rev 5266)
@@ -1876,13 +1876,24 @@
table is designed we have no option but to do a complete linear
scan of the table. Returns NULL if not found. */
=20
+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))
+ // 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;
Modified: branches/FNWRAP/coregrind/m_errormgr.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_errormgr.c 2005-12-02 13:29:07 UTC (rev 5=
265)
+++ branches/FNWRAP/coregrind/m_errormgr.c 2005-12-02 14:28:28 UTC (rev 5=
266)
@@ -765,7 +765,8 @@
StackTrace ips =3D VG_(extract_StackTrace)(p_min->where);
VG_(translate) ( 0 /* dummy ThreadId; irrelevant due to debuggi=
ng*/,
ips[0], /*debugging*/True, 0xFE/*verbosity*/,
- /*bbs_done*/0);
+ /*bbs_done*/0,
+ /*allow redir?*/True);
}
=20
p_min->count =3D 1 << 30;
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-02 13:29:07 UTC (rev 5265)
+++ branches/FNWRAP/coregrind/m_main.c 2005-12-02 14:28:28 UTC (rev 5266)
@@ -1826,7 +1826,7 @@
score_cumul, buf_cumul,
score_here, buf_here, tops[r].addr, name );
VG_(printf)("\n");
- VG_(translate)(0, tops[r].addr, True, VG_(clo_profile_flags), 0);
+ VG_(translate)(0, tops[r].addr, True, VG_(clo_profile_flags), 0, T=
rue);
VG_(printf)("=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D=
end BB rank %d "
"=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D=
\n\n", r);
}
Modified: branches/FNWRAP/coregrind/m_scheduler/scheduler.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_scheduler/scheduler.c 2005-12-02 13:29:07=
UTC (rev 5265)
+++ branches/FNWRAP/coregrind/m_scheduler/scheduler.c 2005-12-02 14:28:28=
UTC (rev 5266)
@@ -580,6 +580,95 @@
=20
=20
/* ---------------------------------------------------------------------
+ Helper stuff for managing no-redirection translations.
+ ------------------------------------------------------------------ */
+
+/* Run a translation. argblock points to 4 UWords, 2 to carry args
+ and 2 to carry results:
+ 0: input: ptr to translation
+ 1: input: ptr to guest state
+ 2: output: next guest PC
+ 3: output: guest state pointer afterwards (=3D=3D thread return co=
de)
+*/
+extern UWord run_a_translation ( UWord* argblock );
+#if defined(VGP_x86_linux)
+asm("\n"
+".text\n"
+"run_a_translation:\n"
+" pushl %esi\n"
+" pushl %edi\n"
+" pushl %ebp\n"
+" pushl %ebx\n"
+
+" movl 20(%esp), %esi\n"
+" movl 4(%esi), %ebp\n"
+" call *0(%esi)\n"
+
+" movl 20(%esp), %esi\n"
+" movl %eax, 8(%esi)\n"
+" movl %ebp, 12(%esi)\n"
+
+" popl %ebx\n"
+" popl %ebp\n"
+" popl %edi\n"
+" popl %esi\n"
+" ret\n"
+".previous\n"
+);
+#else
+# error "Not implemented"
+#endif
+
+
+/* tid just requested a jump to the noredir version of its current
+ program counter. So make up that translation if needed, run it,
+ and return the resulting thread return code. */
+static UInt/*trc*/ handle_noredir_jump ( ThreadId tid )
+{
+ UInt trc;
+ AddrH hcode =3D 0;
+ Addr ip =3D VG_(get_IP)(tid);
+
+ Bool found =3D VG_(search_unredir_transtab)( &hcode, ip );
+ if (!found) {
+ /* Not found; we need to request a translation. */
+ if (VG_(translate)( tid, ip, /*debug*/False, 0/*not verbose*/, bbs=
_done,
+ False/*NO REDIRECTION*/ )) {
+
+ found =3D VG_(search_unredir_transtab)( &hcode, ip );
+ vg_assert2(found, "unredir translation missing after creation?!=
");
+ =20
+ } else {
+ // If VG_(translate)() fails, it's because it had to throw a
+ // signal because the client jumped to a bad address. That
+ // means that either a signal has been set up for delivery,
+ // or the thread has been marked for termination. Either
+ // way, we just need to go back into the scheduler loop.
+ return VG_TRC_BORING;
+ }
+
+ }
+
+ vg_assert(found);
+ vg_assert(hcode !=3D 0);
+=20
+ { UWord argblock[4];
+ argblock[0] =3D (UWord)hcode;
+ argblock[1] =3D (UWord)&VG_(threads)[tid].arch.vex;
+ argblock[2] =3D 0;
+ argblock[3] =3D 0;
+ trc =3D run_a_translation( &argblock[0] );
+ /* store away the guest program counter */
+ VG_(set_IP)( tid, argblock[2] );
+ if (argblock[3] =3D=3D argblock[1])
+ return VG_TRC_BORING;
+ else
+ return (UInt)argblock[3];
+ }
+}
+
+
+/* ---------------------------------------------------------------------
The scheduler proper.
------------------------------------------------------------------ */
=20
@@ -593,7 +682,8 @@
found =3D VG_(search_transtab)( NULL, ip, True/*upd_fast_cache*/ );
if (!found) {
/* Not found; we need to request a translation. */
- if (VG_(translate)( tid, ip, /*debug*/False, 0/*not verbose*/, bbs=
_done )) {
+ if (VG_(translate)( tid, ip, /*debug*/False, 0/*not verbose*/,=20
+ bbs_done, True/*allow redirection*/ )) {
found =3D VG_(search_transtab)( NULL, ip, True );=20
vg_assert2(found, "VG_TRC_INNER_FASTMISS: missing tt_fast entry=
");
=20
@@ -711,7 +801,23 @@
print_sched_event(tid, buf);
}
=20
- switch(trc) {
+ if (trc =3D=3D VEX_TRC_JMP_NOREDIR) {
+ /* If we got a request to run a no-redir version of
+ something, do so now -- handle_noredir_jump just (creates
+ and) runs that one translation. The flip side is that the
+ noredir translation can't itself return another noredir
+ request -- that would be nonsensical. It can, however,
+ return VG_TRC_BORING, which just means keep going as
+ normal. */
+ trc =3D handle_noredir_jump(tid);
+ vg_assert(trc !=3D VEX_TRC_JMP_NOREDIR);
+ }
+
+ switch (trc) {
+ case VG_TRC_BORING:
+ /* no special event, just keep going. */
+ break;
+
case VG_TRC_INNER_FASTMISS:
vg_assert(VG_(dispatch_ctr) > 1);
handle_tt_miss(tid);
@@ -927,6 +1033,14 @@
zztid, O_CLREQ_RET, sizeof(UWord), f); \
} while (0)
=20
+#define SET_CLIENT_NOREDIR(zztid, zzval) \
+ do { VG_(threads)[zztid].arch.vex.guest_NOREDIR =3D 1; \
+ VG_TRACK( post_reg_write, \
+ Vg_CoreClientReq, zztid, \
+ offsetof(VexGuestArchState,guest_NOREDIR), \
+ sizeof(UWord) ); \
+ } while (0)
+
/* ---------------------------------------------------------------------
Handle client requests.
------------------------------------------------------------------ */
@@ -971,6 +1085,11 @@
VG_(printf)("req no =3D 0x%llx, arg =3D %p\n", (ULong)req_no, arg)=
;
switch (req_no) {
=20
+ case VG_USERREQ__SET_NOREDIR:
+ SET_CLIENT_NOREDIR(tid, 1);
+ SET_CLREQ_RETVAL(tid, 0);
+ break;
+
case VG_USERREQ__CLIENT_CALL0: {
UWord (*f)(ThreadId) =3D (void*)arg[1];
if (f =3D=3D NULL)
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-02 13:29:07 UTC (rev =
5265)
+++ branches/FNWRAP/coregrind/m_translate.c 2005-12-02 14:28:28 UTC (rev =
5266)
@@ -445,11 +445,12 @@
Addr64 orig_addr,
Bool debugging_translation,
Int debugging_verbosity,
- ULong bbs_done )
+ ULong bbs_done,
+ Bool allow_redirection )
{
Addr64 redir, orig_addr_noredir =3D orig_addr;
Int tmpbuf_used, verbosity, i;
- Bool notrace_until_done, do_self_check;
+ Bool notrace_until_done, do_self_check, did_redirect;
UInt notrace_until_limit =3D 0;
NSegment* seg;
VexArch vex_arch;
@@ -474,7 +475,13 @@
=20
/* Look in the code redirect table to see if we should
translate an alternative address for orig_addr. */
- redir =3D VG_(code_redirect)(orig_addr);
+ if (allow_redirection) {
+ redir =3D VG_(code_redirect)(orig_addr);
+ did_redirect =3D redir !=3D orig_addr;
+ } else {
+ redir =3D orig_addr;
+ did_redirect =3D False;
+ }
=20
if (redir !=3D orig_addr && VG_(clo_verbosity) >=3D 2) {
Bool ok;
@@ -592,7 +599,11 @@
True, /* cleanup after instrumentation */
do_self_check,
NULL,
- verbosity
+ verbosity,
+ /* If this translation started at a redirected address,
+ then we need to ask the JIT to put in the
+ guest_NOREDIR preamble. */
+ did_redirect =20
);
=20
vg_assert(tres =3D=3D VexTransOK);
@@ -621,13 +632,25 @@
// If debugging, don't do anything with the translated block; we
// only did this for the debugging output produced along the way.
if (!debugging_translation) {
- // Note that we use orig_addr_noredir, not orig_addr, which
- // might have been changed by the redirection
- VG_(add_to_transtab)( &vge,
- orig_addr_noredir,
- (Addr)(&tmpbuf[0]),=20
- tmpbuf_used,
- do_self_check );
+
+ if (allow_redirection) {
+ // Put it into the normal TT/TC structures. This is the
+ // normal case.
+
+ // Note that we use orig_addr_noredir, not orig_addr, which
+ // might have been changed by the redirection
+ VG_(add_to_transtab)( &vge,
+ orig_addr_noredir,
+ (Addr)(&tmpbuf[0]),=20
+ tmpbuf_used,
+ do_self_check );
+ } else {
+ VG_(add_to_unredir_transtab)( &vge,
+ orig_addr_noredir,
+ (Addr)(&tmpbuf[0]),=20
+ tmpbuf_used,
+ do_self_check );
+ }
}
=20
VGP_POPCC(VgpTranslate);
Modified: branches/FNWRAP/coregrind/m_transtab.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_transtab.c 2005-12-02 13:29:07 UTC (rev 5=
265)
+++ branches/FNWRAP/coregrind/m_transtab.c 2005-12-02 14:28:28 UTC (rev 5=
266)
@@ -1203,6 +1203,114 @@
=20
=20
/*------------------------------------------------------------*/
+/*--- AUXILIARY: the unredirected TT/TC ---*/
+/*------------------------------------------------------------*/
+
+/* A very simple translation cache which holds a small number of
+ unredirected translations. This is completely independent of the
+ main tt/tc structures. When unredir_tc or unredir_tt becomes full,
+ both structures are simply dumped and we start over.
+
+ Since these translations are unredirected, the search key is (by
+ definition) the first address entry in the .vge field. */
+
+/* Sized to hold 500 translations each of size 1000 bytes. */
+
+#define UNREDIR_SZB 1000
+
+#define N_UNREDIR_TT 500
+#define N_UNREDIR_TCQ (N_UNREDIR_TT * UNREDIR_SZB / sizeof(ULong))
+
+typedef
+ struct {
+ VexGuestExtents vge;
+ Addr hcode;
+ Bool inUse;
+ }
+ UTCEntry;
+
+static ULong unredir_tc[N_UNREDIR_TCQ] __attribute__((aligned(8)));
+static Int unredir_tc_used;
+static UTCEntry unredir_tt[N_UNREDIR_TT];
+
+
+static void init_unredir_tt_tc ( void )
+{
+ Int i;
+ unredir_tc_used =3D 0;
+ for (i =3D 0; i < N_UNREDIR_TT; i++)
+ unredir_tt[i].inUse =3D False;
+}
+
+/* Add an UNREDIRECTED translation of vge to TT/TC. The translation
+ is temporarily in code[0 .. code_len-1].
+*/
+void VG_(add_to_unredir_transtab)( VexGuestExtents* vge,
+ Addr64 entry,
+ AddrH code,
+ UInt code_len,
+ Bool is_self_checking )
+{
+ Int i, j, code_szQ;
+ HChar *srcP, *dstP;
+
+ /* This is the whole point: it's not redirected! */
+ vg_assert(entry =3D=3D vge->base[0]);
+
+ /* How many unredir_tt slots are needed */ =20
+ code_szQ =3D (code_len + 7) / 8;
+
+ /* Look for an empty unredir_tc slot */
+ for (i =3D 0; i < N_UNREDIR_TT; i++)
+ if (!unredir_tt[i].inUse)
+ break;
+
+ if (i >=3D N_UNREDIR_TT || code_szQ > (N_UNREDIR_TCQ - unredir_tc_use=
d)) {
+ /* It's full; dump everything we currently have */
+ init_unredir_tt_tc();
+ i =3D 0;
+ }
+
+ vg_assert(unredir_tc_used >=3D 0);
+ vg_assert(unredir_tc_used <=3D N_UNREDIR_TCQ);
+ vg_assert(code_szQ > 0);
+ vg_assert(code_szQ + unredir_tc_used <=3D N_UNREDIR_TCQ);
+ vg_assert(i >=3D 0 && i < N_UNREDIR_TT);
+ vg_assert(unredir_tt[i].inUse =3D=3D False);
+
+ dstP =3D (HChar*)&unredir_tc[unredir_tc_used];
+ srcP =3D (HChar*)code;
+ for (j =3D 0; j < code_len; j++)
+ dstP[j] =3D srcP[j];
+
+ unredir_tt[i].inUse =3D True;
+ unredir_tt[i].vge =3D *vge;
+ unredir_tt[i].hcode =3D (Addr)dstP;
+
+ unredir_tc_used +=3D code_szQ;
+ vg_assert(unredir_tc_used >=3D 0);
+ vg_assert(unredir_tc_used <=3D N_UNREDIR_TCQ);
+
+ vg_assert(&dstP[code_len] <=3D (HChar*)&unredir_tc[unredir_tc_used]);
+}
+
+Bool VG_(search_unredir_transtab) ( /*OUT*/AddrH* result,
+ Addr64 guest_addr )
+{
+ Int i;
+ for (i =3D 0; i < N_UNREDIR_TT; i++) {
+ if (!unredir_tt[i].inUse)
+ continue;
+ if (unredir_tt[i].vge.base[0] =3D=3D guest_addr) {
+ *result =3D (AddrH)unredir_tt[i].hcode;
+ return True;
+ }
+ }
+ return False;
+}
+
+
+/*------------------------------------------------------------*/
/*--- Initialisation. ---*/
/*------------------------------------------------------------*/
=20
Modified: branches/FNWRAP/coregrind/pub_core_dispatch_asm.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_dispatch_asm.h 2005-12-02 13:29:07=
UTC (rev 5265)
+++ branches/FNWRAP/coregrind/pub_core_dispatch_asm.h 2005-12-02 14:28:28=
UTC (rev 5266)
@@ -42,6 +42,7 @@
=20
/* And some more of our own. These must not have the same values as
those from libvex_trc_values.h. (viz, 60 or below is safe). */
+#define VG_TRC_BORING 29 /* no event; just keep going */
#define VG_TRC_INNER_FASTMISS 37 /* TRC only; means fast-cache miss.=
*/
#define VG_TRC_INNER_COUNTERZERO 41 /* TRC only; means bb ctr =3D=3D 0 =
*/
#define VG_TRC_FAULT_SIGNAL 43 /* TRC only; got sigsegv/sigbus */
Modified: branches/FNWRAP/coregrind/pub_core_translate.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_translate.h 2005-12-02 13:29:07 UT=
C (rev 5265)
+++ branches/FNWRAP/coregrind/pub_core_translate.h 2005-12-02 14:28:28 UT=
C (rev 5266)
@@ -41,7 +41,8 @@
Addr64 orig_addr,
Bool debugging_translation,
Int debugging_verbosity,
- ULong bbs_done );
+ ULong bbs_done,
+ Bool allow_redirection );
=20
#endif // __PUB_CORE_TRANSLATE_H
=20
Modified: branches/FNWRAP/coregrind/pub_core_transtab.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_transtab.h 2005-12-02 13:29:07 UTC=
(rev 5265)
+++ branches/FNWRAP/coregrind/pub_core_transtab.h 2005-12-02 14:28:28 UTC=
(rev 5266)
@@ -63,6 +63,19 @@
=20
extern UInt VG_(get_bbs_translated) ( void );
=20
+/* Add to / search the auxiliary, small, unredirected translation
+ table. */
+
+extern
+void VG_(add_to_unredir_transtab)( VexGuestExtents* vge,
+ Addr64 entry,
+ AddrH code,
+ UInt code_len,
+ Bool is_self_checking );
+extern=20
+Bool VG_(search_unredir_transtab) ( /*OUT*/AddrH* result,
+ Addr64 guest_addr );
+
// BB profiling stuff
=20
typedef struct _BBProfEntry {
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-02 13:29:07 UTC (rev=
5265)
+++ branches/FNWRAP/coregrind/vg_preloaded.c 2005-12-02 14:28:28 UTC (rev=
5266)
@@ -71,3 +71,68 @@
/*--- end ---*/
/*--------------------------------------------------------------------*/
=20
+#define PTH_FUNC(ret_ty, f, args...) \
+ ret_ty VG_REPLACE_FUNCTION(libpthreadZdsoZd0, f)(args); \
+ ret_ty VG_REPLACE_FUNCTION(libpthreadZdsoZd0, f)(args)
+
+#define LIBC_FUNC(ret_ty, f, args...) \
+ ret_ty VG_REPLACE_FUNCTION(libcZdsoZd6, f)(args); \
+ ret_ty VG_REPLACE_FUNCTION(libcZdsoZd6, f)(args)
+
+#include <stdio.h>
+#include <pthread.h>
+
+#if 1
+PTH_FUNC(int, pthread_create, // pthread_create@*
+ pthread_t *thread, const pthread_attr_t *attr,
+ void *(*start) (void *), void *arg)
+{
+ int ret;
+ fprintf(stderr, "<< pthread_create wrapper"); fflush(stderr);
+
+ VALGRIND_SET_NOREDIR;
+ ret =3D pthread_create(thread, attr, start, arg);
+
+ fprintf(stderr, " -> %d >>\n", ret);
+ return ret;
+}
+
+PTH_FUNC(int, pthread_mutex_lock, pthread_mutex_t *mutex)
+{
+ int ret;
+ fprintf(stderr, "<< pthread_mxlock %p", mutex); fflush(stderr);
+
+ VALGRIND_SET_NOREDIR;
+ ret =3D pthread_mutex_lock(mutex);
+
+ fprintf(stderr, " -> %d >>\n", ret);
+ return ret;
+}
+
+PTH_FUNC(int, pthread_mutex_unlock, pthread_mutex_t *mutex)
+{
+ int ret;
+ fprintf(stderr, "<< pthread_mxunlk %p", mutex); fflush(stderr);
+
+ VALGRIND_SET_NOREDIR;
+ ret =3D pthread_mutex_unlock(mutex);
+
+ fprintf(stderr, " -> %d >>\n", ret);
+ return ret;
+}
+
+#endif
+
+#if 0
+LIBC_FUNC(int, fclose, void* f)
+{
+ int ret;
+ fprintf(stderr, "<< fclose(%p)\n", f);
+
+ VALGRIND_SET_NOREDIR;
+ ret =3D fclose(f);
+
+ fprintf(stderr, ">>\n");
+ return ret;
+}
+#endif
Modified: branches/FNWRAP/include/valgrind.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/valgrind.h 2005-12-02 13:29:07 UTC (rev 5265)
+++ branches/FNWRAP/include/valgrind.h 2005-12-02 14:28:28 UTC (rev 5266)
@@ -248,6 +248,7 @@
typedef
enum { VG_USERREQ__RUNNING_ON_VALGRIND =3D 0x1001,
VG_USERREQ__DISCARD_TRANSLATIONS =3D 0x1002,
+ VG_USERREQ__SET_NOREDIR =3D 0x1003,
=20
/* These allow any function to be called from the
simulated CPU but run on the real CPU.
@@ -310,6 +311,19 @@
_qzz_addr, _qzz_len, 0, 0); \
}
=20
+/* Sets this thread's guest_NOREDIR register to 1, so that the next
+ entry by this thread into a redirected translation will cause it
+ instead to jump to the non-redirected version. */
+#define VALGRIND_SET_NOREDIR __extension__ \
+ ({unsigned int _qzz_res; \
+ VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0, \
+ VG_USERREQ__SET_NOREDIR, \
+ 0, 0, 0, 0); \
+ _qzz_res; \
+ })
+
+
+
#ifdef NVALGRIND
=20
#define VALGRIND_PRINTF(...)
|
|
From: Josef W. <Jos...@gm...> - 2005-12-05 05:29:14
|
On Friday 02 December 2005 15:28, sv...@va... wrote:
> Initial function wrapping hacks. Note, a work in progress - expect
> borkage. Works well enough to intercept pthread_mutex_{lock,unlock}.
Just to understand the idea: You have a per-thread flag to decide about
non-redirection. Ie. only one wrapper can be active at one point in time.
Is this enough for pthread? If one pthread function is calling another
one in its implementation, no wrapper will be called.
Is there any way to support longjmps in wrapped functions?
Josef
|