about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorFrank Busse <bb0xfb@gmail.com>2022-03-18 09:06:48 +0000
committerMartinNowack <2443641+MartinNowack@users.noreply.github.com>2022-04-25 18:13:56 +0100
commit33bac31837938c0fdc143022ae8498beb57510a8 (patch)
treed8018c568ae1d44599504500ed86b624468582c8
parentee94e78a5bde3b491282db7acf1620c224119459 (diff)
downloadklee-33bac31837938c0fdc143022ae8498beb57510a8.tar.gz
use mallinfo2 if available
-rw-r--r--CMakeLists.txt1
-rw-r--r--include/klee/Config/config.h.cmin3
-rw-r--r--lib/Support/MemoryUsage.cpp6
3 files changed, 9 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 728bf922..a92c2f2e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -409,6 +409,7 @@ endif (HAVE_PTY_H OR HAVE_UTIL_H OR HAVE_LIBUTIL_H)
 ################################################################################
 check_cxx_symbol_exists(__ctype_b_loc ctype.h HAVE_CTYPE_EXTERNALS)
 check_cxx_symbol_exists(mallinfo malloc.h HAVE_MALLINFO)
+check_cxx_symbol_exists(mallinfo2 malloc.h HAVE_MALLINFO2)
 check_cxx_symbol_exists(malloc_zone_statistics malloc/malloc.h HAVE_MALLOC_ZONE_STATISTICS)
 
 check_include_file(sys/statfs.h HAVE_SYSSTATFS_H)
diff --git a/include/klee/Config/config.h.cmin b/include/klee/Config/config.h.cmin
index 00431117..272b090a 100644
--- a/include/klee/Config/config.h.cmin
+++ b/include/klee/Config/config.h.cmin
@@ -22,6 +22,9 @@
 /* Define if mallinfo() is available on this platform. */
 #cmakedefine HAVE_MALLINFO @HAVE_MALLINFO@
 
+/* Define if mallinfo2() is available on this platform. */
+#cmakedefine HAVE_MALLINFO2 @HAVE_MALLINFO2@
+
 /* Define to 1 if you have the `malloc_zone_statistics' function. */
 #cmakedefine HAVE_MALLOC_ZONE_STATISTICS @HAVE_MALLOC_ZONE_STATISTICS@
 
diff --git a/lib/Support/MemoryUsage.cpp b/lib/Support/MemoryUsage.cpp
index 6e9f9424..5878939e 100644
--- a/lib/Support/MemoryUsage.cpp
+++ b/lib/Support/MemoryUsage.cpp
@@ -16,7 +16,7 @@
 #include "gperftools/malloc_extension.h"
 #endif
 
-#ifdef HAVE_MALLINFO
+#if defined(HAVE_MALLINFO) || defined(HAVE_MALLINFO2)
 #include <malloc.h>
 #endif
 #ifdef HAVE_MALLOC_ZONE_STATISTICS
@@ -96,6 +96,10 @@ size_t util::GetTotalMallocUsage() {
   MallocExtension::instance()->GetNumericProperty(
       "generic.current_allocated_bytes", &value);
   return value;
+#elif defined(HAVE_MALLINFO2)
+  // niy in tcmalloc
+  struct mallinfo2 mi = ::mallinfo2();
+  return mi.uordblks + mi.hblkhd;
 #elif defined(HAVE_MALLINFO)
   struct mallinfo mi = ::mallinfo();
   // The malloc implementation in glibc (pmalloc2)