summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator64_testlib.cc
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2012-12-27 07:37:24 +0000
committerKostya Serebryany <kcc@google.com>2012-12-27 07:37:24 +0000
commit6f604b50072a990c7a2436262d1bce1fb744414e (patch)
tree5684348557118104f3255427876a57dbc84a64f2 /compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator64_testlib.cc
parent757f3fc394cb57c721ce12373fb34ed5ff19e74d (diff)
downloadbcm5719-llvm-6f604b50072a990c7a2436262d1bce1fb744414e.tar.gz
bcm5719-llvm-6f604b50072a990c7a2436262d1bce1fb744414e.zip
[asan/tsan] when unmapping a chunk of user memory, apply madvise(MADV_DONTNEED) to the corresponding chunk of shadow memory. Also update sanitizer_allocator64_testlib.cc
llvm-svn: 171144
Diffstat (limited to 'compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator64_testlib.cc')
-rw-r--r--compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator64_testlib.cc37
1 files changed, 30 insertions, 7 deletions
diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator64_testlib.cc b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator64_testlib.cc
index 3f56cc4463c..3e9c541bceb 100644
--- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator64_testlib.cc
+++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator64_testlib.cc
@@ -10,7 +10,14 @@
// The primary purpose of this file is an end-to-end integration test
// for CombinedAllocator.
//===----------------------------------------------------------------------===//
+/* Usage:
+clang++ -fno-exceptions -g -fPIC -I. -I../include -Isanitizer \
+ sanitizer_common/tests/sanitizer_allocator64_testlib.cc \
+ sanitizer_common/sanitizer_*.cc -shared -o testmalloc.so
+LD_PRELOAD=`pwd`/testmalloc.so /your/app
+*/
#include "sanitizer_common/sanitizer_allocator.h"
+#include "sanitizer_common/sanitizer_common.h"
#include <stddef.h>
#include <stdio.h>
#include <unistd.h>
@@ -20,10 +27,9 @@ namespace {
static const uptr kAllocatorSpace = 0x600000000000ULL;
static const uptr kAllocatorSize = 0x10000000000; // 1T.
-typedef SizeClassAllocator64<kAllocatorSpace, kAllocatorSize, 16,
- DefaultSizeClassMap> PrimaryAllocator;
-typedef SizeClassAllocatorLocalCache<PrimaryAllocator::kNumClasses,
- PrimaryAllocator> AllocatorCache;
+typedef SizeClassAllocator64<kAllocatorSpace, kAllocatorSize, 0,
+ CompactSizeClassMap> PrimaryAllocator;
+typedef SizeClassAllocatorLocalCache<PrimaryAllocator> AllocatorCache;
typedef LargeMmapAllocator<> SecondaryAllocator;
typedef CombinedAllocator<PrimaryAllocator, AllocatorCache,
SecondaryAllocator> Allocator;
@@ -34,7 +40,7 @@ static Allocator allocator;
static int inited = 0;
__attribute__((constructor))
-void Init() {
+static void Init() {
if (inited) return;
inited = true; // this must happen before any threads are created.
allocator.Init();
@@ -51,37 +57,54 @@ void *malloc(size_t size) {
}
void free(void *p) {
- assert(inited);
+ if (!inited) return;
+ // assert(inited);
allocator.Deallocate(&cache, p);
}
void *calloc(size_t nmemb, size_t size) {
+ Init();
assert(inited);
return allocator.Allocate(&cache, nmemb * size, 8, /*cleared=*/true);
}
void *realloc(void *p, size_t new_size) {
+ Init();
assert(inited);
return allocator.Reallocate(&cache, p, new_size, 8);
}
-void *memalign() { assert(0); }
+void *memalign(size_t boundary, size_t size) {
+ Init();
+ return allocator.Allocate(&cache, size, boundary);
+}
+void *__libc_memalign(size_t boundary, size_t size) {
+ Init();
+ return allocator.Allocate(&cache, size, boundary);
+}
int posix_memalign(void **memptr, size_t alignment, size_t size) {
+ Init();
*memptr = allocator.Allocate(&cache, size, alignment);
CHECK_EQ(((uptr)*memptr & (alignment - 1)), 0);
return 0;
}
void *valloc(size_t size) {
+ Init();
assert(inited);
return allocator.Allocate(&cache, size, GetPageSizeCached());
}
void *pvalloc(size_t size) {
+ Init();
assert(inited);
if (size == 0) size = GetPageSizeCached();
return allocator.Allocate(&cache, size, GetPageSizeCached());
}
+
+void malloc_usable_size() { }
+void mallinfo() { }
+void mallopt() { }
}
#endif
OpenPOWER on IntegriCloud