|
From: <sv...@va...> - 2009-02-17 04:01:08
|
Author: njn
Date: 2009-02-17 04:00:35 +0000 (Tue, 17 Feb 2009)
New Revision: 9190
Log:
Defined VG_MIN_MALLOC_SZB on a platform-by-platform basis.
Added malloc_usable_size replacements for DRD, Ptrcheck and Massif. tweaked
those for already present for Helgrind and Memcheck.
Fixed the relevant test for Memcheck, added one for Massif.
Added:
branches/DARWIN/massif/tests/malloc_usable.c
branches/DARWIN/massif/tests/malloc_usable.stderr.exp
branches/DARWIN/massif/tests/malloc_usable.vgtest
Modified:
branches/DARWIN/coregrind/pub_core_mallocfree.h
branches/DARWIN/drd/drd_malloc_wrappers.c
branches/DARWIN/exp-ptrcheck/h_main.c
branches/DARWIN/exp-ptrcheck/h_main.h
branches/DARWIN/exp-ptrcheck/pc_main.c
branches/DARWIN/helgrind/hg_main.c
branches/DARWIN/massif/ms_main.c
branches/DARWIN/massif/tests/Makefile.am
branches/DARWIN/massif/tests/toobig-allocs.vgtest
branches/DARWIN/memcheck/mc_malloc_wrappers.c
branches/DARWIN/memcheck/tests/malloc_usable.c
Modified: branches/DARWIN/coregrind/pub_core_mallocfree.h
===================================================================
--- branches/DARWIN/coregrind/pub_core_mallocfree.h 2009-02-17 00:50:45 UTC (rev 9189)
+++ branches/DARWIN/coregrind/pub_core_mallocfree.h 2009-02-17 04:00:35 UTC (rev 9190)
@@ -69,10 +69,20 @@
// This is both the minimum payload size of a malloc'd block, and its
// minimum alignment. Must be a power of 2 greater than 4, and should be
// greater than 8.
-#if defined(VGO_darwin)
+#if defined(VGP_x86_linux) || \
+ defined(VGP_ppc32_linux) || \
+ defined(VGP_ppc32_aix5)
+# define VG_MIN_MALLOC_SZB 8
+// Nb: We always use 16 bytes for Darwin, even on 32-bits, so it can be used
+// for any AltiVec- or SSE-related type.
+#elif defined(VGP_amd64_linux) || \
+ defined(VGP_ppc64_linux) || \
+ defined(VGP_ppc64_aix5) || \
+ defined(VGP_x86_darwin) || \
+ defined(VGP_amd64_darwin)
# define VG_MIN_MALLOC_SZB 16
#else
-# define VG_MIN_MALLOC_SZB 8
+# error Unknown platform
#endif
/* This struct definition MUST match the system one. */
Modified: branches/DARWIN/drd/drd_malloc_wrappers.c
===================================================================
--- branches/DARWIN/drd/drd_malloc_wrappers.c 2009-02-17 00:50:45 UTC (rev 9189)
+++ branches/DARWIN/drd/drd_malloc_wrappers.c 2009-02-17 04:00:35 UTC (rev 9190)
@@ -243,6 +243,15 @@
DRD_(handle_free)(tid, (Addr)p);
}
+static SizeT DRD_(malloc_usable_size) ( ThreadId tid, void* p )
+{
+ DRD_Chunk *mc = VG_(HT_lookup)( DRD_(s_malloc_list), (UWord)p );
+
+ // There may be slop, but pretend there isn't because only the asked-for
+ // area will have been shadowed properly.
+ return ( mc ? mc->size : 0 );
+}
+
void DRD_(register_malloc_wrappers)(const StartUsingMem start_callback,
const StopUsingMem stop_callback)
{
@@ -264,7 +273,7 @@
DRD_(__builtin_delete),
DRD_(__builtin_vec_delete),
DRD_(realloc),
- NULL, // DDD: malloc_usable_size
+ DRD_(malloc_usable_size),
0);
}
Modified: branches/DARWIN/exp-ptrcheck/h_main.c
===================================================================
--- branches/DARWIN/exp-ptrcheck/h_main.c 2009-02-17 00:50:45 UTC (rev 9189)
+++ branches/DARWIN/exp-ptrcheck/h_main.c 2009-02-17 04:00:35 UTC (rev 9190)
@@ -999,7 +999,16 @@
}
}
+SizeT h_replace_malloc_usable_size ( ThreadId tid, void* p )
+{
+ Seg* seg = find_Seg_by_addr( (Addr)p );
+ // There may be slop, but pretend there isn't because only the asked-for
+ // area will have been shadowed properly.
+ return ( seg ? seg->szB : 0 );
+}
+
+
/*------------------------------------------------------------*/
/*--- Memory events ---*/
/*------------------------------------------------------------*/
Modified: branches/DARWIN/exp-ptrcheck/h_main.h
===================================================================
--- branches/DARWIN/exp-ptrcheck/h_main.h 2009-02-17 00:50:45 UTC (rev 9189)
+++ branches/DARWIN/exp-ptrcheck/h_main.h 2009-02-17 04:00:35 UTC (rev 9190)
@@ -65,6 +65,7 @@
void h_replace___builtin_delete ( ThreadId tid, void* p );
void h_replace___builtin_vec_delete ( ThreadId tid, void* p );
void* h_replace_realloc ( ThreadId tid, void* p_old, SizeT new_size );
+SizeT h_replace_malloc_usable_size ( ThreadId tid, void* p );
void h_new_mem_startup( Addr a, SizeT len,
Bool rr, Bool ww, Bool xx, ULong di_handle );
Modified: branches/DARWIN/exp-ptrcheck/pc_main.c
===================================================================
--- branches/DARWIN/exp-ptrcheck/pc_main.c 2009-02-17 00:50:45 UTC (rev 9189)
+++ branches/DARWIN/exp-ptrcheck/pc_main.c 2009-02-17 04:00:35 UTC (rev 9190)
@@ -166,7 +166,7 @@
h_replace___builtin_delete,
h_replace___builtin_vec_delete,
h_replace_realloc,
- NULL, // DDD: malloc_usable_size
+ h_replace_malloc_usable_size,
0 /* no need for client heap redzones */ );
VG_(needs_var_info) ();
Modified: branches/DARWIN/helgrind/hg_main.c
===================================================================
--- branches/DARWIN/helgrind/hg_main.c 2009-02-17 00:50:45 UTC (rev 9189)
+++ branches/DARWIN/helgrind/hg_main.c 2009-02-17 04:00:35 UTC (rev 9190)
@@ -3468,16 +3468,11 @@
static SizeT hg_cli_malloc_usable_size ( ThreadId tid, void* p )
{
- MallocMeta *md;
+ MallocMeta *md = VG_(HT_lookup)( hg_mallocmeta_table, (UWord)p );
- /* First try and find the block. */
- md = (MallocMeta*) VG_(HT_lookup)( hg_mallocmeta_table, (UWord)p );
-
- if (md == NULL) {
- return 0;
- }
-
- return md->szB;
+ // There may be slop, but pretend there isn't because only the asked-for
+ // area will have been shadowed properly.
+ return ( md ? md->szB : 0 );
}
Modified: branches/DARWIN/massif/ms_main.c
===================================================================
--- branches/DARWIN/massif/ms_main.c 2009-02-17 00:50:45 UTC (rev 9189)
+++ branches/DARWIN/massif/ms_main.c 2009-02-17 04:00:35 UTC (rev 9190)
@@ -1561,10 +1561,8 @@
static __inline__
void die_block ( void* p, Bool custom_free )
{
- HP_Chunk* hc;
-
// Remove HP_Chunk from malloc_list
- hc = VG_(HT_remove)(malloc_list, (UWord)p);
+ HP_Chunk* hc = VG_(HT_remove)(malloc_list, (UWord)p);
if (NULL == hc) {
return; // must have been a bogus free()
}
@@ -1768,7 +1766,13 @@
return renew_block(tid, p_old, new_szB);
}
+static SizeT ms_malloc_usable_size ( ThreadId tid, void* p )
+{
+ HP_Chunk* hc = VG_(HT_lookup)( malloc_list, (UWord)p );
+ return ( hc ? hc->req_szB + hc->slop_szB : 0 );
+}
+
//------------------------------------------------------------//
//--- Stacks ---//
//------------------------------------------------------------//
@@ -2339,7 +2343,7 @@
ms___builtin_delete,
ms___builtin_vec_delete,
ms_realloc,
- NULL,
+ ms_malloc_usable_size,
0 );
// HP_Chunks.
Modified: branches/DARWIN/massif/tests/Makefile.am
===================================================================
--- branches/DARWIN/massif/tests/Makefile.am 2009-02-17 00:50:45 UTC (rev 9189)
+++ branches/DARWIN/massif/tests/Makefile.am 2009-02-17 04:00:35 UTC (rev 9190)
@@ -25,6 +25,7 @@
insig.post.exp insig.stderr.exp insig.vgtest \
long-names.post.exp long-names.stderr.exp long-names.vgtest \
long-time.post.exp long-time.stderr.exp long-time.vgtest \
+ malloc_usable.stderr.exp malloc_usable.vgtest \
new-cpp.post.exp new-cpp.stderr.exp new-cpp.vgtest \
no-stack-no-heap.post.exp no-stack-no-heap.stderr.exp no-stack-no-heap.vgtest \
null.post.exp null.stderr.exp null.vgtest \
@@ -62,6 +63,7 @@
insig \
long-names \
long-time \
+ malloc_usable \
new-cpp \
null \
one \
Copied: branches/DARWIN/massif/tests/malloc_usable.c (from rev 9187, branches/DARWIN/memcheck/tests/malloc_usable.c)
===================================================================
--- branches/DARWIN/massif/tests/malloc_usable.c (rev 0)
+++ branches/DARWIN/massif/tests/malloc_usable.c 2009-02-17 04:00:35 UTC (rev 9190)
@@ -0,0 +1,25 @@
+#include <assert.h>
+#if defined(__APPLE__)
+#include <malloc/malloc.h>
+#else
+#include <malloc.h>
+#endif
+#include <stdlib.h>
+#include <stdio.h>
+
+int main(void)
+{
+ // Because our allocations are in multiples of 8 or 16, 99 will round up
+ // to 104 or 112.
+ int* x = malloc(99);
+
+ // DDD: would be better to have a HAVE_MALLOC_USABLE_SIZE variable here
+# if !defined(_AIX)
+ assert(104 == malloc_usable_size(x) ||
+ 112 == malloc_usable_size(x));
+ assert( 0 == malloc_usable_size(NULL));
+ assert( 0 == malloc_usable_size((void*)0xdeadbeef));
+# endif
+
+ return 0;
+}
Property changes on: branches/DARWIN/massif/tests/malloc_usable.c
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: branches/DARWIN/massif/tests/malloc_usable.stderr.exp (from rev 9187, branches/DARWIN/memcheck/tests/malloc_usable.stderr.exp)
===================================================================
--- branches/DARWIN/massif/tests/malloc_usable.stderr.exp (rev 0)
+++ branches/DARWIN/massif/tests/malloc_usable.stderr.exp 2009-02-17 04:00:35 UTC (rev 9190)
@@ -0,0 +1,2 @@
+
+
Property changes on: branches/DARWIN/massif/tests/malloc_usable.stderr.exp
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: branches/DARWIN/massif/tests/malloc_usable.vgtest (from rev 9187, branches/DARWIN/memcheck/tests/malloc_usable.vgtest)
===================================================================
--- branches/DARWIN/massif/tests/malloc_usable.vgtest (rev 0)
+++ branches/DARWIN/massif/tests/malloc_usable.vgtest 2009-02-17 04:00:35 UTC (rev 9190)
@@ -0,0 +1,3 @@
+prog: malloc_usable
+vgopts: --massif-out-file=massif.out
+cleanup: rm massif.out
Property changes on: branches/DARWIN/massif/tests/malloc_usable.vgtest
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: branches/DARWIN/massif/tests/toobig-allocs.vgtest
===================================================================
--- branches/DARWIN/massif/tests/toobig-allocs.vgtest 2009-02-17 00:50:45 UTC (rev 9189)
+++ branches/DARWIN/massif/tests/toobig-allocs.vgtest 2009-02-17 04:00:35 UTC (rev 9190)
@@ -1,4 +1,3 @@
prog: ../../tests/toobig-allocs
vgopts: --massif-out-file=massif.out
-vgopts: --ignore-fn=__part_load_locale --ignore-fn=__time_load_locale --ignore-fn=dwarf2_unwind_dyld_add_image_hook --ignore-fn=get_or_create_key_element
cleanup: rm massif.out
Modified: branches/DARWIN/memcheck/mc_malloc_wrappers.c
===================================================================
--- branches/DARWIN/memcheck/mc_malloc_wrappers.c 2009-02-17 00:50:45 UTC (rev 9189)
+++ branches/DARWIN/memcheck/mc_malloc_wrappers.c 2009-02-17 04:00:35 UTC (rev 9190)
@@ -488,15 +488,11 @@
// memory as they asked for, with no additional alignment padding.
SizeT MC_(malloc_usable_size) ( ThreadId tid, void* p )
{
- if (p) {
- MC_Chunk* mc = VG_(HT_lookup) ( MC_(malloc_list), (UWord)p );
- if (mc) {
- return mc->szB;
- }
- }
+ MC_Chunk* mc = VG_(HT_lookup) ( MC_(malloc_list), (UWord)p );
- // bad pointer or no pointer - Linux and Darwin both return 0 with no error.
- return 0;
+ // There may be slop, but pretend there isn't because only the asked-for
+ // area will be marked as addressable.
+ return ( mc ? mc->szB : 0 );
}
Modified: branches/DARWIN/memcheck/tests/malloc_usable.c
===================================================================
--- branches/DARWIN/memcheck/tests/malloc_usable.c 2009-02-17 00:50:45 UTC (rev 9189)
+++ branches/DARWIN/memcheck/tests/malloc_usable.c 2009-02-17 04:00:35 UTC (rev 9190)
@@ -9,10 +9,16 @@
int main(void)
{
- // Since our allocations are in multiples of 8, 99 will round up to 104.
+ // Because Memcheck marks any slop as inaccessible, it doesn't round up
+ // sizes for malloc_usable_size().
int* x = malloc(99);
-# if !defined(_AIX) && !defined(__APPLE__)
- assert(104 == malloc_usable_size(x));
+
+ // DDD: would be better to have a HAVE_MALLOC_USABLE_SIZE variable here
+# if !defined(_AIX)
+ assert(99 == malloc_usable_size(x));
+ assert( 0 == malloc_usable_size(NULL));
+ assert( 0 == malloc_usable_size((void*)0xdeadbeef));
# endif
+
return 0;
}
|