-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy paththreadDescendants.ml
More file actions
66 lines (59 loc) · 2.31 KB
/
threadDescendants.ml
File metadata and controls
66 lines (59 loc) · 2.31 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
63
64
65
66
(** thread descendants analysis [threadDescendants]
flow-insensitive construction of descendants may-set for every thread
*)
open Analyses
module TID = ThreadIdDomain.Thread
module TIDs = ConcDomain.ThreadSet
(** reflexive-transitive closure of child relation applied to [tid]
and filtered to only include threads, where [tid] is a must-ancestor
@param man any man
@param tid
*)
let must_ancestor_descendants_closure man tid =
let descendants = man.ask @@ Queries.DescendantThreads tid in
let must_ancestors_descendants = TIDs.filter (TID.must_be_ancestor tid) descendants in
TIDs.add tid must_ancestors_descendants
(** compute all descendant threads that may run along with the ego thread at a program point.
for all of them, tid must be an ancestor
@param man man of ego thread at the program point
@param tid ego thread id
*)
let get_must_ancestor_running_descendants man tid =
let may_created_tids = man.ask Queries.CreatedThreads in
let may_must_ancestor_created_tids =
TIDs.filter (TID.must_be_ancestor tid) may_created_tids
in
let may_transitively_created_tids =
TIDs.fold
(fun child_tid acc -> TIDs.union acc (must_ancestor_descendants_closure man child_tid))
may_must_ancestor_created_tids
(TIDs.empty ())
in
let must_joined_tids = man.ask Queries.MustJoinedThreads in
TIDs.diff_mustset may_transitively_created_tids must_joined_tids
module Spec = struct
include IdentityUnitContextsSpec
module D = Lattice.Unit
module V = TIDV
module G = ConcDomain.ThreadSet
let name () = "threadDescendants"
let startstate _ = D.bot ()
let exitstate _ = D.bot ()
let query man (type a) (x : a Queries.t) : a Queries.result =
match x with
| Queries.DescendantThreads t ->
let children = man.global t in
(G.fold
(fun e acc -> G.union (man.ask @@ Queries.DescendantThreads e) acc)
children
children
: G.t)
| _ -> Queries.Result.top x
let threadspawn man ~multiple lval f args fman =
let tid_lifted = man.ask Queries.CurrentThreadId in
let child_tid_lifted = fman.ask Queries.CurrentThreadId in
match tid_lifted, child_tid_lifted with
| `Lifted tid, `Lifted child_tid -> man.sideg tid (G.singleton child_tid)
| _ -> ()
end
let _ = MCP.register_analysis ~dep:[ "threadid" ] (module Spec : MCPSpec)