summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc
diff options
context:
space:
mode:
authorAlex Shlyapnikov <alekseys@google.com>2017-06-22 00:02:37 +0000
committerAlex Shlyapnikov <alekseys@google.com>2017-06-22 00:02:37 +0000
commitf3cc7cc3d868d967a59b35e3ab65c1e340beeb70 (patch)
tree0db6f7aca3ee1a1a8b0942d95c9e39d574d4e18f /compiler-rt/lib/sanitizer_common/sanitizer_posix.cc
parentfe6414b043eb2e5dcd7a6da65a1dc064a2f727d9 (diff)
downloadbcm5719-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.cc7
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.
OpenPOWER on IntegriCloud