This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] Implement shared semantics checks for XNU functions in PthreadLockChecker
Needs ReviewPublic

Authored by ASDenysPetrov on Sep 4 2020, 8:25 AM.

Details

Summary

Implement shared semantics checks for correct use of XNU functions for shared and exclusive mutexes.

Clarification:
Shared semantics says that if a lock has been acquired as shared, so it shall be released as shared as well. And vice versa, unique(usual) acquisition shall be followed by a unique unlock. This produces so-called pairs "shared-shared" and "unique-unique" Any mixed sequences of "shared-unique" or "unique-shared" are ill-formed and can lead to undefined behavior.

In particular affected functions lck_rw_lock_shared and lck_rw_unlock_shared are guided by documentaion here
https://developer.apple.com/library/archive/documentation/Darwin/Conceptual/KernelProgramming/synchronization/synchronization.html#//apple_ref/doc/uid/TP30000905-CH218-BABCHEIA
Quote: "You should always be careful when using these functions, as unlocking a lock held in shared mode using an exclusive call or vice-versa will lead to undefined results."

Diff Detail

Event Timeline

ASDenysPetrov created this revision.Sep 4 2020, 8:25 AM

Fixed some missed conditions. Added more tests.

Minor fixes.

It would be nice if someone had time to look at this. Thanks.

It would be nice if someone had time to look at this. Thanks.

I am just looking, but I am not a pthread expert.

It would be nice if someone had time to look at this. Thanks.

I am just looking, but I am not a pthread expert.

Sorry, absolutely no competence.

ASDenysPetrov edited the summary of this revision. (Show Details)Sep 28 2020, 8:50 AM

@baloghadamsoftware

Sorry, absolutely no competence.

That's OK. I've added a clarification section to the summary to make it easier to understand my intentions.

Just a ping. Let me, please, do smth with this revision.

Hey, folk. Please, look at this revision.
This is the 2nd revision from the stack of 3. Its aim is preparing the field for the 3rd revision (also welcome to review). The 1st one has been closed.

Just want to load this revision in scope of the stack. I need you review for this. Thanks.

Could you please give a few links to some documentation about the functions you are trying to model?
Is https://developer.apple.com/library/archive/documentation/Darwin/Conceptual/KernelProgramming/synchronization/synchronization.html a legitimate resource for this?

It's really important to bake the proper semantic rules into the modeling.

ASDenysPetrov edited the summary of this revision. (Show Details)Feb 18 2021, 5:24 AM
ASDenysPetrov edited the summary of this revision. (Show Details)

@steakhal

Could you please give a few links to some documentation about the functions you are trying to model?

Yes, you a re right. I've edited the summary with the link.