|
From: Nicholas N. <nj...@cs...> - 2005-03-28 00:53:55
|
On Sun, 27 Mar 2005, Jeremy Fitzhardinge wrote: > The tool interface is going to be a bit more complex, but the fewer > complex types the better if we actually want to achieve any kind of > long-term ABI stability. Yep. > The basic problem is that the thread modelling code needs to know the mapping > between a libpthread thread identifier (pthread_t) and the underlying > Valgrind thread ID. The way I implement this is by repointing the > thread-start function to an intercept function in vg_intercept.c which does a > pthread_self() call; the pthread modelling code wraps this pthread_self call > and looks at the return value. Because it knows what ThreadID is making the > call, it can create the mapping from pthread_t -> ThreadID. > > This is implemented by allocating a small piece of memory (wrapper info, > known as vg_pthread_newthread_data) in the pthread_create "before" wrapper > function, which stores the original (start_func, arg) pair. It then replaces > the arguments to pthread_create()-proper with a (start_func_wrapper, > wrapper_info_ptr) pair. When the start_func_wrapper gets called in the new > thread, it calls pthread_self(), extracts the original function and argument > from the wrapper info, frees the wrapper info and calls the original > (*start_func)(arg). > > By necessesity, the memory needs to be allocated within Valgrind, but freed > by the client code. We could add a special-case client callback to free this > specific piece of memory, but USERREQ_FREE seemed like the right thing to use > since it was there. Also, since this is allocated memory being used by the > VCPU, all its uses are subject to inspection by the tool, so it has to all > look OK to the tool (or suppressed around, which definitely isn't nice). Hmm, I didn't really follow that... I'm not clear on what functions/bits of memory are from the client, what are from the pthreads implementation, and what are in Valgrind/pthreadmodel. Where would the USERREQ_FREE requrest be embedded in the client? Would every client have to have such a request in it? N |