|
From: Andres T. <and...@ta...> - 2015-03-19 12:32:26
|
Hi, I'm having troubles wrapping functions from pthread.
I made a very simple tool fo valgrind-3.10.1 that just wraps
pthread_create but I can't make it work and I don't know why.
The tool has just 2 files: fb_main.c and fb_intercept.c
------------------------------fb_main.c-----------------------------------------------
#include "pub_tool_tooliface.h"
static void fb_post_clo_init(void)
{
}
static IRSB* fb_instrument ( VgCallbackClosure* closure,
IRSB* bb,
const VexGuestLayout* layout,
const VexGuestExtents* vge,
const VexArchInfo* archinfo_host,
IRType gWordTy, IRType hWordTy )
{
return bb;
}
static void fb_fini(Int exitcode)
{
}
static void fb_pre_clo_init(void)
{
VG_(details_name) ("Nulgrind");
VG_(details_version) (NULL);
VG_(details_description) ("the minimal Valgrind tool");
VG_(details_copyright_author)(
"Copyright (C) 2002-2013, and GNU GPL'd, by Nicholas Nethercote.");
VG_(details_bug_reports_to) (VG_BUGS_TO);
VG_(basic_tool_funcs) (fb_post_clo_init,
fb_instrument,
fb_fini);
VG_(needs_core_errors) ();
}
VG_DETERMINE_INTERFACE_VERSION(fb_pre_clo_init)
-------------------------------------------------------------------------------------------------------
and
--------------------------------- 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 <pthread.h>
int I_WRAP_SONAME_FNNAME_ZZ(libpthreadZdsoZd0, pthreadZucreateZAZa)
(pthread_t *thread, const pthread_attr_t *attr, void *(*start)
(void *), void *arg)
{
int result = 1;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
CALL_FN_W_WWWW(result, fn, thread, attr, start, arg);
return result;
}
-------------------------------------------------------------------------------------------------------------------
But when I try to run a program tah uses pthread I'm getting this:
----------------------------------------------------------------------------------------------------------
==6540== Nulgrind, the minimal Valgrind tool
==6540== Copyright (C) 2002-2013, and GNU GPL'd, by Nicholas Nethercote.
==6540== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==6540== Command: ../prueba/a.out
==6540==
--6540-- VG_USERREQ__CLIENT_CALL2: func=0x0
==6540==
==6540== Process terminating with default action of signal 11 (SIGSEGV)
==6540== Access not within mapped region at address 0x10
==6540== at 0x35006084D1: pthread_create@@GLIBC_2.2.5 (in
/usr/lib64/libpthread-2.18.so)
==6540== by 0x4A077CD: pthread_create@* (fb_intercept.c:42)
==6540== by 0x4008D1: main (in /home/andres/Documents/valgrind/prueba/a.out)
==6540== If you believe this happened as a result of a stack
==6540== overflow in your program's main thread (unlikely but
==6540== possible), you can try to increase the size of the
==6540== main thread stack using the --main-stacksize= flag.
==6540== The main thread stack size used in this run was 8388608.
==6540==
==6540== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Segmentation fault (core dumped)
-----------------------------------------------------------------------------------------------------------
If I comment the "CALL_FN_W_WWWW()" in fb_intercept.c when I wrap
pthread_create, there are no problems, just pthread_create doesn't
work properly as expected.
I have not a single clue what's going on but maybe someone can help me
know what I'm doing wrong.
ps:I'm working in fedora 20 and ubuntu 14.04
Regards,
Andrés.
|