summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc
diff options
context:
space:
mode:
authorAlex Shlyapnikov <alekseys@google.com>2018-01-17 23:20:36 +0000
committerAlex Shlyapnikov <alekseys@google.com>2018-01-17 23:20:36 +0000
commitfd2833992a93f0bb4f3ca535ddda8f600b722926 (patch)
tree843e83d259db7e2011203990f8a54e60e3789887 /compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc
parent8bf200aeb4b953912ec0fc8354f10dd2d01f4fd0 (diff)
downloadbcm5719-llvm-fd2833992a93f0bb4f3ca535ddda8f600b722926.tar.gz
bcm5719-llvm-fd2833992a93f0bb4f3ca535ddda8f600b722926.zip
[Sanitizers] Make common allocator agnostic to failure handling modes.
Summary: Make common allocator agnostic to failure handling modes and move the decision up to the particular sanitizer's allocator, where the context is available (call stack, parameters, return nullptr/crash mode etc.) It simplifies the common allocator and allows the particular sanitizer's allocator to generate more specific and detailed error reports (which will be implemented later). The behavior is largely the same, except one case, the violation of the common allocator's check for "size + alignment" overflow is now reportied as OOM instead of "bad request". It feels like a worthy tradeoff and "size + alignment" is huge in this case anyway (thus, can be interpreted as not enough memory to satisfy the request). There's also a Report() statement added there. Reviewers: eugenis Subscribers: kubamracek, llvm-commits, #sanitizers Differential Revision: https://reviews.llvm.org/D42198 llvm-svn: 322784
Diffstat (limited to 'compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc')
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc13
1 files changed, 7 insertions, 6 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc
index fc4f7a75ae3..0642ee426da 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc
@@ -140,8 +140,8 @@ void *InternalAlloc(uptr size, InternalAllocatorCache *cache, uptr alignment) {
if (size + sizeof(u64) < size)
return nullptr;
void *p = RawInternalAlloc(size + sizeof(u64), cache, alignment);
- if (!p)
- return nullptr;
+ if (UNLIKELY(!p))
+ return DieOnFailure::OnOOM();
((u64*)p)[0] = kBlockMagic;
return (char*)p + sizeof(u64);
}
@@ -155,16 +155,17 @@ void *InternalRealloc(void *addr, uptr size, InternalAllocatorCache *cache) {
size = size + sizeof(u64);
CHECK_EQ(kBlockMagic, ((u64*)addr)[0]);
void *p = RawInternalRealloc(addr, size, cache);
- if (!p)
- return nullptr;
+ if (UNLIKELY(!p))
+ return DieOnFailure::OnOOM();
return (char*)p + sizeof(u64);
}
void *InternalCalloc(uptr count, uptr size, InternalAllocatorCache *cache) {
if (UNLIKELY(CheckForCallocOverflow(count, size)))
- return InternalAllocator::FailureHandler::OnBadRequest();
+ return DieOnFailure::OnBadRequest();
void *p = InternalAlloc(count * size, cache);
- if (p) internal_memset(p, 0, count * size);
+ if (LIKELY(p))
+ internal_memset(p, 0, count * size);
return p;
}
OpenPOWER on IntegriCloud