diff options
author | Alexey Samsonov <samsonov@google.com> | 2012-08-27 09:30:58 +0000 |
---|---|---|
committer | Alexey Samsonov <samsonov@google.com> | 2012-08-27 09:30:58 +0000 |
commit | 70e177e29c6f9ac987b65a79f6b4f3ebdabc75cc (patch) | |
tree | 796420f9799d74d43c3104291d21b943a9f97102 /lib/sanitizer_common/sanitizer_allocator.cc | |
parent | ae46cd0e92794f3b18f49f94c081e414fb7e1367 (diff) |
[Sanitizer] move low-level (mmap-based) allocator to sanitizer_common
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@162663 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/sanitizer_allocator.cc')
-rw-r--r-- | lib/sanitizer_common/sanitizer_allocator.cc | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/sanitizer_common/sanitizer_allocator.cc b/lib/sanitizer_common/sanitizer_allocator.cc index 816fddf1c..b08434ad6 100644 --- a/lib/sanitizer_common/sanitizer_allocator.cc +++ b/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 |