From: Nicholas Nethercote Date: Tue, 22 Apr 2003 22:45:55 +0000 (+0000) Subject: Implemented malloc_usable_size(), which was used in a program written by X-Git-Tag: svn/VALGRIND_2_0_0~219 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e7b23faa99d83e271de6ef908731d145b63da82f;p=thirdparty%2Fvalgrind.git Implemented malloc_usable_size(), which was used in a program written by Frederic Delley . This required also adding VG_(arena_payload_szB)(). git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1540 --- diff --git a/coregrind/vg_include.h b/coregrind/vg_include.h index 4d3d33ec82..34dfb80749 100644 --- a/coregrind/vg_include.h +++ b/coregrind/vg_include.h @@ -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 ); diff --git a/coregrind/vg_malloc2.c b/coregrind/vg_malloc2.c index 9377da0706..bf9c8d0617 100644 --- a/coregrind/vg_malloc2.c +++ b/coregrind/vg_malloc2.c @@ -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 a 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. ---*/ /*------------------------------------------------------------*/ diff --git a/coregrind/vg_replace_malloc.c b/coregrind/vg_replace_malloc.c index 42e2e1184b..2299fad68e 100644 --- a/coregrind/vg_replace_malloc.c +++ b/coregrind/vg_replace_malloc.c @@ -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 )