Using and understanding the Valgrind core: Advanced Topics
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.
It is regrettable that this limitation exists.
Function
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.
This is not a limitation of the function wrapping
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.
49
Содержание BBV
Страница 176: ...Valgrind FAQ Release 3 8 0 10 August 2012 Copyright 2000 2012 Valgrind Developers Email valgrind valgrind org ...
Страница 177: ...Valgrind FAQ Table of Contents Valgrind Frequently Asked Questions 1 ii ...
Страница 302: ...README mips based on newer GCC versions if possible 95 ...
Страница 303: ...GNU Licenses ...
Страница 304: ...GNU Licenses Table of Contents 1 The GNU General Public License 1 2 The GNU Free Documentation License 8 ii ...