|
From: Jeremy F. <je...@go...> - 2005-02-28 01:13:07
|
CVS commit by fitzhardinge:
Insert MALLOCLIKE/FREELIKE instrumentation into VG_(arena_*) functions.
I'm not convinced this is correct yet, but it works enough.
This change includes some fixes for problems found while running V
under memcheck.
M +11 -4 stage1.c 1.33
M +11 -3 vg_main.c 1.254
M +17 -8 vg_malloc2.c 1.35
M +1 -0 vg_signals.c 1.134
M +4 -4 vg_symtab2.c 1.104
--- valgrind/coregrind/vg_malloc2.c #1.34:1.35
@@ -32,4 +32,5 @@
#include "core.h"
+#include "memcheck/memcheck.h"
//#define DEBUG_MALLOC // turn on heavyweight debugging machinery
@@ -479,4 +480,5 @@ Superblock* newSuperblock ( Arena* a, Si
}
vg_assert(NULL != sb);
+ VALGRIND_DISCARD(VALGRIND_MAKE_WRITABLE(sb, cszB));
vg_assert(0 == (Addr)sb % VG_MIN_MALLOC_SZB);
sb->n_payload_bytes = cszB - sizeof(Superblock);
@@ -867,4 +869,5 @@ void mkFreeBlock ( Arena* a, Block* b, S
SizeT pszB = bszB_to_pszB(a, bszB);
vg_assert(b_lno == pszB_to_listNo(pszB));
+ VALGRIND_DISCARD(VALGRIND_MAKE_WRITABLE(b, bszB));
// Set the size fields and indicate not-in-use.
set_bszB_lo(b, mk_free_bszB(bszB));
@@ -896,4 +899,5 @@ void mkInuseBlock ( Arena* a, Block* b,
UInt i;
vg_assert(bszB >= min_useful_bszB(a));
+ VALGRIND_MAKE_WRITABLE(b, bszB);
set_bszB_lo(b, mk_inuse_bszB(bszB));
set_bszB_hi(b, mk_inuse_bszB(bszB));
@@ -1030,4 +1034,6 @@ void* VG_(arena_malloc) ( ArenaId aid, S
v = get_block_payload(a, b);
vg_assert( (((Addr)v) & (VG_MIN_MALLOC_SZB-1)) == 0 );
+
+ VALGRIND_MALLOCLIKE_BLOCK(v, req_pszB, 0, False);
return v;
}
@@ -1125,4 +1131,6 @@ void VG_(arena_free) ( ArenaId aid, void
# endif
+ VALGRIND_FREELIKE_BLOCK(ptr, 0);
+
VGP_POPCC(VgpMalloc);
}
@@ -1251,4 +1259,7 @@ void* VG_(arena_malloc_aligned) ( ArenaI
vg_assert( (((Addr)align_p) % req_alignB) == 0 );
+
+ VALGRIND_MALLOCLIKE_BLOCK(align_p, req_pszB, 0, False);
+
return align_p;
}
@@ -1269,5 +1280,4 @@ SizeT VG_(arena_payload_szB) ( ArenaId a
void* VG_(arena_calloc) ( ArenaId aid, SizeT alignB, SizeT nmemb, SizeT nbytes )
{
- UInt i;
SizeT size;
UChar* p;
@@ -1283,5 +1293,7 @@ void* VG_(arena_calloc) ( ArenaId aid, S
p = VG_(arena_malloc_aligned) ( aid, alignB, size );
- for (i = 0; i < size; i++) p[i] = 0;
+ VG_(memset)(p, 0, nbytes);
+
+ VALGRIND_MALLOCLIKE_BLOCK(p, nbytes, 0, True);
VGP_POPCC(VgpMalloc);
@@ -1296,6 +1308,5 @@ void* VG_(arena_realloc) ( ArenaId aid,
Arena* a;
SizeT old_bszB, old_pszB;
- UInt i;
- UChar *p_old, *p_new;
+ UChar *p_new;
Block* b;
@@ -1326,9 +1337,7 @@ void* VG_(arena_realloc) ( ArenaId aid,
}
- p_old = (UChar*)ptr;
- for (i = 0; i < old_pszB; i++)
- p_new[i] = p_old[i];
+ VG_(memcpy)(p_new, ptr, old_pszB);
- VG_(arena_free)(aid, p_old);
+ VG_(arena_free)(aid, ptr);
VGP_POPCC(VgpMalloc);
--- valgrind/coregrind/vg_main.c #1.253:1.254
@@ -46,4 +46,6 @@
#include <unistd.h>
+#include "memcheck/memcheck.h"
+
#ifndef AT_DCACHEBSIZE
#define AT_DCACHEBSIZE 19
@@ -1178,5 +1180,5 @@ static void load_tool( const char *tooln
{
Bool ok;
- int len = strlen(VG_(libdir)) + strlen(toolname)*2 + 16;
+ int len = strlen(VG_(libdir)) + strlen(toolname) + 16;
char buf[len];
void* handle;
@@ -2184,8 +2186,12 @@ static void build_segment_map_callback (
vg_assert(0 != r_esp);
if (is_stack_segment) {
- if (0)
- VG_(message)(Vg_DebugMsg, "invalidating stack area: %x .. %x",
+ if (0) {
+ VG_(message)(Vg_DebugMsg, "invalidating stack area: %p .. %p",
start,r_esp);
+ VG_(message)(Vg_DebugMsg, " validating stack area: %p .. %p",
+ r_esp, start+size);
+ }
VG_TRACK( die_mem_stack, start, r_esp-start );
+ VG_TRACK( post_mem_write, r_esp, (start+size)-r_esp );
}
}
@@ -2466,4 +2473,5 @@ int main(int argc, char **argv, char **e
sp_at_startup = setup_client_stack(init_sp, cl_argv, env, &info,
&client_auxv);
+ free(env);
}
--- valgrind/coregrind/stage1.c #1.32:1.33
@@ -44,4 +44,5 @@
#include "core.h"
#include "ume.h"
+#include "memcheck/memcheck.h"
static int stack[SIGSTKSZ*4];
@@ -304,8 +305,5 @@ int main(int argc, char** argv)
{
struct rlimit rlim;
- const char *cp = getenv(VALGRINDLIB);
-
- if (cp != NULL)
- valgrind_lib = cp;
+ const char *cp;
// Initial stack pointer is to argc, which is immediately before argv[0]
@@ -313,4 +311,13 @@ int main(int argc, char** argv)
init_sp = argv - 1;
+ /* The Linux libc startup sequence leaves this in an apparently
+ undefined state, but it really is defined, so mark it so. */
+ VALGRIND_MAKE_READABLE(init_sp, sizeof(int));
+
+ cp = getenv(VALGRINDLIB);
+
+ if (cp != NULL)
+ valgrind_lib = cp;
+
/* Set the address space limit as high as it will go, since we make
a lot of very large mappings. */
--- valgrind/coregrind/vg_symtab2.c #1.103:1.104
@@ -1106,5 +1106,5 @@ static
Addr find_debug_file( Char* objpath, Char* debugname, UInt crc, UInt* size )
{
- Char *objdir = VG_(strdup)(objpath);
+ Char *objdir = VG_(arena_strdup)(VG_AR_SYMTAB, objpath);
Char *objdirptr;
Char *debugpath;
@@ -1114,5 +1114,5 @@ Addr find_debug_file( Char* objpath, Cha
*objdirptr = '\0';
- debugpath = VG_(malloc)(VG_(strlen)(objdir) + VG_(strlen)(debugname) + 16);
+ debugpath = VG_(arena_malloc)(VG_AR_SYMTAB, VG_(strlen)(objdir) + VG_(strlen)(debugname) + 16);
VG_(sprintf)(debugpath, "%s/%s", objdir, debugname);
@@ -1126,6 +1126,6 @@ Addr find_debug_file( Char* objpath, Cha
}
- VG_(free)(debugpath);
- VG_(free)(objdir);
+ VG_(arena_free)(VG_AR_SYMTAB, debugpath);
+ VG_(arena_free)(VG_AR_SYMTAB, objdir);
return addr;
--- valgrind/coregrind/vg_signals.c #1.133:1.134
@@ -2080,4 +2080,5 @@ void VG_(sigstartup_actions) ( void )
tsa.ksa_handler = (void *)vg_sync_signalhandler;
tsa.sa_flags = VKI_SA_SIGINFO;
+ tsa.sa_restorer = 0;
VG_(sigfillset)(&tsa.sa_mask);
|