3.3.6. Limitations - original function signatures
As shown in the above example, to call the original you must use a macro of the form CALL_FN_ * . For technical
reasons it is impossible to create a single macro to deal with all argument types and numbers, so a family of macros
covering the most common cases is supplied. In what follows, 'W' denotes a machine-word-typed value (a pointer or
a C long), and 'v' denotes C's void type. The currently available macros are:
CALL_FN_v_v
-- call an original of type void fn ( void )
CALL_FN_W_v
-- call an original of type long fn ( void )
CALL_FN_v_W
-- call an original of type void fn ( long )
CALL_FN_W_W
-- call an original of type long fn ( long )
CALL_FN_v_WW
-- call an original of type void fn ( long, long )
CALL_FN_W_WW
-- call an original of type long fn ( long, long )
CALL_FN_v_WWW -- call an original of type void fn ( long, long, long )
CALL_FN_W_WWW -- call an original of type long fn ( long, long, long )
CALL_FN_W_WWWW -- call an original of type long fn ( long, long, long, long )
CALL_FN_W_5W
-- call an original of type long fn ( long, long, long, long, long )
CALL_FN_W_6W
-- call an original of type long fn ( long, long, long, long, long, long )
and so on, up to
CALL_FN_W_12W
The set of supported types can be expanded as needed.
wrapping has proven difficult to implement, with a certain apparently unavoidable level of ickiness. After several
implementation attempts, the present arrangement appears to be the least-worst tradeoff. At least it works reliably in
the presence of dynamic linking and dynamic code loading/unloading.
You should not attempt to wrap a function of one type signature with a wrapper of a different type signature.
Such trickery will surely lead to crashes or strange behaviour.
implementation, merely a reflection of the fact that it gives you sweeping powers to shoot yourself in the foot if you
are not careful. Imagine the instant havoc you could wreak by writing a wrapper which matched any function name
in any soname - in effect, one which claimed to be a wrapper for all functions in the process.
3.3.7. Examples
In the source tree, memcheck/tests/wrap[1-8].c provide a series of examples, ranging from very simple to
quite advanced.
mpi/libmpiwrap.c is an example of wrapping a big, complex API (the MPI-2 interface). This file defines almost
300 different wrappers.
Using and understanding the Valgrind core: Advanced Topics
It is regrettable that this limitation exists.
This is not a limitation of the function wrapping
Function
49
Need help?
Do you have a question about the Software and is the answer not in the manual?