12#include "klee/Config/config.h"
15#ifdef HAVE_GPERFTOOLS_MALLOC_EXTENSION_H
16#include "gperftools/malloc_extension.h"
22#ifdef HAVE_MALLOC_ZONE_STATISTICS
23#include <malloc/malloc.h>
47#if defined(__has_feature)
48# if __has_feature(address_sanitizer)
49# if __has_include("sanitizer/allocator_interface.h")
50# include <sanitizer/allocator_interface.h>
52# define ASAN_GET_ALLOCATED_MEM_FUNCTION __sanitizer_get_current_allocated_bytes
54# include <sanitizer/asan_interface.h>
56# define ASAN_GET_ALLOCATED_MEM_FUNCTION __asan_get_current_allocated_bytes
58# define KLEE_ASAN_BUILD
63#ifndef KLEE_ASAN_BUILD
64# if defined(__SANITIZE_ADDRESS__)
68 size_t __sanitizer_get_current_allocated_bytes();
69 size_t __asan_get_current_allocated_bytes();
75# define ASAN_GET_ALLOCATED_MEM_FUNCTION __sanitizer_get_current_allocated_bytes
79# define ASAN_GET_ALLOCATED_MEM_FUNCTION __asan_get_current_allocated_bytes
81# define KLEE_ASAN_BUILD
91 return ASAN_GET_ALLOCATED_MEM_FUNCTION();
94#ifdef HAVE_GPERFTOOLS_MALLOC_EXTENSION_H
96 MallocExtension::instance()->GetNumericProperty(
97 "generic.current_allocated_bytes", &value);
99#elif defined(HAVE_MALLINFO)
100 struct mallinfo mi = ::mallinfo();
104#if defined(__GLIBC__)
105 return (
size_t)(unsigned)mi.uordblks + (
unsigned)mi.hblkhd;
107 return (
unsigned)mi.uordblks;
110#elif defined(HAVE_MALLOC_ZONE_STATISTICS)
114 malloc_statistics_t stats;
115 malloc_zone_t **zones;
116 unsigned int num_zones;
118 if (malloc_get_all_zones(0,
nullptr, (vm_address_t **)&zones, &num_zones) !=
123 for (
unsigned i = 0; i < num_zones; i++) {
124 malloc_zone_statistics(zones[i], &stats);
125 total += stats.size_in_use;
131#warning Cannot get malloc info on this platform
size_t GetTotalMallocUsage()
Get total malloc usage in bytes.
void klee_error(const char *msg,...) __attribute__((format(printf