forked from github/codeql-coding-standards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNonRecursiveMutexRecursivelyLocked.ql
More file actions
37 lines (35 loc) · 1.33 KB
/
NonRecursiveMutexRecursivelyLocked.ql
File metadata and controls
37 lines (35 loc) · 1.33 KB
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
34
35
36
37
/**
* @id c/misra/non-recursive-mutex-recursively-locked
* @name RULE-22-18: Non-recursive mutexes shall not be recursively locked
* @description Mutexes initialized with mtx_init() without mtx_recursive shall not be locked by a
* thread that has previously locked it.
* @kind problem
* @precision very-high
* @problem.severity error
* @tags external/misra/id/rule-22-18
* correctness
* concurrency
* external/misra/c/2012/amendment4
* external/misra/obligation/required
*/
import cpp
import codingstandards.c.misra
import codingstandards.c.SubObjects
import codingstandards.cpp.ConcurrencyNew
import codingstandards.cpp.Type
from
LockProtectedControlFlowNode n, CMutexFunctionCall lockCall, SubObject mutex,
CMutexFunctionCall coveredByLock
where
not isExcluded(n, Concurrency9Package::nonRecursiveMutexRecursivelyLockedQuery()) and
lockCall = n and
coveredByLock = n.coveredByLock() and
not coveredByLock = lockCall and
mutex.isPrecise() and
coveredByLock.getLockExpr() = mutex.getAnAddressOfExpr() and
lockCall.getLockExpr() = mutex.getAnAddressOfExpr() and
forex(C11MutexSource init | init.getMutexExpr() = mutex.getAnAddressOfExpr() |
not init.isRecursive()
)
select n, "Non-recursive mutex " + mutex.toString() + " locked after it is $@.", coveredByLock,
"already locked"