From: Julian S. <js...@ac...> - 2007-03-29 21:39:44
|
Dirk > the patch is below, and its not working. probably I'm doing something > stupid, No - this is subtle. > but I can't find an example for a wrapper function anywhere. auxprogs/libmpiwrap.c has a huge collection of them. You've hit the distinction between replacement functions and wrapper functions. A replacement (eg malloc) simply replaces some function; there is no way to call onwards to the original. A wrapper function is more powerful - it gives you a way to find out the original and call onwards to it. I think your wrapper might produce an infinite loop, since the call to putenv just goes back to the wrapper. Try the code below. All this strange stuff is documented at http://www.valgrind.org/docs/manual/manual-core.html#manual-core.wrapping J /* putenv */ int VG_WRAP_FUNCTION_ZU(m_libc_soname, putenv) (char* string); int VG_WRAP_FUNCTION_ZU(m_libc_soname, putenv) (char* string) { OrigFn fn; char* p; VALGRIND_GET_ORIG_FN(fn); // remember the original p = string; if (string) { int len = 0; while (*p++) len++; VALGRIND_CHECK_MEM_IS_DEFINED(string, len+1); } // call original, ultra-magic hacks to avoid recursion unsigned long tmp; CALL_FN_W_W(tmp, fn, (unsigned long)string); return (int)tmp; } |