summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/hwasan/hwasan_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/hwasan/hwasan_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/hwasan/hwasan_allocator.cc')
-rw-r--r--compiler-rt/lib/hwasan/hwasan_allocator.cc4
1 files changed, 3 insertions, 1 deletions
diff --git a/compiler-rt/lib/hwasan/hwasan_allocator.cc b/compiler-rt/lib/hwasan/hwasan_allocator.cc
index 2acac818912..5bd46f8f579 100644
--- a/compiler-rt/lib/hwasan/hwasan_allocator.cc
+++ b/compiler-rt/lib/hwasan/hwasan_allocator.cc
@@ -128,7 +128,7 @@ static void *HwasanAllocate(StackTrace *stack, uptr size, uptr alignment,
if (size > kMaxAllowedMallocSize) {
Report("WARNING: HWAddressSanitizer failed to allocate %p bytes\n",
(void *)size);
- return Allocator::FailureHandler::OnBadRequest();
+ return ReturnNullOrDieOnFailure::OnBadRequest();
}
HwasanThread *t = GetCurrentThread();
void *allocated;
@@ -140,6 +140,8 @@ static void *HwasanAllocate(StackTrace *stack, uptr size, uptr alignment,
AllocatorCache *cache = &fallback_allocator_cache;
allocated = allocator.Allocate(cache, size, alignment);
}
+ if (UNLIKELY(!allocated))
+ return ReturnNullOrDieOnFailure::OnOOM();
Metadata *meta =
reinterpret_cast<Metadata *>(allocator.GetMetaData(allocated));
meta->state = CHUNK_ALLOCATED;
OpenPOWER on IntegriCloud