This is an archive of the discontinued LLVM Phabricator instance.

[tsan] Return 0 from malloc_size for non-malloc'd pointers
ClosedPublic

Authored by kubamracek on Apr 28 2016, 3:30 AM.

Details

Summary

In http://reviews.llvm.org/D19100, I introduced a bug: On OS X, existing programs rely on malloc_size() to detect whether a pointer comes from heap memory (malloc_size returns non-zero) or not. We have to distinguish between a zero-sized allocation (where we need to return 1 from malloc_size, due to other binary compatibility reasons, see http://reviews.llvm.org/D19100), and pointers that are not returned from malloc at all.

Diff Detail

Repository
rL LLVM

Event Timeline

kubamracek updated this revision to Diff 55395.Apr 28 2016, 3:30 AM
kubamracek retitled this revision from to [tsan] Return 0 from malloc_size for non-malloc'd pointers.
kubamracek updated this object.
kubamracek added reviewers: dvyukov, kcc, glider, samsonov.
kubamracek added a project: Restricted Project.
aizatsky added inline comments.
lib/tsan/rtl/tsan_mman.cc
167 ↗(On Diff #55395)

this changes behavior on all platforms, not only Mac, right? Is it intended?

kubamracek added inline comments.Apr 29 2016, 5:52 AM
lib/tsan/rtl/tsan_mman.cc
167 ↗(On Diff #55395)

Correct, this changes all platforms. It is intended, I should have said that in the original description. At least on Linux, malloc_usable_size also returns non-zero value for a zero-sized allocation, I guess other platforms behave the same. Running under TSan shouldn't change that to avoid breaking compatibility.

aizatsky accepted this revision.Apr 29 2016, 10:46 AM
aizatsky added a reviewer: aizatsky.
This revision is now accepted and ready to land.Apr 29 2016, 10:46 AM
This revision was automatically updated to reflect the committed changes.