|
From: Andres T. <and...@ta...> - 2015-03-17 18:01:42
|
Hi, I've been having a problem when wrapping functions in programs
using functions from pthread.h.
for example I have my tool:
------------------- fb_intercept.c
----------------------------------------------
#include "pub_tool_basics.h"
#include "pub_tool_redir.h"
#include "pub_tool_clreq.h"
#include "valgrind.h"
#include "config.h"
#include <stdio.h>
int I_WRAP_SONAME_FNNAME_ZU(NONE,testFunction)( int a)
{
int result;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
printf("foo's wrapper: args %d\n", a);
a = 0;
CALL_FN_W_W(result, fn, a);
printf("foo's wrapper: result %d\n", result);
return result;
}
-------------------------------------------------------------------------------------------------------
and main1.c and main2.c
--------------------------------- main1.c-------------------------------------
#include <stdio.h>
int testFunction(int a)
{
return a+1;
}
int main(void)
{
printf("%d\n", testFunction(5));
return 0;
}
-------------------------------------------------------------------------------------
--------------------------------- main2.c-------------------------------------
#include <stdio.h>
#include <pthread.h>
int testFunction(int a)
{
return a+1;
}
void* dummy(void *var)
{
return var;
}
int main(void)
{
pthread_t tid;
pthread_create(&tid, NULL, dummy, &var);
printf("%d\n", testFunction(5));
return 0;
}
-------------------------------------------------------------------------------------
when i run:
valgrind --tool=foobar main1
I get:
==12362== Nulgrind, the minimal Valgrind tool
==12362== Copyright (C) 2002-2013, and GNU GPL'd, by Nicholas Nethercote.
==12362== Using Valgrind-3.11.0.SVN and LibVEX; rerun with -h for copyright info
==12362== Command: main1
==12362==
foo's wrapper: args 5
foo's wrapper: result 1
1
And everything it's fine but when I run:
valgrind --tool=foobar main2
I get:
==12396== Nulgrind, the minimal Valgrind tool
==12396== Copyright (C) 2002-2013, and GNU GPL'd, by Nicholas Nethercote.
==12396== Using Valgrind-3.11.0.SVN and LibVEX; rerun with -h for copyright info
==12396== Command: main2
==12396==
--12396-- VG_USERREQ__CLIENT_CALL2: func=0x0
==12396==
==12396== Process terminating with default action of signal 11 (SIGSEGV)
==12396== Access not within mapped region at address 0x10
==12396== at 0x35006084D1: pthread_create@@GLIBC_2.2.5 (in
/usr/lib64/libpthread-2.18.so)
==12396== by 0x400698: main (in main2)
==12396== If you believe this happened as a result of a stack
==12396== overflow in your program's main thread (unlikely but
==12396== possible), you can try to increase the size of the
==12396== main thread stack using the --main-stacksize= flag.
==12396== The main thread stack size used in this run was 8388608.
==12396==
Segmentation fault (core dumped)
I have no idea what's going on but maybe someone have a clue.
Regards,
Andres.
|