diff options
author | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2013-10-15 11:33:48 +0000 |
---|---|---|
committer | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2013-10-15 11:33:48 +0000 |
commit | 113c646c56eea9452aeb8cc481fdbc24898dc780 (patch) | |
tree | 7498c4d5feb71b6460de7e9f4ffab2a0f3d542c4 /compiler-rt/lib/msan/msan_allocator.cc | |
parent | 59c850de6da85014f358529f9636e49ce86e5bd2 (diff) | |
download | bcm5719-llvm-113c646c56eea9452aeb8cc481fdbc24898dc780.tar.gz bcm5719-llvm-113c646c56eea9452aeb8cc481fdbc24898dc780.zip |
[msan] Implement allocator_may_return_null=1 in MemorySanitizer.
llvm-svn: 192687
Diffstat (limited to 'compiler-rt/lib/msan/msan_allocator.cc')
-rw-r--r-- | compiler-rt/lib/msan/msan_allocator.cc | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/compiler-rt/lib/msan/msan_allocator.cc b/compiler-rt/lib/msan/msan_allocator.cc index 0fe1297a86f..04d6fedb2b5 100644 --- a/compiler-rt/lib/msan/msan_allocator.cc +++ b/compiler-rt/lib/msan/msan_allocator.cc @@ -25,6 +25,7 @@ struct Metadata { static const uptr kAllocatorSpace = 0x600000000000ULL; static const uptr kAllocatorSize = 0x80000000000; // 8T. static const uptr kMetadataSize = sizeof(Metadata); +static const uptr kMaxAllowedMallocSize = 8UL << 30; typedef SizeClassAllocator64<kAllocatorSpace, kAllocatorSize, kMetadataSize, DefaultSizeClassMap> PrimaryAllocator; @@ -48,6 +49,11 @@ static inline void Init() { static void *MsanAllocate(StackTrace *stack, uptr size, uptr alignment, bool zeroise) { Init(); + if (size > kMaxAllowedMallocSize) { + Report("WARNING: MemorySanitizer failed to allocate %p bytes\n", + (void *)size); + return AllocatorReturnNull(); + } void *res = allocator.Allocate(&cache, size, alignment, false); Metadata *meta = reinterpret_cast<Metadata*>(allocator.GetMetaData(res)); meta->requested_size = size; @@ -110,9 +116,10 @@ void *MsanReallocate(StackTrace *stack, void *old_p, uptr new_size, uptr memcpy_size = Min(new_size, old_size); void *new_p = MsanAllocate(stack, new_size, alignment, zeroise); // Printf("realloc: old_size %zd new_size %zd\n", old_size, new_size); - if (new_p) + if (new_p) { __msan_memcpy(new_p, old_p, memcpy_size); - MsanDeallocate(stack, old_p); + MsanDeallocate(stack, old_p); + } return new_p; } |