]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Implemented malloc_usable_size(), which was used in a program written by
authorNicholas Nethercote <njn@valgrind.org>
Tue, 22 Apr 2003 22:45:55 +0000 (22:45 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Tue, 22 Apr 2003 22:45:55 +0000 (22:45 +0000)
Frederic Delley <fdelley@cisco.com>.

This required also adding VG_(arena_payload_szB)().

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1540

coregrind/vg_include.h
coregrind/vg_malloc2.c
coregrind/vg_replace_malloc.c

index 4d3d33ec829f8fa3a48c4267078d52878a2d761b..34dfb8074953d753daa4f5e3136cb0fdcb24dabb 100644 (file)
@@ -427,6 +427,8 @@ extern void* VG_(arena_realloc) ( ArenaId arena, void* ptr, Int alignment,
 extern void* VG_(arena_malloc_aligned) ( ArenaId aid, Int req_alignB, 
                                                 Int req_pszB );
 
+extern Int   VG_(arena_payload_szB) ( ArenaId aid, void* payload );
+
 extern void  VG_(mallocSanityCheckAll)   ( void );
 
 extern void  VG_(show_all_arena_stats) ( void );
index 9377da07066c15cec67eb7db7650727b783525a5..bf9c8d0617e8679cabf5f5c6c5186694dcf66597 100644 (file)
@@ -325,7 +325,7 @@ Word* first_to_payload ( Arena* a, WordF* fw )
    return & fw[3 + a->rz_szW];
 }
 
-/* Given the addr of the first word of the payload of a block,
+/* Given the addr of the first word of the payload of a block,
    return the addr of the first word of the block. */
 static __inline__
 Word* payload_to_first ( Arena* a, WordF* payload )
@@ -430,7 +430,7 @@ Int overhead_szW ( Arena* a )
 }
 
 
-/* Convert pointer size in words to block size in words, and back. */
+/* Convert payload size in words to block size in words, and back. */
 static __inline__
 Int pszW_to_bszW ( Arena* a, Int pszW )
 {
@@ -445,6 +445,15 @@ Int bszW_to_pszW ( Arena* a, Int bszW )
    return pszW;
 }
 
+Int VG_(arena_payload_szB) ( ArenaId aid, void* ptr )
+{
+   Arena* a = arenaId_to_ArenaP(aid);
+   Word* fw = payload_to_first(a, (WordF*)ptr);
+   Int pszW = bszW_to_pszW(a, get_bszW_lo(fw));
+   return VKI_BYTES_PER_WORD * pszW;
+}
+
+
 /*------------------------------------------------------------*/
 /*--- Functions for working with freelists.                ---*/
 /*------------------------------------------------------------*/
index 42e2e1184b287b832364f45b6d0478d2861ebaec..2299fad68e3b0617ffe147546874881bb3778301 100644 (file)
@@ -362,6 +362,26 @@ int __posix_memalign ( void **memptr, UInt alignment, UInt size )
     return VKI_ENOMEM /*12*/ /*ENOMEM*/;
 }
 
+Int malloc_usable_size ( void* p )
+{ 
+   Int pszB;
+   
+   MALLOC_TRACE("malloc_usable_size[simd=%d](%p)", 
+                (UInt)VG_(is_running_on_simd_CPU)(), p );
+   if (NULL == p)
+      return 0;
+
+   if (VG_(is_running_on_simd_CPU)()) {
+      pszB = (Int)VALGRIND_NON_SIMD_CALL2( VG_(arena_payload_szB), 
+                                           VG_AR_CLIENT, p );
+   } else {
+      pszB = VG_(arena_payload_szB)(VG_AR_CLIENT, p);
+   }
+   MALLOC_TRACE(" = %d\n", pszB );
+
+   return pszB;
+}
+
 
 /* Bomb out if we get any of these. */
 /* HACK: We shouldn't call VG_(core_panic) or VG_(message) on the simulated
@@ -372,8 +392,7 @@ void pvalloc ( void )
 { VG_(core_panic)("call to pvalloc\n"); }
 void malloc_stats ( void )
 { VG_(core_panic)("call to malloc_stats\n"); }
-void malloc_usable_size ( void )
-{ VG_(core_panic)("call to malloc_usable_size\n"); }
+
 void malloc_trim ( void )
 { VG_(core_panic)("call to malloc_trim\n"); }
 void malloc_get_state ( void )