mirror of
git://sourceware.org/git/valgrind.git
synced 2026-01-19 00:08:14 +08:00
This implements the interception of all globally public allocation functions by default. It works by adding a flag to the spec to say the interception only applies to global functions. Which is set for the somalloc spec. The librarypath to match is set to "*" unless the user overrides it. Then each DiSym keeps track of whether the symbol is local or global. For a spec which has isGlobal set only isGlobal symbols will match. Note that because of padding to keep the addresses in DiSym aligned the addition of the extra bool isGlobal doesn't actually grow the struct. The comments explain how the struct could be made more compact on 32bit systems, but this isn't as easy on 64bit systems. So I didn't try to do that in this patch. For ELF symbols keeping track of which are global is trivial. For pdb I had to guess and made only the "Public" symbols global. I don't know how/if macho keeps track of global symbols or not. For now I just mark all of them local (which just means things work as previously on platforms that use machos, no non-system symbols are matches by default for somalloc unless the user explicitly tells which library name to match). Included are two testcases for shared libraries (wrapmalloc) and staticly linked (wrapmallocstatic) malloc/free overrides that depend on the new default. One existing testcase (new_override) was adjusted to explicitly not use the new somalloc default because it depends on a user defined new implementation that has side-effects and should explicitly not be intercepted. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15726
30 lines
533 B
C
30 lines
533 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
/* Test that a program that has malloc/free interposed in the
|
|
executable is also intercepted. */
|
|
|
|
int main ( void )
|
|
{
|
|
printf ("start\n");
|
|
void *p = malloc (1024);
|
|
free (p);
|
|
printf ("done\n");
|
|
return 0;
|
|
}
|
|
|
|
/* Fake malloc/free functions that just print something. When run
|
|
under memcheck these functions will be intercepted and not print
|
|
anything. */
|
|
|
|
void *malloc ( size_t size )
|
|
{
|
|
printf ("malloc\n");
|
|
return NULL;
|
|
}
|
|
|
|
void free (void *ptr)
|
|
{
|
|
printf ("free\n");
|
|
}
|