-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathThreadCreation.qll
More file actions
62 lines (56 loc) · 1.92 KB
/
ThreadCreation.qll
File metadata and controls
62 lines (56 loc) · 1.92 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
57
58
59
60
61
62
/**
* A library for reasoning about thread creation events in C#.
*/
import Concurrency
/**
* A method or constructor which starts a thread based on one of its parameters.
*/
class ThreadStartingCallable extends Callable {
ThreadStartingCallable() {
this.(Constructor).getDeclaringType().getQualifiedName() = "System.Threading.Tasks.Task" or
this.(Method).getQualifiedName() = "System.Threading.Tasks.Task.Run" or
this.(Constructor).getDeclaringType().getQualifiedName() = "System.Threading.Thread" or
this.(Method).getQualifiedName() = "System.Threading.Thread.Start" or
this.(Constructor)
.getDeclaringType()
.getQualifiedName()
.matches("System.Threading.Tasks.Task<%>")
}
}
/**
* A callable which may be the starting point of a concurrently executing thread.
* This is an abstract class; subclasses provide different ways of recognizing
* such entry points.
*/
abstract class ConcurrentEntryPoint extends Callable { }
/**
* Methods annotated with the `async` keyword are concurrent entry points.
*/
class AsyncMethod extends ConcurrentEntryPoint {
AsyncMethod() { this.(Modifiable).isAsync() }
}
/**
* Lambdas or methods passed into the thread or task creation library functions
* will execute at the beginning of a new thread.
*/
class LibraryTask extends ConcurrentEntryPoint {
LibraryTask() {
exists(Call c, Expr arg |
c.getTarget() instanceof ThreadStartingCallable and
arg = c.getAnArgument()
|
this = arg or
this = arg.(DelegateCreation).getArgument().(CallableAccess).getTarget()
)
}
}
/**
* A method which takes some measures to control concurrent execution can be taken
* as an indication that the code is expected to run concurrently.
*/
class ConcurrencyAwareMethod extends ConcurrentEntryPoint {
ConcurrencyAwareMethod() {
this = any(LockStmt l).getEnclosingCallable() or
this = any(LockingCall c).getEnclosingCallable()
}
}