This is an archive of the discontinued LLVM Phabricator instance.

[Sanitizers] 32 bit allocator respects allocator_may_return_null flag
ClosedPublic

Authored by alekseyshl on Jun 20 2017, 5:40 PM.

Details

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.

Diff Detail

Repository
rL LLVM

Event Timeline

alekseyshl created this revision.Jun 20 2017, 5:40 PM
eugenis added inline comments.Jun 20 2017, 5:59 PM
lib/sanitizer_common/sanitizer_allocator_primary32.h
308 ↗(On Diff #103302)

is it possible for CreateBatch to return nullptr?
It may Allocate().

  • Accomodate for CreateBatch returning nullptr.
alekseyshl marked an inline comment as done.Jun 21 2017, 9:59 AM
alekseyshl added inline comments.
lib/sanitizer_common/sanitizer_allocator_primary32.h
308 ↗(On Diff #103302)

Indeed!

cryptoad added inline comments.Jun 21 2017, 10:46 AM
lib/sanitizer_common/sanitizer_allocator_local_cache.h
147 ↗(On Diff #103302)

Doing it this way, we are losing the 'unlikeliness' of c->count == 0.
I am not sure this will matter much though.

alekseyshl marked an inline comment as done.
  • Restore UNLIKELY(c->count == 0) condition semantics
alekseyshl marked an inline comment as done.Jun 21 2017, 11:21 AM
alekseyshl added inline comments.
lib/sanitizer_common/sanitizer_allocator_local_cache.h
147 ↗(On Diff #103302)

Let's bring it back then.

eugenis accepted this revision.Jun 21 2017, 4:08 PM

LGTM

lib/sanitizer_common/sanitizer_allocator_local_cache.h
147 ↗(On Diff #103302)

unnecessary {}

lib/sanitizer_common/sanitizer_allocator_primary32.h
284 ↗(On Diff #103425)

early exit
do we need UNLIKELY here? probably not.

This revision is now accepted and ready to land.Jun 21 2017, 4:08 PM
alekseyshl marked 2 inline comments as done.
  • Address comments
alekseyshl added inline comments.Jun 21 2017, 4:44 PM
lib/sanitizer_common/sanitizer_allocator_local_cache.h
147 ↗(On Diff #103302)

I'd rather keep those, I prefer to add {} when if body is more than one line. This one is.

This revision was automatically updated to reflect the committed changes.