In the core, include malloc_usable_size() as one of the functions that must
be replaced if malloc() et al are replaced by a tool.  This is because
different tools implement the function in different ways.

Add an appropriate malloc_usable_size() replacement to each of Memcheck,
Helgrind, DRD, Ptrcheck, Massif.

Update memcheck/tests/malloc_usable and add massif/tests/malloc_usable.

Merged from the DARWIN branch.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@9193 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/drd/drd_malloc_wrappers.c b/drd/drd_malloc_wrappers.c
index 556ff5f..086f82f 100644
--- a/drd/drd_malloc_wrappers.c
+++ b/drd/drd_malloc_wrappers.c
@@ -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,6 +273,7 @@
                                 DRD_(__builtin_delete),
                                 DRD_(__builtin_vec_delete),
                                 DRD_(realloc),
+                                DRD_(malloc_usable_size),
                                 0);
 }