|
From: <sv...@va...> - 2005-12-07 22:20:27
|
Author: sewardj
Date: 2005-12-07 22:20:19 +0000 (Wed, 07 Dec 2005)
New Revision: 5313
Log:
Nasty tri-state hack to avoid looping on libpthread wrappers.
Modified:
branches/FNWRAP/coregrind/m_scheduler/scheduler.c
branches/FNWRAP/coregrind/m_translate.c
branches/FNWRAP/coregrind/vg_preloaded.c
branches/FNWRAP/include/valgrind.h
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-07 21:07:35=
UTC (rev 5312)
+++ branches/FNWRAP/coregrind/m_scheduler/scheduler.c 2005-12-07 22:20:19=
UTC (rev 5313)
@@ -1033,13 +1033,16 @@
zztid, O_CLREQ_RET, sizeof(UWord), f); \
} while (0)
=20
-#define SET_CLIENT_NRADDR(zztid, zzaddr) \
- do { VG_(threads)[zztid].arch.vex.guest_NRFLAG =3D 1; \
- VG_(threads)[zztid].arch.vex.guest_NRADDR =3D (zzaddr); \
+#define SET_CLIENT_NRFLAG(zztid, zzflag) \
+ do { VG_(threads)[zztid].arch.vex.guest_NRFLAG =3D (zzflag); \
VG_TRACK( post_reg_write, \
Vg_CoreClientReq, zztid, \
offsetof(VexGuestArchState,guest_NRFLAG), \
sizeof(UWord) ); \
+ } while (0)
+
+#define SET_CLIENT_NRADDR(zztid, zzaddr) \
+ do { VG_(threads)[zztid].arch.vex.guest_NRADDR =3D (zzaddr); \
VG_TRACK( post_reg_write, \
Vg_CoreClientReq, zztid, \
offsetof(VexGuestArchState,guest_NRADDR), \
@@ -1048,6 +1051,8 @@
=20
#define GET_CLIENT_NRFLAG(zztid) \
VG_(threads)[zztid].arch.vex.guest_NRFLAG
+#define GET_CLIENT_NRADDR(zztid) \
+ VG_(threads)[zztid].arch.vex.guest_NRADDR
=20
=20
/* ---------------------------------------------------------------------
@@ -1095,14 +1100,51 @@
switch (req_no) {
=20
case VG_USERREQ__PUSH_NRADDR: {
- Addr noredir =3D arg[1];
- if (GET_CLIENT_NRFLAG(tid) !=3D 0) {
- /* The 1-entry stack is full, so we must fail (return 1). */
- SET_CLREQ_RETVAL(tid, 1);
- } else {
- SET_CLIENT_NRADDR(tid, noredir); /* also sets _NRFLAG */
+ Addr nraddr =3D arg[1];
+ UWord do_check =3D arg[2];
+
+ if (do_check) {
+
+ /* This is the normal (safe) case. */
+ switch (GET_CLIENT_NRFLAG(tid)) {
+ case 0:
+ SET_CLIENT_NRFLAG(tid, 1);
+ SET_CLIENT_NRADDR(tid, nraddr);
+ SET_CLREQ_RETVAL(tid, 0);
+ break;
+ case 1:=20
+ case 2:
+ /* The 1-entry stack is full, so we must fail
+ (return 1). */
+ SET_CLREQ_RETVAL(tid, 1);
+ break;
+ default:
+ vg_assert2(0, "VG_USERREQ__PUSH_NRADDR(checked):"
+ " bogus value");
+ }
+
+ } else {
+
+ /* This is the not-normal (unsafe) case. */
+ switch (GET_CLIENT_NRFLAG(tid)) {
+ case 0:
+ SET_CLIENT_NRFLAG(tid, 1);
+ SET_CLIENT_NRADDR(tid, nraddr);
+ break;
+ case 1:=20
+ SET_CLIENT_NRFLAG(tid, 2);
+ break;
+ case 2:
+ break;
+ default:
+ vg_assert2(0, "VG_USERREQ__PUSH_NRADDR(***unchecked***=
):"
+ " bogus value");
+ }
+ /* Unchecked case always succeeds */
SET_CLREQ_RETVAL(tid, 0);
- }
+
+ }
+
break;
}
=20
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-07 21:07:35 UTC (rev =
5312)
+++ branches/FNWRAP/coregrind/m_translate.c 2005-12-07 22:20:19 UTC (rev =
5313)
@@ -486,7 +486,8 @@
did_redirect =3D False;
}
=20
- if (redir !=3D orig_addr && VG_(clo_verbosity) >=3D 2) {
+ if (redir !=3D orig_addr=20
+ && (VG_(clo_verbosity) >=3D 2 || VG_(clo_trace_redir))) {
Bool ok;
Char name1[64] =3D "";
Char name2[64] =3D "";
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-07 21:07:35 UTC (rev=
5312)
+++ branches/FNWRAP/coregrind/vg_preloaded.c 2005-12-07 22:20:19 UTC (rev=
5313)
@@ -77,10 +77,6 @@
ret_ty VG_REDIRECT_FUNCTION_ZZ(libpthreadZdsoZd0,f)(args); \
ret_ty VG_REDIRECT_FUNCTION_ZZ(libpthreadZdsoZd0,f)(args)
=20
-#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>
=20
@@ -93,8 +89,7 @@
int ret;
fprintf(stderr, "<< pthread_create wrapper"); fflush(stderr);
=20
- VALGRIND_SET_NOREDIR;
- ret =3D pthread_create(thread, attr, start, arg);
+ CALL_ORIG_FN_4_UNCHECKED(ret, pthread_create, thread,attr,start,arg);
=20
fprintf(stderr, " -> %d >>\n", ret);
return ret;
@@ -107,8 +102,7 @@
int ret;
fprintf(stderr, "<< pthread_mxlock %p", mutex); fflush(stderr);
=20
- VALGRIND_SET_NOREDIR;
- ret =3D pthread_mutex_lock(mutex);
+ CALL_ORIG_FN_1_UNCHECKED(ret, pthread_mutex_lock, mutex);
=20
fprintf(stderr, " -> %d >>\n", ret);
return ret;
@@ -121,8 +115,7 @@
int ret;
fprintf(stderr, "<< pthread_mxunlk %p", mutex); fflush(stderr);
=20
- VALGRIND_SET_NOREDIR;
- ret =3D pthread_mutex_unlock(mutex);
+ CALL_ORIG_FN_1_UNCHECKED(ret, pthread_mutex_unlock, mutex);
=20
fprintf(stderr, " -> %d >>\n", ret);
return ret;
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-07 21:07:35 UTC (rev 5312)
+++ branches/FNWRAP/include/valgrind.h 2005-12-07 22:20:19 UTC (rev 5313)
@@ -315,17 +315,19 @@
that the next entry by this thread into a redirected translation
whose address is on top of the stack will instead to jump to the
non-redirected version. Returns 0 if success, 1 if failure. */
-#define VALGRIND_PUSH_NRADDR(_qzz_addr) __extension__ \
+#define VALGRIND_PUSH_NRADDR(_qzz_addr,_qzz_check) __extension__ \
({unsigned long _qzz_res; \
VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0/*native result*/, \
VG_USERREQ__PUSH_NRADDR, \
- _qzz_addr, 0, 0, 0); \
+ _qzz_addr, _qzz_check, 0, 0); \
_qzz_res; \
})
+
#define VALGRIND_PUSH_NRADDR_AND_CHECK(_addr) \
+ /* Always use this one -- it's safer. */ \
do { \
extern void exit(int); \
- long _r =3D VALGRIND_PUSH_NRADDR(_addr); \
+ long _r =3D VALGRIND_PUSH_NRADDR(_addr,1); \
if (_r) { \
VALGRIND_PRINTF_BACKTRACE( \
"Valgrind: function wrapping: " \
@@ -333,6 +335,11 @@
exit(1); \
} \
} while (0)
+#define VALGRIND_PUSH_NRADDR_NO_CHECK(_addr) \
+ /* Don't use this. This is a horrible kludge for libpthread. */ \
+ do { \
+ (void) VALGRIND_PUSH_NRADDR(_addr,0); \
+ } while (0)
=20
=20
#ifdef NVALGRIND
@@ -520,9 +527,38 @@
id, start, end, 0); \
}
=20
+/* ---------------------------------------------------------- */
+/* --- Hacky macros for writing function wrappers. --- */
+/* --- XXXXXXX DANGEROUS. DO NOT USE. XXXXXXXXXX --- */
+/* ---------------------------------------------------------- */
=20
-/* --- End-user functions for writing function wrappers. --- */
+#define CALL_ORIG_FN_1_UNCHECKED(lval,fn,arg1) \
+ do { \
+ __typeof__(&(fn)) _fn =3D &(fn); \
+ __typeof__(lval) _lval; \
+ __typeof__(arg1) _arg1 =3D (arg1); \
+ VALGRIND_PUSH_NRADDR_NO_CHECK(_fn); \
+ _lval =3D (*_fn)(_arg1); \
+ lval =3D _lval; \
+ } while (0)
=20
+#define CALL_ORIG_FN_4_UNCHECKED(lval,fn,arg1,arg2,arg3,arg4) \
+ do { \
+ __typeof__(&(fn)) _fn =3D &(fn); \
+ __typeof__(lval) _lval; \
+ __typeof__(arg1) _arg1 =3D (arg1); \
+ __typeof__(arg2) _arg2 =3D (arg2); \
+ __typeof__(arg3) _arg3 =3D (arg3); \
+ __typeof__(arg4) _arg4 =3D (arg4); \
+ VALGRIND_PUSH_NRADDR_NO_CHECK(_fn); \
+ _lval =3D (*_fn)(_arg1,_arg2,_arg3,_arg4); \
+ lval =3D _lval; \
+ } while (0)
+
+/* ---------------------------------------------------------- */
+/* --- End-user functions for writing function wrappers. --- */
+/* ---------------------------------------------------------- */
+
/* Use these to write the name of your wrapper. NOTE: duplicates
VG_REDIRECT_FUNCTION_Z{U,Z} in pub_tool_redir.h. */
=20
@@ -546,7 +582,7 @@
(*_fn)(); \
} while (0)
=20
-/* returns an arg, takes one arg */
+/* returns a value, takes one arg */
#define CALL_ORIG_FN_1(lval,fn,arg1) \
do { \
__typeof__(&(fn)) _fn =3D &(fn); \
@@ -557,4 +593,18 @@
lval =3D _lval; \
} while (0)
=20
+/* returns a value, takes four args */
+#define CALL_ORIG_FN_4(lval,fn,arg1,arg2,arg3,arg4) \
+ do { \
+ __typeof__(&(fn)) _fn =3D &(fn); \
+ __typeof__(lval) _lval; \
+ __typeof__(arg1) _arg1 =3D (arg1); \
+ __typeof__(arg2) _arg2 =3D (arg2); \
+ __typeof__(arg3) _arg3 =3D (arg3); \
+ __typeof__(arg4) _arg4 =3D (arg4); \
+ VALGRIND_PUSH_NRADDR_AND_CHECK(_fn); \
+ _lval =3D (*_fn)(_arg1,_arg2,_arg3,_arg4); \
+ lval =3D _lval; \
+ } while (0)
+
#endif /* __VALGRIND_H */
|