about summary refs log tree commit diff homepage
path: root/lib
diff options
context:
space:
mode:
authorDan Liew <delcypher@gmail.com>2014-04-24 14:14:22 +0100
committerDan Liew <delcypher@gmail.com>2014-04-24 14:14:22 +0100
commit9dd4766a3f58070501ed6498e6aa42c14776cc0f (patch)
tree01cfa9cf86783c002368e43197d92ca8b27f3925 /lib
parent169b4eed5b29427611c7d4211de5c1ab16adb3cb (diff)
parent016120fd8a8a2cac8457b66b6d2a41e0b5093889 (diff)
downloadklee-9dd4766a3f58070501ed6498e6aa42c14776cc0f.tar.gz
Merge pull request #116 from MartinNowack/fix_malloc
Fix handling of memory usage in KLEE.
Diffstat (limited to 'lib')
-rw-r--r--lib/Core/Executor.cpp7
-rw-r--r--lib/Support/MemoryUsage.cpp25
2 files changed, 27 insertions, 5 deletions
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
index 070f825e..abb023eb 100644
--- a/lib/Core/Executor.cpp
+++ b/lib/Core/Executor.cpp
@@ -47,6 +47,7 @@
 #include "klee/Internal/Module/KModule.h"
 #include "klee/Internal/Support/FloatEvaluation.h"
 #include "klee/Internal/System/Time.h"
+#include "klee/Internal/System/MemoryUsage.h"
 
 #if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3)
 #include "llvm/IR/Function.h"
@@ -2584,11 +2585,7 @@ void Executor::run(ExecutionState &initialState) {
         // We need to avoid calling GetMallocUsage() often because it
         // is O(elts on freelist). This is really bad since we start
         // to pummel the freelist once we hit the memory cap.
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3)
-        unsigned mbs = sys::Process::GetMallocUsage() >> 20;
-#else
-        unsigned mbs = sys::Process::GetTotalMemoryUsage() >> 20;
-#endif
+        unsigned mbs = util::GetTotalMallocUsage() >> 20;
         if (mbs > MaxMemory) {
           if (mbs > MaxMemory + 100) {
             // just guess at how many to kill
diff --git a/lib/Support/MemoryUsage.cpp b/lib/Support/MemoryUsage.cpp
new file mode 100644
index 00000000..676ce307
--- /dev/null
+++ b/lib/Support/MemoryUsage.cpp
@@ -0,0 +1,25 @@
+//===-- MemoryUsage.cpp ---------------------------------------------------===//
+//
+//                     The KLEE Symbolic Virtual Machine
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "klee/Internal/System/MemoryUsage.h"
+#include <malloc.h>
+
+using namespace klee;
+
+size_t util::GetTotalMallocUsage() {
+  struct mallinfo mi = ::mallinfo();
+  // The malloc implementation in glibc (pmalloc2)
+  // does not include mmap()'ed memory in mi.uordblks
+  // but other implementations (e.g. tcmalloc) do.
+#if defined(__GLIBC__)
+  return mi.uordblks + mi.hblkhd;
+#else
+  return mi.uordblks;
+#endif
+}