Skip to content

Commit 5f4f94b

Browse files
Merge pull request #1187 from goblint/issue_843
Spawn threads created from unknown functions as non-unique
2 parents 808e91d + 809e5a0 commit 5f4f94b

51 files changed

Lines changed: 214 additions & 157 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/analyses/abortUnless.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ struct
6565
false
6666

6767
let startstate v = false
68-
let threadenter ctx lval f args = [false]
69-
let threadspawn ctx lval f args fctx = false
68+
let threadenter ctx ~multiple lval f args = [false]
69+
let threadspawn ctx ~multiple lval f args fctx = false
7070
let exitstate v = false
7171
end
7272

src/analyses/accessAnalysis.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct
5454

5555
(** We just lift start state, global and dependency functions: *)
5656
let startstate v = ()
57-
let threadenter ctx lval f args = [()]
57+
let threadenter ctx ~multiple lval f args = [()]
5858
let exitstate v = ()
5959
let context fd d = ()
6060

@@ -121,7 +121,7 @@ struct
121121
ctx.local
122122

123123

124-
let threadspawn ctx lval f args fctx =
124+
let threadspawn ctx ~multiple lval f args fctx =
125125
(* must explicitly access thread ID lval because special to pthread_create doesn't if singlethreaded before *)
126126
begin match lval with
127127
| None -> ()

src/analyses/activeLongjmp.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct
2626

2727
(* Initial values don't really matter: overwritten at longjmp call. *)
2828
let startstate v = D.bot ()
29-
let threadenter ctx lval f args = [D.bot ()]
29+
let threadenter ctx ~multiple lval f args = [D.bot ()]
3030
let exitstate v = D.top ()
3131

3232
let query ctx (type a) (q: a Queries.t): a Queries.result =

src/analyses/activeSetjmp.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct
2525
| _ -> ctx.local
2626

2727
let startstate v = D.bot ()
28-
let threadenter ctx lval f args = [D.bot ()]
28+
let threadenter ctx ~multiple lval f args = [D.bot ()]
2929
let exitstate v = D.top ()
3030

3131
let query ctx (type a) (q: a Queries.t): a Queries.result =

src/analyses/apron/relationAnalysis.apron.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ struct
647647

648648
(* Thread transfer functions. *)
649649

650-
let threadenter ctx lval f args =
650+
let threadenter ctx ~multiple lval f args =
651651
let st = ctx.local in
652652
match Cilfacade.find_varinfo_fundec f with
653653
| fd ->
@@ -665,7 +665,7 @@ struct
665665
(* TODO: do something like base? *)
666666
failwith "relation.threadenter: unknown function"
667667

668-
let threadspawn ctx lval f args fctx =
668+
let threadspawn ctx ~multiple lval f args fctx =
669669
ctx.local
670670

671671
let event ctx e octx =

src/analyses/base.ml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,7 +1944,7 @@ struct
19441944

19451945

19461946

1947-
let forkfun (ctx:(D.t, G.t, C.t, V.t) Analyses.ctx) (lv: lval option) (f: varinfo) (args: exp list) : (lval option * varinfo * exp list) list =
1947+
let forkfun (ctx:(D.t, G.t, C.t, V.t) Analyses.ctx) (lv: lval option) (f: varinfo) (args: exp list) : (lval option * varinfo * exp list) list * bool =
19481948
let create_thread lval arg v =
19491949
try
19501950
(* try to get function declaration *)
@@ -1985,7 +1985,7 @@ struct
19851985
else
19861986
start_funvars
19871987
in
1988-
List.filter_map (create_thread (Some (Mem id, NoOffset)) (Some ptc_arg)) start_funvars_with_unknown
1988+
List.filter_map (create_thread (Some (Mem id, NoOffset)) (Some ptc_arg)) start_funvars_with_unknown, false
19891989
end
19901990
| _, _ when get_bool "sem.unknown_function.spawn" ->
19911991
(* TODO: Remove sem.unknown_function.spawn check because it is (and should be) really done in LibraryFunctions.
@@ -1998,9 +1998,9 @@ struct
19981998
let deep_flist = collect_invalidate ~deep:true (Analyses.ask_of_ctx ctx) ctx.global ctx.local deep_args in
19991999
let flist = shallow_flist @ deep_flist in
20002000
let addrs = List.concat_map AD.to_var_may flist in
2001-
if addrs <> [] then M.debug ~category:Analyzer "Spawning functions from unknown function: %a" (d_list ", " CilType.Varinfo.pretty) addrs;
2002-
List.filter_map (create_thread None None) addrs
2003-
| _, _ -> []
2001+
if addrs <> [] then M.debug ~category:Analyzer "Spawning non-unique functions from unknown function: %a" (d_list ", " CilType.Varinfo.pretty) addrs;
2002+
List.filter_map (create_thread None None) addrs, true
2003+
| _, _ -> [], false
20042004

20052005
let assert_fn ctx e refine =
20062006
(* make the state meet the assertion in the rest of the code *)
@@ -2131,9 +2131,9 @@ struct
21312131
let addr = eval_lv (Analyses.ask_of_ctx ctx) ctx.global ctx.local lval in
21322132
(addr, AD.type_of addr)
21332133
in
2134-
let forks = forkfun ctx lv f args in
2134+
let forks, multiple = forkfun ctx lv f args in
21352135
if M.tracing then if not (List.is_empty forks) then M.tracel "spawn" "Base.special %s: spawning functions %a\n" f.vname (d_list "," CilType.Varinfo.pretty) (List.map BatTuple.Tuple3.second forks);
2136-
List.iter (BatTuple.Tuple3.uncurry ctx.spawn) forks;
2136+
List.iter (BatTuple.Tuple3.uncurry (ctx.spawn ~multiple)) forks;
21372137
let st: store = ctx.local in
21382138
let gs = ctx.global in
21392139
let desc = LF.find f in
@@ -2641,7 +2641,7 @@ struct
26412641
in
26422642
combine_one ctx.local after
26432643

2644-
let threadenter ctx (lval: lval option) (f: varinfo) (args: exp list): D.t list =
2644+
let threadenter ctx ~multiple (lval: lval option) (f: varinfo) (args: exp list): D.t list =
26452645
match Cilfacade.find_varinfo_fundec f with
26462646
| fd ->
26472647
[make_entry ~thread:true ctx fd args]
@@ -2651,7 +2651,7 @@ struct
26512651
let st = special_unknown_invalidate ctx (Analyses.ask_of_ctx ctx) ctx.global st f args in
26522652
[st]
26532653

2654-
let threadspawn ctx (lval: lval option) (f: varinfo) (args: exp list) fctx: D.t =
2654+
let threadspawn ctx ~multiple (lval: lval option) (f: varinfo) (args: exp list) fctx: D.t =
26552655
begin match lval with
26562656
| Some lval ->
26572657
begin match ThreadId.get_current (Analyses.ask_of_ctx fctx) with

src/analyses/basePriv.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ end
893893
module MinePrivBase =
894894
struct
895895
include NoFinalize
896-
include ConfCheck.RequireMutexPathSensInit
896+
include ConfCheck.RequireMutexPathSensOneMainInit
897897
include MutexGlobals (* explicit not needed here because G is Prod anyway? *)
898898

899899
let thread_join ?(force=false) ask get e st = st

src/analyses/commonPriv.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ struct
1919
if not mutex_active then failwith "Privatization (to be useful) requires the 'mutex' analysis to be enabled (it is currently disabled)"
2020
end
2121

22-
module RequireMutexPathSensInit =
22+
module RequireMutexPathSensOneMainInit =
2323
struct
2424
let init () =
2525
RequireMutexActivatedInit.init ();
2626
let mutex_path_sens = List.mem "mutex" (GobConfig.get_string_list "ana.path_sens") in
2727
if not mutex_path_sens then failwith "The activated privatization requires the 'mutex' analysis to be enabled & path sensitive (it is currently enabled, but not path sensitive)";
28+
let mainfuns = List.length @@ GobConfig.get_list "mainfun" in
29+
if not (mainfuns = 1) then failwith "The activated privatization requires exactly one main function to be specified";
2830
()
2931
end
3032

src/analyses/condVars.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ struct
155155
ctx.local
156156

157157
let startstate v = D.bot ()
158-
let threadenter ctx lval f args = [D.bot ()]
159-
let threadspawn ctx lval f args fctx = ctx.local
158+
let threadenter ctx ~multiple lval f args = [D.bot ()]
159+
let threadspawn ctx ~multiple lval f args fctx = ctx.local
160160
let exitstate v = D.bot ()
161161
end
162162

src/analyses/expsplit.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ struct
8484
in
8585
emit_splits ctx d
8686

87-
let threadenter ctx lval f args = [ctx.local]
87+
let threadenter ctx ~multiple lval f args = [ctx.local]
8888

89-
let threadspawn ctx lval f args fctx =
89+
let threadspawn ctx ~multiple lval f args fctx =
9090
emit_splits_ctx ctx
9191

9292
let event ctx (event: Events.t) octx =

0 commit comments

Comments
 (0)