Merge in function wrapping support from the FNWRAP branch. That

branch hereby becomes inactive.  This currently breaks everything
except x86; fixes for amd64/ppc32 to follow.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@5520
This commit is contained in:
Julian Seward
2006-01-12 12:32:32 +00:00
parent 5777709dc1
commit f9a9e03c7a
56 changed files with 3492 additions and 1348 deletions

View File

@@ -49,7 +49,7 @@
// VALGRIND_NON_SIMD_CALL[12]
#include "pub_core_debuginfo.h" // needed for pub_core_redir.h :(
#include "pub_core_mallocfree.h" // for VG_MIN_MALLOC_SZB, VG_AR_CLIENT
#include "pub_core_redir.h" // for VG_REPLACE_FUNCTION
#include "pub_core_redir.h" // for VG_REDIRECT_FUNCTION_*
#include "pub_core_replacemalloc.h"
/* Some handy Z-encoded names */
@@ -90,10 +90,11 @@ static void init(void) __attribute__((constructor));
__builtin_delete, calloc, realloc, memalign, and friends.
None of these functions are called directly - they are not meant to
be found by the dynamic linker. But ALL client calls to malloc() and
friends wind up here eventually. They get called because vg_replace_malloc
installs a bunch of code redirects which causes Valgrind to use these
functions rather than the ones they're replacing.
be found by the dynamic linker. But ALL client calls to malloc()
and friends wind up here eventually. They get called because
vg_replace_malloc installs a bunch of code redirects which causes
Valgrind to use these functions rather than the ones they're
replacing.
*/
/* Generate a replacement for 'fnname' in object 'soname', which calls
@@ -101,8 +102,8 @@ static void init(void) __attribute__((constructor));
*/
#define ALLOC_or_NULL(soname, fnname, vg_replacement) \
\
void* VG_REPLACE_FUNCTION(soname,fnname) (SizeT n); \
void* VG_REPLACE_FUNCTION(soname,fnname) (SizeT n) \
void* VG_REPLACE_FUNCTION_ZU(soname,fnname) (SizeT n); \
void* VG_REPLACE_FUNCTION_ZU(soname,fnname) (SizeT n) \
{ \
void* v; \
\
@@ -121,8 +122,8 @@ static void init(void) __attribute__((constructor));
*/
#define ALLOC_or_BOMB(soname, fnname, vg_replacement) \
\
void* VG_REPLACE_FUNCTION(soname,fnname) (SizeT n); \
void* VG_REPLACE_FUNCTION(soname,fnname) (SizeT n) \
void* VG_REPLACE_FUNCTION_ZU(soname,fnname) (SizeT n); \
void* VG_REPLACE_FUNCTION_ZU(soname,fnname) (SizeT n) \
{ \
void* v; \
\
@@ -219,8 +220,8 @@ ALLOC_or_BOMB(m_libc_dot_so_star, __builtin_vec_new, __builtin_vec_new );
*/
#define FREE(soname, fnname, vg_replacement) \
\
void VG_REPLACE_FUNCTION(soname,fnname) (void *p); \
void VG_REPLACE_FUNCTION(soname,fnname) (void *p) \
void VG_REPLACE_FUNCTION_ZU(soname,fnname) (void *p); \
void VG_REPLACE_FUNCTION_ZU(soname,fnname) (void *p) \
{ \
MALLOC_TRACE(#vg_replacement "(%p)", p ); \
if (p == NULL) \
@@ -262,8 +263,8 @@ FREE(m_libc_dot_so_star, _ZdaPvRKSt9nothrow_t, __builtin_vec_delete );
#define CALLOC(soname, fnname) \
\
void* VG_REPLACE_FUNCTION(soname,fnname) ( SizeT nmemb, SizeT size ); \
void* VG_REPLACE_FUNCTION(soname,fnname) ( SizeT nmemb, SizeT size ) \
void* VG_REPLACE_FUNCTION_ZU(soname,fnname) ( SizeT nmemb, SizeT size ); \
void* VG_REPLACE_FUNCTION_ZU(soname,fnname) ( SizeT nmemb, SizeT size ) \
{ \
void* v; \
\
@@ -280,8 +281,8 @@ CALLOC(m_libc_dot_so_star, calloc);
#define REALLOC(soname, fnname) \
\
void* VG_REPLACE_FUNCTION(soname,fnname) ( void* ptrV, SizeT new_size );\
void* VG_REPLACE_FUNCTION(soname,fnname) ( void* ptrV, SizeT new_size ) \
void* VG_REPLACE_FUNCTION_ZU(soname,fnname) ( void* ptrV, SizeT new_size );\
void* VG_REPLACE_FUNCTION_ZU(soname,fnname) ( void* ptrV, SizeT new_size ) \
{ \
void* v; \
\
@@ -290,9 +291,9 @@ CALLOC(m_libc_dot_so_star, calloc);
if (ptrV == NULL) \
/* We need to call a malloc-like function; so let's use \
one which we know exists. */ \
return VG_REPLACE_FUNCTION(libcZdsoZa,malloc) (new_size); \
return VG_REPLACE_FUNCTION_ZU(libcZdsoZa,malloc) (new_size); \
if (new_size <= 0) { \
VG_REPLACE_FUNCTION(libcZdsoZa,free)(ptrV); \
VG_REPLACE_FUNCTION_ZU(libcZdsoZa,free)(ptrV); \
MALLOC_TRACE(" = 0"); \
return NULL; \
} \
@@ -307,8 +308,8 @@ REALLOC(m_libc_dot_so_star, realloc);
#define MEMALIGN(soname, fnname) \
\
void* VG_REPLACE_FUNCTION(soname,fnname) ( SizeT alignment, SizeT n ); \
void* VG_REPLACE_FUNCTION(soname,fnname) ( SizeT alignment, SizeT n ) \
void* VG_REPLACE_FUNCTION_ZU(soname,fnname) ( SizeT alignment, SizeT n ); \
void* VG_REPLACE_FUNCTION_ZU(soname,fnname) ( SizeT alignment, SizeT n ) \
{ \
void* v; \
\
@@ -333,10 +334,10 @@ MEMALIGN(m_libc_dot_so_star, memalign);
#define VALLOC(soname, fnname) \
\
void* VG_REPLACE_FUNCTION(soname,fnname) ( SizeT size ); \
void* VG_REPLACE_FUNCTION(soname,fnname) ( SizeT size ) \
void* VG_REPLACE_FUNCTION_ZU(soname,fnname) ( SizeT size ); \
void* VG_REPLACE_FUNCTION_ZU(soname,fnname) ( SizeT size ) \
{ \
return VG_REPLACE_FUNCTION(libcZdsoZa,memalign)(VKI_PAGE_SIZE, size); \
return VG_REPLACE_FUNCTION_ZU(libcZdsoZa,memalign)(VKI_PAGE_SIZE, size); \
}
VALLOC(m_libc_dot_so_star, valloc);
@@ -346,8 +347,8 @@ VALLOC(m_libc_dot_so_star, valloc);
#define MALLOPT(soname, fnname) \
\
int VG_REPLACE_FUNCTION(soname, fnname) ( int cmd, int value ); \
int VG_REPLACE_FUNCTION(soname, fnname) ( int cmd, int value ) \
int VG_REPLACE_FUNCTION_ZU(soname, fnname) ( int cmd, int value ); \
int VG_REPLACE_FUNCTION_ZU(soname, fnname) ( int cmd, int value ) \
{ \
/* In glibc-2.2.4, 1 denotes a successful return value for \
mallopt */ \
@@ -359,8 +360,10 @@ MALLOPT(m_libc_dot_so_star, mallopt);
#define POSIX_MEMALIGN(soname, fnname) \
\
int VG_REPLACE_FUNCTION(soname, fnname) ( void **memptr, SizeT alignment, SizeT size ); \
int VG_REPLACE_FUNCTION(soname, fnname) ( void **memptr, SizeT alignment, SizeT size ) \
int VG_REPLACE_FUNCTION_ZU(soname, fnname) ( void **memptr, \
SizeT alignment, SizeT size ); \
int VG_REPLACE_FUNCTION_ZU(soname, fnname) ( void **memptr, \
SizeT alignment, SizeT size ) \
{ \
void *mem; \
\
@@ -370,7 +373,7 @@ MALLOPT(m_libc_dot_so_star, mallopt);
|| (alignment & (alignment - 1)) != 0) \
return VKI_EINVAL; \
\
mem = VG_REPLACE_FUNCTION(libcZdsoZa,memalign)(alignment, size); \
mem = VG_REPLACE_FUNCTION_ZU(libcZdsoZa,memalign)(alignment, size); \
\
if (mem != NULL) { \
*memptr = mem; \
@@ -385,8 +388,8 @@ POSIX_MEMALIGN(m_libc_dot_so_star, posix_memalign);
#define MALLOC_USABLE_SIZE(soname, fnname) \
\
int VG_REPLACE_FUNCTION(soname, fnname) ( void* p ); \
int VG_REPLACE_FUNCTION(soname, fnname) ( void* p ) \
int VG_REPLACE_FUNCTION_ZU(soname, fnname) ( void* p ); \
int VG_REPLACE_FUNCTION_ZU(soname, fnname) ( void* p ) \
{ \
SizeT pszB; \
\
@@ -416,8 +419,8 @@ static void panic(const char *str)
#define PANIC(soname, fnname) \
\
void VG_REPLACE_FUNCTION(soname, fnname) ( void ); \
void VG_REPLACE_FUNCTION(soname, fnname) ( void ) \
void VG_REPLACE_FUNCTION_ZU(soname, fnname) ( void ); \
void VG_REPLACE_FUNCTION_ZU(soname, fnname) ( void ) \
{ \
panic(#fnname); \
}
@@ -433,8 +436,8 @@ PANIC(m_libc_dot_so_star, malloc_set_state);
// doesn't know that the call to mallinfo fills in mi.
#define MALLINFO(soname, fnname) \
\
struct vg_mallinfo VG_REPLACE_FUNCTION(soname, fnname) ( void ); \
struct vg_mallinfo VG_REPLACE_FUNCTION(soname, fnname) ( void ) \
struct vg_mallinfo VG_REPLACE_FUNCTION_ZU(soname, fnname) ( void ); \
struct vg_mallinfo VG_REPLACE_FUNCTION_ZU(soname, fnname) ( void ) \
{ \
static struct vg_mallinfo mi; \
MALLOC_TRACE("mallinfo()"); \
@@ -457,8 +460,8 @@ static void init(void)
init_done = 1;
VALGRIND_MAGIC_SEQUENCE(res, -1, VG_USERREQ__GET_MALLOCFUNCS, &info,
0, 0, 0);
VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__GET_MALLOCFUNCS, &info,
0, 0, 0);
}
/*--------------------------------------------------------------------*/