summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc
diff options
context:
space:
mode:
authorAlexey Samsonov <samsonov@google.com>2012-08-27 09:30:58 +0000
committerAlexey Samsonov <samsonov@google.com>2012-08-27 09:30:58 +0000
commitdc8d1f1039564940a44da00bcb755829dbf5256f (patch)
treecebacd84827decbfb3696a2666894ff6bfe81054 /compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc
parent882a283946e5d116df41805096d1bd5ff7b680da (diff)
downloadbcm5719-llvm-dc8d1f1039564940a44da00bcb755829dbf5256f.tar.gz
bcm5719-llvm-dc8d1f1039564940a44da00bcb755829dbf5256f.zip
[Sanitizer] move low-level (mmap-based) allocator to sanitizer_common
llvm-svn: 162663
Diffstat (limited to 'compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc')
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc25
1 files changed, 25 insertions, 0 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc
index 816fddf1c5a..b08434ad668 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc
@@ -56,4 +56,29 @@ void *InternalAllocBlock(void *p) {
return pp + 1;
}
+// LowLevelAllocator
+static LowLevelAllocateCallback low_level_alloc_callback;
+
+void *LowLevelAllocator::Allocate(uptr size) {
+ CHECK((size & (size - 1)) == 0 && "size must be a power of two");
+ if (allocated_end_ - allocated_current_ < (sptr)size) {
+ uptr size_to_allocate = Max(size, kPageSize);
+ allocated_current_ =
+ (char*)MmapOrDie(size_to_allocate, __FUNCTION__);
+ allocated_end_ = allocated_current_ + size_to_allocate;
+ if (low_level_alloc_callback) {
+ low_level_alloc_callback((uptr)allocated_current_,
+ size_to_allocate);
+ }
+ }
+ CHECK(allocated_end_ - allocated_current_ >= (sptr)size);
+ void *res = allocated_current_;
+ allocated_current_ += size;
+ return res;
+}
+
+void SetLowLevelAllocateCallback(LowLevelAllocateCallback callback) {
+ low_level_alloc_callback = callback;
+}
+
} // namespace __sanitizer
OpenPOWER on IntegriCloud