// can be removed by setting LimitMb to 0. This function's parameters should
// be fully trusted to avoid security mishaps.
void __scudo_set_rss_limit(size_t LimitMb, int HardLimit);
+
+ // This function outputs various allocator statistics for both the Primary
+ // and Secondary allocators, including memory usage, number of allocations
+ // and deallocations.
+ void __scudo_print_stats(void);
#ifdef __cplusplus
} // extern "C"
#endif
SoftRssLimitMb = LimitMb;
CheckRssLimit = HardRssLimitMb || SoftRssLimitMb;
}
+
+ void printStats() {
+ initThreadMaybe();
+ BackendAllocator.printStats();
+ }
};
static ScudoAllocator Instance(LINKER_INITIALIZED);
return;
Instance.setRssLimit(LimitMb, !!HardLimit);
}
+
+void __scudo_print_stats() {
+ Instance.printStats();
+}
Stats.Get(StatType);
}
+ void printStats() {
+ Primary.PrintStats();
+ Secondary.PrintStats();
+ }
+
private:
PrimaryAllocator Primary;
SecondaryAllocator Secondary;
SANITIZER_INTERFACE_ATTRIBUTE
void __scudo_set_rss_limit(uptr LimitMb, s32 HardLimit);
+
+SANITIZER_INTERFACE_ATTRIBUTE
+void __scudo_print_stats();
} // extern "C"
#endif // SCUDO_INTERFACE_INTERNAL_H_
--- /dev/null
+// RUN: %clang_scudo %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s
+
+// Tests that the allocator stats printing function exists and outputs
+// "something". Currently that "something" is fairly nebulous, as the 32-bit
+// primary doesn't output anything, and for the 64-bit one it's highly dependent
+// on the size class map and potential library allocations. So keep it very
+// generic for now.
+
+#include <stdlib.h>
+
+#include <sanitizer/scudo_interface.h>
+
+int main(int argc, char **argv)
+{
+ free(malloc(1U));
+ __scudo_print_stats();
+ return 0;
+}
+
+// CHECK: Stats: