-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #839 from goblint/issue_718
MayLock Analysis & Sanity Checks of Mutex Usage & Analysis of Mutex Types
- Loading branch information
Showing
27 changed files
with
926 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
(** An analysis tracking the type of a mutex. *) | ||
|
||
open GoblintCil | ||
open Analyses | ||
|
||
module MAttr = ValueDomain.MutexAttr | ||
module LF = LibraryFunctions | ||
|
||
module Spec : Analyses.MCPSpec with module D = Lattice.Unit and module C = Lattice.Unit = | ||
struct | ||
include Analyses.IdentitySpec | ||
|
||
let name () = "pthreadMutexType" | ||
module D = Lattice.Unit | ||
module C = Lattice.Unit | ||
|
||
(* Removing indexes here avoids complicated lookups and allows to have the LVals as vars here, at the price that different types of mutexes in arrays are not dinstinguished *) | ||
module O = Lval.OffsetNoIdx | ||
|
||
module V = struct | ||
include Printable.Prod(CilType.Varinfo)(O) | ||
let is_write_only _ = false | ||
end | ||
|
||
module G = MAttr | ||
|
||
(* transfer functions *) | ||
let assign ctx (lval:lval) (rval:exp) : D.t = | ||
match lval with | ||
| (Var v, o) -> | ||
(* There's no way to use the PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP etc for accesses via pointers *) | ||
let rec helper o t = function | ||
| Field ({fname = "__data"; _}, Field ({fname = "__kind"; _}, NoOffset)) when ValueDomain.Compound.is_mutex_type t -> | ||
let kind = | ||
(match Cil.constFold true rval with | ||
| Const (CInt (c, _, _)) -> MAttr.of_int c | ||
| _ -> `Top) | ||
in | ||
ctx.sideg (v,o) kind; | ||
ctx.local | ||
| Index (i,o') -> | ||
let o'' = O.of_offs (`Index (i, `NoOffset)) in | ||
helper (O.add_offset o o'') (Cilfacade.typeOffset t (Index (i,NoOffset))) o' | ||
| Field (f,o') -> | ||
let o'' = O.of_offs (`Field (f, `NoOffset)) in | ||
helper (O.add_offset o o'') (Cilfacade.typeOffset t (Field (f,NoOffset))) o' | ||
| NoOffset -> ctx.local | ||
in | ||
helper `NoOffset v.vtype o | ||
| _ -> ctx.local | ||
|
||
let special ctx (lval: lval option) (f:varinfo) (arglist:exp list) : D.t = | ||
let desc = LF.find f in | ||
match desc.special arglist with | ||
| MutexInit {mutex = mutex; attr = attr} -> | ||
let attr = ctx.ask (Queries.EvalMutexAttr attr) in | ||
let mutexes = ctx.ask (Queries.MayPointTo mutex) in | ||
(* It is correct to iter over these sets here, as mutexes need to be intialized before being used, and an analysis that detects usage before initialization is a different analysis. *) | ||
Queries.LS.iter (function (v, o) -> ctx.sideg (v,O.of_offs o) attr) mutexes; | ||
ctx.local | ||
| _ -> ctx.local | ||
|
||
let startstate v = D.bot () | ||
let threadenter ctx lval f args = [D.top ()] | ||
let threadspawn ctx lval f args fctx = ctx.local | ||
let exitstate v = D.top () | ||
|
||
let query ctx (type a) (q: a Queries.t): a Queries.result = | ||
match q with | ||
| Queries.MutexType (v,o) -> (ctx.global (v,o):MutexAttrDomain.t) | ||
| _ -> Queries.Result.top q | ||
end | ||
|
||
let _ = | ||
MCP.register_analysis (module Spec : MCPSpec) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.