diff options
| author | Alex Shlyapnikov <alekseys@google.com> | 2017-06-22 00:02:37 +0000 |
|---|---|---|
| committer | Alex Shlyapnikov <alekseys@google.com> | 2017-06-22 00:02:37 +0000 |
| commit | f3cc7cc3d868d967a59b35e3ab65c1e340beeb70 (patch) | |
| tree | 0db6f7aca3ee1a1a8b0942d95c9e39d574d4e18f /compiler-rt/lib/sanitizer_common/sanitizer_posix.cc | |
| parent | fe6414b043eb2e5dcd7a6da65a1dc064a2f727d9 (diff) | |
| download | bcm5719-llvm-f3cc7cc3d868d967a59b35e3ab65c1e340beeb70.tar.gz bcm5719-llvm-f3cc7cc3d868d967a59b35e3ab65c1e340beeb70.zip | |
[Sanitizers] 32 bit allocator respects allocator_may_return_null flag
Summary:
Make SizeClassAllocator32 return nullptr when it encounters OOM, which
allows the entire sanitizer's allocator to follow allocator_may_return_null=1
policy, even for small allocations (LargeMmapAllocator is already fixed
by D34243).
Will add a test for OOM in primary allocator later, when
SizeClassAllocator64 can gracefully handle OOM too.
Reviewers: eugenis
Subscribers: kubamracek, llvm-commits
Differential Revision: https://reviews.llvm.org/D34433
llvm-svn: 305972
Diffstat (limited to 'compiler-rt/lib/sanitizer_common/sanitizer_posix.cc')
| -rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_posix.cc | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc index 4184a84c73f..87c5b9add5c 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc @@ -164,11 +164,14 @@ void *MmapOrDieOnFatalError(uptr size, const char *mem_type) { // We want to map a chunk of address space aligned to 'alignment'. // We do it by maping a bit more and then unmaping redundant pieces. // We probably can do it with fewer syscalls in some OS-dependent way. -void *MmapAlignedOrDie(uptr size, uptr alignment, const char *mem_type) { +void *MmapAlignedOrDieOnFatalError(uptr size, uptr alignment, + const char *mem_type) { CHECK(IsPowerOfTwo(size)); CHECK(IsPowerOfTwo(alignment)); uptr map_size = size + alignment; - uptr map_res = (uptr)MmapOrDie(map_size, mem_type); + uptr map_res = (uptr)MmapOrDieOnFatalError(map_size, mem_type); + if (!map_res) + return nullptr; uptr map_end = map_res + map_size; uptr res = map_res; if (res & (alignment - 1)) // Not aligned. |

