diff --git a/coregrind/m_mallocfree.c b/coregrind/m_mallocfree.c index 1aa4ef3ea..e21ed6290 100644 --- a/coregrind/m_mallocfree.c +++ b/coregrind/m_mallocfree.c @@ -1197,7 +1197,7 @@ void* VG_(arena_memalign) ( ArenaId aid, SizeT req_alignB, SizeT req_pszB ) } -SizeT VG_(arena_payload_szB) ( ArenaId aid, void* ptr ) +SizeT VG_(arena_payload_szB) ( ThreadId tid, ArenaId aid, void* ptr ) { Arena* a = arenaId_to_ArenaP(aid); Block* b = get_payload_block(a, ptr); diff --git a/coregrind/pub_core_mallocfree.h b/coregrind/pub_core_mallocfree.h index b5b7ec22b..94dcbc69c 100644 --- a/coregrind/pub_core_mallocfree.h +++ b/coregrind/pub_core_mallocfree.h @@ -81,7 +81,7 @@ extern Char* VG_(arena_strdup) ( ArenaId aid, const Char* s); must be called before any of VG_(malloc) and friends are called. */ extern void VG_(set_client_malloc_redzone_szB) ( SizeT rz_szB ); -extern SizeT VG_(arena_payload_szB) ( ArenaId aid, void* payload ); +extern SizeT VG_(arena_payload_szB) ( ThreadId tid, ArenaId aid, void* p ); extern void VG_(sanity_check_malloc_all) ( void ); diff --git a/coregrind/pub_core_replacemalloc.h b/coregrind/pub_core_replacemalloc.h index 3484a6e02..e50de51d7 100644 --- a/coregrind/pub_core_replacemalloc.h +++ b/coregrind/pub_core_replacemalloc.h @@ -50,7 +50,7 @@ struct vg_mallocfunc_info { void (*tl___builtin_vec_delete)(ThreadId tid, void* p); void* (*tl_realloc) (ThreadId tid, void* p, SizeT size); - SizeT (*arena_payload_szB) (ArenaId aid, void* payload); + SizeT (*arena_payload_szB) (ThreadId tid, ArenaId aid, void* payload); Bool clo_trace_malloc; }; diff --git a/memcheck/tests/Makefile.am b/memcheck/tests/Makefile.am index 251eb6ead..5e59567eb 100644 --- a/memcheck/tests/Makefile.am +++ b/memcheck/tests/Makefile.am @@ -39,6 +39,7 @@ EXTRA_DIST = $(noinst_SCRIPTS) \ leak-tree.stderr.exp2 leak-tree.stderr.exp64 \ leak-regroot.vgtest leak-regroot.stderr.exp \ leakotron.vgtest leakotron.stdout.exp leakotron.stderr.exp \ + malloc_usable.stderr.exp malloc_usable.vgtest \ malloc1.stderr.exp malloc1.vgtest \ malloc2.stderr.exp malloc2.vgtest \ malloc3.stderr.exp malloc3.stdout.exp malloc3.vgtest \ @@ -99,7 +100,7 @@ check_PROGRAMS = \ doublefree error_counts errs1 exitprog execve execve2 erringfds \ fprw fwrite hello inits inline \ leak-0 leak-cycle leak-tree leak-regroot leakotron \ - malloc1 malloc2 malloc3 manuel1 manuel2 manuel3 \ + malloc_usable malloc1 malloc2 malloc3 manuel1 manuel2 manuel3 \ match-overrun \ memalign_test memalign2 memcmptest mempool mmaptest \ nanoleak new_nothrow \ diff --git a/memcheck/tests/malloc_usable.c b/memcheck/tests/malloc_usable.c new file mode 100644 index 000000000..670bc98c0 --- /dev/null +++ b/memcheck/tests/malloc_usable.c @@ -0,0 +1,12 @@ +#include +#include +#include +#include + +int main(void) +{ + // Since our allocations are in multiples of 8, 99 will round up to 104. + int* x = malloc(99); + assert(104 == malloc_usable_size(x)); + return 0; +} diff --git a/memcheck/tests/malloc_usable.stderr.exp b/memcheck/tests/malloc_usable.stderr.exp new file mode 100644 index 000000000..e69de29bb diff --git a/memcheck/tests/malloc_usable.vgtest b/memcheck/tests/malloc_usable.vgtest new file mode 100644 index 000000000..407d87261 --- /dev/null +++ b/memcheck/tests/malloc_usable.vgtest @@ -0,0 +1,2 @@ +prog: malloc_usable +vgopts: -q