mirror of
https://github.com/Zenithsiz/ftmemsim-valgrind.git
synced 2026-02-04 02:18:37 +00:00
The replacement functions are running on the simulated CPU. The code on the simulated CPU does not necessarily use all arguments. E.g. args can be ignored and/or only given to a NON SIMD call. The definedness of such 'unused' arguments will not be verified by memcheck. A call to 'trigger_memcheck_error_if_undefined' allows memcheck to detect such errors for the otherwise unused args. Apart of allowing memcheck to detect an error, the function trigger_memcheck_error_if_undefined has no effect and has a minimal cost for other tools replacing malloc functions. (suggestion of the 'no operation check' from Julian). tested on f12/x86, debian6/amd64, f18/ppc64 Note that some Darwin specific code has been modified in coregrind/m_replace_malloc/vg_replace_malloc.c. (Some of) this code has not been compiled (no access to a Darwin system). The code changed is trivial, so there is some chance it will compile and even maybe work. Added a new test verifying that various malloc related functions undefined args are triggering an error in memcheck. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13361
58 lines
1.1 KiB
C
58 lines
1.1 KiB
C
#include <stdlib.h>
|
|
#include <malloc.h>
|
|
#include "../memcheck.h"
|
|
int main (int argc, char*argv[])
|
|
{
|
|
size_t def_size = 1<<20;
|
|
char *p;
|
|
char *new_p;
|
|
|
|
if (argc > 10000) def_size = def_size * 2;
|
|
|
|
{
|
|
size_t size = def_size;
|
|
VALGRIND_MAKE_MEM_UNDEFINED(&size, 1);
|
|
p = malloc(size);
|
|
}
|
|
|
|
VALGRIND_MAKE_MEM_UNDEFINED(&p, 1);
|
|
new_p = realloc(p, def_size);
|
|
|
|
VALGRIND_MAKE_MEM_UNDEFINED(&new_p, 1);
|
|
new_p = realloc(new_p, def_size);
|
|
|
|
VALGRIND_MAKE_MEM_UNDEFINED(&new_p, 1);
|
|
free (new_p);
|
|
|
|
{
|
|
size_t nmemb = 1;
|
|
VALGRIND_MAKE_MEM_UNDEFINED(&nmemb, 1);
|
|
new_p = calloc(nmemb, def_size);
|
|
free (new_p);
|
|
}
|
|
|
|
{
|
|
size_t alignment = 1;
|
|
VALGRIND_MAKE_MEM_UNDEFINED(&alignment, 1);
|
|
new_p = memalign(alignment, def_size);
|
|
free(new_p);
|
|
}
|
|
|
|
{
|
|
size_t nmemb = 16;
|
|
size_t size = def_size;
|
|
VALGRIND_MAKE_MEM_UNDEFINED(&size, 1);
|
|
new_p = memalign(nmemb, size);
|
|
free(new_p);
|
|
}
|
|
|
|
{
|
|
size_t size = def_size;
|
|
VALGRIND_MAKE_MEM_UNDEFINED(&size, 1);
|
|
new_p = valloc(size);
|
|
free (new_p);
|
|
}
|
|
|
|
return 0;
|
|
}
|