mirror of
https://github.com/Zenithsiz/ftmemsim-valgrind.git
synced 2026-02-04 02:18:37 +00:00
Implemented malloc_usable_size(), which was used in a program written by
Frederic Delley <fdelley@cisco.com>. This required also adding VG_(arena_payload_szB)(). git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1540
This commit is contained in:
parent
a00a117591
commit
e7b23faa99
@ -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 );
|
||||
|
||||
@ -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. ---*/
|
||||
/*------------------------------------------------------------*/
|
||||
|
||||
@ -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 )
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user