-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathNonstandardUseOfThreadingObject.ql
More file actions
56 lines (50 loc) · 1.88 KB
/
NonstandardUseOfThreadingObject.ql
File metadata and controls
56 lines (50 loc) · 1.88 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* @id c/misra/nonstandard-use-of-threading-object
* @name RULE-22-12: Standard library threading objects (mutexes, threads, etc.) shall only be accessed by the appropriate Standard Library functions
* @description Thread objects, thread synchronization objects, and thread-specific storage pointers
* shall only be accessed by the appropriate Standard Library functions.
* @kind problem
* @precision very-high
* @problem.severity error
* @tags external/misra/id/rule-22-12
* correctness
* concurrency
* external/misra/c/2012/amendment4
* external/misra/obligation/mandatory
*/
import cpp
import codingstandards.c.misra
import codingstandards.cpp.Concurrency
import codingstandards.cpp.types.Resolve
predicate isThreadingObject(Type t) {
t instanceof ResolvesTo<C11ThreadingObjectType>::IgnoringSpecifiers
}
predicate validUseOfStdThreadObject(Expr e) {
e.getParent() instanceof AddressOfExpr
or
exists(Call c |
c.getTarget().hasName(["tss_get", "tss_set", "tss_delete"]) and
e = c.getArgument(0)
)
}
predicate isStdThreadObjectPtr(Type t) { isThreadingObject(t.(PointerType).getBaseType()) }
predicate invalidStdThreadObjectUse(Expr e) {
// Invalid use of mtx_t, etc.
isThreadingObject(e.getType()) and
not validUseOfStdThreadObject(e)
or
// Invalid cast from mtx_t* to void*, etc.
isStdThreadObjectPtr(e.getType()) and
exists(Cast cast |
cast.getExpr() = e and
not isStdThreadObjectPtr(cast.getType())
)
}
from Expr e
where
not isExcluded(e, Concurrency8Package::nonstandardUseOfThreadingObjectQuery()) and
invalidStdThreadObjectUse(e) and
// Deduplicate results: (mtx = mtx) is an expression of mtx type, but don't flag the equality
// check, only flag the two `mtx` references.
not invalidStdThreadObjectUse(e.getAChild+())
select e, "Invalid usage of standard thread object type '" + e.getType().toString() + "'."