This is an archive of the discontinued LLVM Phabricator instance.

Add tid validation checks to blocking mutex and rw mutex
AbandonedPublic

Authored by fjricci on Feb 6 2017, 10:54 AM.

Details

Summary

Blocking mutex currently only performs tid validation checks
in the mac and windows implementations. Add these checks to the
linux implementation as well.

Also add analogous validation checks to rw mutex. In order to
access the current tid, this requires moving the implementation
of rw mutex out of the sanitizer mutex header file.

Event Timeline

fjricci created this revision.Feb 6 2017, 10:54 AM
kubamracek edited reviewers, added: kcc; removed: samsonov.Feb 6 2017, 10:55 AM
dvyukov edited edge metadata.Feb 7 2017, 2:17 AM

This adds 5 calls and 3 syscalls per rw mutex lock/unlock. What's the performance effect of this?

I'm working on evaluating that currently. I assume that since mac and windows already use these checks, it won't be a significant decrease in performance (and if it is, we should consider removing the checks from those platforms).

dvyukov added inline comments.Feb 8 2017, 8:15 AM
lib/sanitizer_common/sanitizer_common.cc
77

"state == kReadLock" must be "state >= kReadLock" because kReadLock is a counter.
Checking state != kUnlocked when owner_ == GetTid() is pointless because state is always kWriteLock when owner_ == GetTid().
This should be:
CHECK(state >= kReadLock || owner_ == GetTid());
Also note the reversed order of conditions -- syscall is slower than a check of local variable.

fjricci abandoned this revision.Feb 9 2017, 11:48 AM

Fixed via D29728