thank you for your answer.
But when i use  _WRAP_ macros like following code, it gives me an error.
*code:*
long I_WRAP_SONAME_FNNAME_ZU(libcZdsoZd6,malloc) ( long n )
{
   char *  r;
   OrigFn fn;
   printf("11111\n");
   VALGRIND_GET_ORIG_FN(fn);
   CALL_FN_W_W(r, fn, n);
   //printf("in wrapper1-post: fact(%d) = %x\n", n, r);
   return r;
}

/* --------------- */

int main ( void )
{
   char * r , *x, *y;
   //printf("computing fact(5)\n");
   //r = fact(5);
   r = malloc(0x20);
   x = malloc(0x20);
   printf("malloc(0x20) = %x \n",r );
   printf("malloc(0x20) = %x \n",x );

   return 0;
}
* error:*
==14498== Stack overflow in thread #1: can't grow stack to 0xfe04d000
==14498==
==14498== Process terminating with default action of signal 11 (SIGSEGV)
==14498==  Access not within mapped region at address 0xFE04DFFC
==14498== Stack overflow in thread #1: can't grow stack to 0xfe04d000
==14498==    at 0x40B1183: _IO_doallocbuf (genops.c:394)
==14498==  If you believe this happened as a result of a stack
==14498==  overflow in your program's main thread (unlikely but
==14498==  possible), you can try to increase the size of the
==14498==  main thread stack using the --main-stacksize= flag.
==14498==  The main thread stack size used in this run was 8388608.

But when i comment out the ' printf("11111\n"); ', It seems ok.....

On Thu, Jul 12, 2018 at 7:24 PM Tom Hughes <[email protected]> wrote:

> On 12/07/18 10:26, shuai xi wrote:
>
> > I know that 'Memcheck's implementation of malloc has "nothing to do"
> > with glibc's implementation' after readind some code of valgrind, but i
> > want to use the glibc's malloc to avoid changing heap layout.
> > Memcheck sets the VG_(needs_malloc_replacement) to hook malloc and exec
> > MC_(malloc) instead of real malloc. It's very convenient. So can i
> > get the address of the original malloc in MC_(malloc) and exec it?
> > if not,can i use I_WRAP_SONAME_FNNAME_ZU function to hook malloc in my
> > valgrind tool's code?
>
> Yes if you want to wrap the function rather than replacing it
> then use the _WRAP_ macros and then your wrapper can get the
> original address and call it.
>
> Tom
>
> --
> Tom Hughes ([email protected])
> http://compton.nu/
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Valgrind-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to