From: Paul Floyd Date: Tue, 19 Aug 2025 14:37:50 +0000 (+0200) Subject: Bug 507721 - Wire up illumos and Solaris mallinfo X-Git-Tag: VALGRIND_3_26_0~231 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=27873587a6e67e37b5692924036d9889b0f044de;p=thirdparty%2Fvalgrind.git Bug 507721 - Wire up illumos and Solaris mallinfo --- diff --git a/NEWS b/NEWS index d5aaee976..e2c49a0ff 100644 --- a/NEWS +++ b/NEWS @@ -70,6 +70,7 @@ are not entered into bugzilla tend to get forgotten about or ignored. 506967 Implement and override mallinfo2 506970 mmap needs an EBADF fd_allowed check 507173 s390x: Crash when constant folding is disabled +507721 Wire up illumos and Solaris mallinfo 507853 faccessat and faccessat2 should handle AT_FDCWD and absolute paths 507868 futimesat doesn't handle AT_FDCWD 507873 Make fchmodat and fchmodat2 syscall wrappers accept AT_FDCWD diff --git a/configure.ac b/configure.ac index 0d5633fc0..ee623b050 100755 --- a/configure.ac +++ b/configure.ac @@ -4943,6 +4943,12 @@ AC_CHECK_LIB([pthread], [pthread_create]) AC_CHECK_LIB([rt], [clock_gettime]) AC_CHECK_LIB([rt], [timer_delete]) +if test "$VGCONF_OS" = "solaris" ; then +# for mallinfo +saved_LDFLAGS="$LDFLAGS" +LDFLAGS="$saved_LDFLAGS -lmalloc" +fi + AC_CHECK_FUNCS([ \ aligned_alloc \ clock_gettime\ @@ -5013,6 +5019,10 @@ AC_CHECK_FUNCS([ \ exterrctl ]) +if test "$VGCONF_OS" = "solaris" ; then +LDFLAGS="$saved_LDFLAGS" +fi + # AC_CHECK_LIB adds any library found to the variable LIBS, and links these # libraries with any shared object and/or executable. This is NOT what we # want for e.g. vgpreload_core-x86-linux.so diff --git a/coregrind/m_mallocfree.c b/coregrind/m_mallocfree.c index e7c80af71..a84bbeb3a 100644 --- a/coregrind/m_mallocfree.c +++ b/coregrind/m_mallocfree.c @@ -2433,6 +2433,7 @@ void VG_(mallinfo) ( ThreadId tid, struct vg_mallinfo* mi ) mi->keepcost = 0; // may want some value in here } +#if defined(VGO_linux) // The aforementioned older function, mallinfo(), is deprecated since the type // used for the fields is too small. void VG_(mallinfo2) ( ThreadId tid, struct vg_mallinfo2* mi ) @@ -2467,6 +2468,7 @@ void VG_(mallinfo2) ( ThreadId tid, struct vg_mallinfo2* mi ) mi->fordblks = free_blocks_size + VG_(free_queue_volume); mi->keepcost = 0; // may want some value in here } +#endif SizeT VG_(arena_redzone_size) ( ArenaId aid ) { diff --git a/coregrind/m_replacemalloc/vg_replace_malloc.c b/coregrind/m_replacemalloc/vg_replace_malloc.c index 808096152..02134d672 100644 --- a/coregrind/m_replacemalloc/vg_replace_malloc.c +++ b/coregrind/m_replacemalloc/vg_replace_malloc.c @@ -2518,8 +2518,9 @@ static void panic(const char *str) MALLINFO(VG_Z_LIBC_SONAME, mallinfo); MALLINFO(SO_SYN_MALLOC, mallinfo); -#elif defined(VGO_darwin) - //MALLINFO(VG_Z_LIBC_SONAME, mallinfo); +#elif defined(VGO_solaris) + MALLINFO(VG_Z_LIBC_SONAME, mallinfo); + MALLINFO(SO_SYN_MALLOC, mallinfo); #endif @@ -2545,9 +2546,6 @@ static void panic(const char *str) MALLINFO2(VG_Z_LIBC_SONAME, mallinfo2); MALLINFO2(SO_SYN_MALLOC, mallinfo2); -#elif defined(VGO_darwin) - //MALLINFO2(VG_Z_LIBC_SONAME, mallinfo2); - #endif diff --git a/coregrind/m_scheduler/scheduler.c b/coregrind/m_scheduler/scheduler.c index 1e77944cd..4862f2506 100644 --- a/coregrind/m_scheduler/scheduler.c +++ b/coregrind/m_scheduler/scheduler.c @@ -2145,9 +2145,12 @@ void do_client_request ( ThreadId tid ) info->tl___builtin_vec_delete = VG_(tdict).tool___builtin_vec_delete; info->tl___builtin_vec_delete_aligned = VG_(tdict).tool___builtin_vec_delete_aligned; info->tl_malloc_usable_size = VG_(tdict).tool_malloc_usable_size; - +#if defined(VGO_linux) || defined(VGO_solaris) info->mallinfo = VG_(mallinfo); +#endif +#if defined(VGO_linux) info->mallinfo2 = VG_(mallinfo2); +#endif info->clo_trace_malloc = VG_(clo_trace_malloc); info->clo_realloc_zero_bytes_frees = VG_(clo_realloc_zero_bytes_frees); diff --git a/coregrind/pub_core_mallocfree.h b/coregrind/pub_core_mallocfree.h index 3ae9eb486..1ab3a9f08 100644 --- a/coregrind/pub_core_mallocfree.h +++ b/coregrind/pub_core_mallocfree.h @@ -91,6 +91,7 @@ typedef Int ArenaId; # error Unknown platform #endif +#if defined(VGO_linux) /* This struct definition MUST match the system one. */ /* SVID2/XPG mallinfo structure */ struct vg_mallinfo { @@ -120,6 +121,22 @@ struct vg_mallinfo2 { SizeT fordblks; /* total non-inuse space */ SizeT keepcost; /* top-most, releasable (via malloc_trim) space */ }; +#elif defined(VGO_solaris) + +struct vg_mallinfo { + unsigned long arena; /* total space in arena */ + unsigned long ordblks; /* number of ordinary blocks */ + unsigned long smblks; /* number of small blocks */ + unsigned long hblks; /* number of holding blocks */ + unsigned long hblkhd; /* space in holding block headers */ + unsigned long usmblks; /* space in small blocks in use */ + unsigned long fsmblks; /* space in free small blocks */ + unsigned long uordblks; /* space in ordinary blocks in use */ + unsigned long fordblks; /* space in free ordinary blocks */ + unsigned long keepcost; /* cost of enabling keep option */ +}; + +#endif extern void* VG_(arena_malloc) ( ArenaId arena, const HChar* cc, SizeT nbytes ); extern void VG_(arena_free) ( ArenaId arena, void* ptr ); @@ -146,8 +163,12 @@ extern SizeT VG_(arena_malloc_usable_size) ( ArenaId aid, void* payload ); extern SizeT VG_(arena_redzone_size) ( ArenaId aid ); +#if defined(VGO_linux) || defined(VGO_solaris) extern void VG_(mallinfo) ( ThreadId tid, struct vg_mallinfo* mi ); +#endif +#if defined(VGO_linux) extern void VG_(mallinfo2) ( ThreadId tid, struct vg_mallinfo2* mi ); +#endif // VG_(arena_perm_malloc) is for permanent allocation of small blocks. // See VG_(perm_malloc) in pub_tool_mallocfree.h for more details. diff --git a/coregrind/pub_core_replacemalloc.h b/coregrind/pub_core_replacemalloc.h index 4f9c5bb1a..0c81e7c55 100644 --- a/coregrind/pub_core_replacemalloc.h +++ b/coregrind/pub_core_replacemalloc.h @@ -53,8 +53,12 @@ struct vg_mallocfunc_info { void (*tl___builtin_vec_delete_aligned)(ThreadId tid, void* p, SizeT n); void* (*tl_realloc) (ThreadId tid, void* p, SizeT size); SizeT (*tl_malloc_usable_size) (ThreadId tid, void* payload); +#if defined(VGO_linux) || defined(VGO_solaris) void (*mallinfo) (ThreadId tid, struct vg_mallinfo* mi); +#endif +#if defined(VGO_linux) void (*mallinfo2) (ThreadId tid, struct vg_mallinfo2* mi); +#endif Bool clo_trace_malloc; Bool clo_realloc_zero_bytes_frees; }; diff --git a/memcheck/tests/Makefile.am b/memcheck/tests/Makefile.am index 91d58b48b..349cdaf15 100644 --- a/memcheck/tests/Makefile.am +++ b/memcheck/tests/Makefile.am @@ -684,9 +684,16 @@ bug472219_CFLAGS = $(AM_CFLAGS) @FLAG_W_NO_UNINITIALIZED@ calloc_overflow_CFLAGS = ${AM_CFLAGS} @FLAG_W_NO_ALLOC_SIZE_LARGER_THAN@ malloc_usable_CFLAGS = ${AM_CFLAGS} @FLAG_W_NO_MAYBE_UNINITIALIZED@ @FLAG_W_NO_UNINITIALIZED@ mallinfo_CFLAGS = $(AM_CFLAGS) -Wno-deprecated-declarations +if VGCONF_OS_IS_SOLARIS +mallinfo_LDADD = -lmalloc +endif mallinfo2_CFLAGS = $(AM_CFLAGS) -Wno-deprecated-declarations malloc3_CFLAGS = $(AM_CFLAGS) @FLAG_W_NO_ALLOC_SIZE_LARGER_THAN@ sbfragment_CFLAGS = $(AM_CFLAGS) -Wno-deprecated-declarations +if VGCONF_OS_IS_SOLARIS +sbfragment_LDADD = -lmalloc +endif + strchr_CFLAGS = $(AM_CFLAGS) @FLAG_W_NO_UNINITIALIZED@ big_debuginfo_symbol_SOURCES = big_debuginfo_symbol.cpp