-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathOutOfOrderLocks.ql
More file actions
33 lines (29 loc) · 988 Bytes
/
OutOfOrderLocks.ql
File metadata and controls
33 lines (29 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* @name Out-of-order locks
* @description Where nested locks are inevitable, they should always be taken in the same order.
* @kind problem
* @id cpp/jpl-c/out-of-order-locks
* @problem.severity warning
* @tags correctness
* concurrency
* external/jpl
*/
import Semaphores
predicate lockOrder(LockOperation outer, LockOperation inner) {
outer.getAReachedNode() = inner and
inner.getLocked() != outer.getLocked()
}
int orderCount(Declaration outerLock, Declaration innerLock) {
result =
strictcount(LockOperation outer, LockOperation inner |
outer.getLocked() = outerLock and
inner.getLocked() = innerLock and
lockOrder(outer, inner)
)
}
from LockOperation outer, LockOperation inner
where
lockOrder(outer, inner) and
orderCount(outer.getLocked(), inner.getLocked()) <=
orderCount(inner.getLocked(), outer.getLocked())
select inner, "Out-of-order locks: A " + inner.say() + " usually precedes a $@.", outer, outer.say()