diff options
| author | Matt Morehouse <mascasa@google.com> | 2019-10-30 11:17:56 -0700 |
|---|---|---|
| committer | Matt Morehouse <mascasa@google.com> | 2019-10-30 11:26:05 -0700 |
| commit | 7904bd9409b86afbec763d0d95cb75ccef559379 (patch) | |
| tree | 2b804ca111107a4749af4213426e5bee6fac4d5e /compiler-rt/lib/msan | |
| parent | e477988309dbde214a6d16ec690a416882714aac (diff) | |
| download | bcm5719-llvm-7904bd9409b86afbec763d0d95cb75ccef559379.tar.gz bcm5719-llvm-7904bd9409b86afbec763d0d95cb75ccef559379.zip | |
[sanitizer_common] Create max_allocation_size_mb flag.
Summary:
The flag allows the user to specify a maximum allocation size that the
sanitizers will honor. Any larger allocations will return nullptr or
crash depending on allocator_may_return_null.
Reviewers: kcc, eugenis
Reviewed By: kcc, eugenis
Subscribers: #sanitizers, llvm-commits
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D69576
Diffstat (limited to 'compiler-rt/lib/msan')
| -rw-r--r-- | compiler-rt/lib/msan/msan_allocator.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/compiler-rt/lib/msan/msan_allocator.cpp b/compiler-rt/lib/msan/msan_allocator.cpp index 6aa4e273807..a08c1a00d2e 100644 --- a/compiler-rt/lib/msan/msan_allocator.cpp +++ b/compiler-rt/lib/msan/msan_allocator.cpp @@ -115,9 +115,16 @@ static Allocator allocator; static AllocatorCache fallback_allocator_cache; static StaticSpinMutex fallback_mutex; +static uptr max_malloc_size; + void MsanAllocatorInit() { SetAllocatorMayReturnNull(common_flags()->allocator_may_return_null); allocator.Init(common_flags()->allocator_release_to_os_interval_ms); + if (common_flags()->max_allocation_size_mb) + max_malloc_size = Min(common_flags()->max_allocation_size_mb << 20, + kMaxAllowedMallocSize); + else + max_malloc_size = kMaxAllowedMallocSize; } AllocatorCache *GetAllocatorCache(MsanThreadLocalMallocStorage *ms) { @@ -132,12 +139,12 @@ void MsanThreadLocalMallocStorage::CommitBack() { static void *MsanAllocate(StackTrace *stack, uptr size, uptr alignment, bool zeroise) { - if (size > kMaxAllowedMallocSize) { + if (size > max_malloc_size) { if (AllocatorMayReturnNull()) { Report("WARNING: MemorySanitizer failed to allocate 0x%zx bytes\n", size); return nullptr; } - ReportAllocationSizeTooBig(size, kMaxAllowedMallocSize, stack); + ReportAllocationSizeTooBig(size, max_malloc_size, stack); } MsanThread *t = GetCurrentThread(); void *allocated; |

