summaryrefslogtreecommitdiff
path: root/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc')
-rw-r--r--lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc37
1 files changed, 33 insertions, 4 deletions
diff --git a/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc b/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc
index 038d9c543bb7d..c6dd3c4bb20c4 100644
--- a/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc
+++ b/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc
@@ -14,6 +14,7 @@
clang++ -std=c++11 -fno-exceptions -g -fPIC -I. -I../include -Isanitizer \
sanitizer_common/tests/sanitizer_allocator_testlib.cc \
$(\ls sanitizer_common/sanitizer_*.cc | grep -v sanitizer_common_nolibc.cc) \
+ sanitizer_common/sanitizer_linux_x86_64.S \
-shared -lpthread -o testmalloc.so
LD_PRELOAD=`pwd`/testmalloc.so /your/app
*/
@@ -33,13 +34,22 @@ LD_PRELOAD=`pwd`/testmalloc.so /your/app
# define SANITIZER_FREE_HOOK(p)
#endif
-namespace {
static const uptr kAllocatorSpace = 0x600000000000ULL;
static const uptr kAllocatorSize = 0x10000000000ULL; // 1T.
-// typedef SizeClassAllocator64<kAllocatorSpace, kAllocatorSize, 0,
-typedef SizeClassAllocator64<~(uptr)0, kAllocatorSize, 0,
- CompactSizeClassMap> PrimaryAllocator;
+struct __AP64 {
+ static const uptr kSpaceBeg = ~(uptr)0;
+ static const uptr kSpaceSize = kAllocatorSize;
+ static const uptr kMetadataSize = 0;
+ typedef CompactSizeClassMap SizeClassMap;
+ typedef NoOpMapUnmapCallback MapUnmapCallback;
+ static const uptr kFlags =
+ SizeClassAllocator64FlagMasks::kRandomShuffleChunks;
+};
+
+namespace {
+
+typedef SizeClassAllocator64<__AP64> PrimaryAllocator;
typedef SizeClassAllocatorLocalCache<PrimaryAllocator> AllocatorCache;
typedef LargeMmapAllocator<> SecondaryAllocator;
typedef CombinedAllocator<PrimaryAllocator, AllocatorCache,
@@ -59,6 +69,25 @@ static void thread_dtor(void *v) {
allocator.SwallowCache(&cache);
}
+static size_t GetRss() {
+ if (FILE *f = fopen("/proc/self/statm", "r")) {
+ size_t size = 0, rss = 0;
+ fscanf(f, "%zd %zd", &size, &rss);
+ fclose(f);
+ return rss << 12; // rss is in pages.
+ }
+ return 0;
+}
+
+struct AtExit {
+ ~AtExit() {
+ allocator.PrintStats();
+ Printf("RSS: %zdM\n", GetRss() >> 20);
+ }
+};
+
+static AtExit at_exit;
+
static void NOINLINE thread_init() {
if (!global_inited) {
global_inited = true;