-
Notifications
You must be signed in to change notification settings - Fork 84
MayLock Analysis & Sanity Checks of Mutex Usage & Analysis of Mutex Types #839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
52de056
Simplify Lockset
michael-schwarz dde2b1a
Steps
michael-schwarz c982337
Add case where no warning should be issued
michael-schwarz 37155af
More tests
michael-schwarz 24c7563
Rm spurious code
michael-schwarz 06f98a9
Adapt comments
michael-schwarz 28dc103
Cleanup test
michael-schwarz 575cb54
Add warning if MayLockset is not empty
michael-schwarz 430c376
Account for returning from thread via pthread_exit
michael-schwarz f471f47
Add warning when unlocking mutex that may not held
michael-schwarz 014481e
Rudimentary, flow-insensitive analysis of mutex types
michael-schwarz 8ccfb9e
Fix indentation
michael-schwarz 15131fe
Add test for recurisve mutexes
michael-schwarz 1c17d61
Track value of mutexAttrT locally
michael-schwarz 5f32337
Add mutex type tracking for local mutexes
michael-schwarz 6236e48
Skip 60/05 on OS X
michael-schwarz e8b09f1
Category for Double Locking
michael-schwarz 95f249a
OS X :(
michael-schwarz afd4153
Merge branch 'master' into issue_718
michael-schwarz 32257f8
Merge branch 'master' into issue_718
michael-schwarz 8dc1e84
Merge branch 'master' into issue_718
michael-schwarz ee4b452
Merge branch 'master' into issue_718
michael-schwarz 53112a0
Dynamically lookup constants
michael-schwarz 99f4261
Cleanup
michael-schwarz 792e4ec
Make conditions more clear
michael-schwarz 208fcf1
Slim down tests by removing unused code
michael-schwarz bab294b
Only trace if tracing is enabled
michael-schwarz e8d0219
Finally fix it for OS X
michael-schwarz 7e91913
Merge branch 'master' into issue_718
michael-schwarz 5d82c5c
Fix compilation warnings for test cases with GCC.
jerhard ca53009
Merge branch 'master' into issue_718
michael-schwarz 01fb38a
Warning for unlocking definitely not-held mutex
michael-schwarz 282b671
Add comments about other types of mutexes
michael-schwarz 97713d3
Add further dynamic mutex
michael-schwarz 3a813de
Change queries, fix unlock for recursive mutexes
michael-schwarz b548422
Adapt tests to correct maylockset
michael-schwarz cc95869
Fix test 09
michael-schwarz 283ec75
Merge branch 'master' into issue_718
michael-schwarz 3d064ce
Make example smaller
michael-schwarz e7e15fa
Fix whitespace
michael-schwarz 550c4f3
Style improvement
michael-schwarz f90bbd7
Indentation
michael-schwarz aa29d4c
Indentation
michael-schwarz 1b0ffc4
Fix annotation
michael-schwarz 9f99115
Comments on why 71/07 contains no assertions.
michael-schwarz 52c701f
Fix test 71/08 on OS X which doesn't define some constants
michael-schwarz fec7dd3
71/07: Do not include pthread.h so OS X tests can have asserts
michael-schwarz 5758ff7
Ensure `MutexAttr` survives joins
michael-schwarz fe5c49f
Support for Lvals
michael-schwarz eeb11fa
Support mutexes in structs also for assignments
michael-schwarz be5432c
Add comment
michael-schwarz fbc3df4
Cleanup
michael-schwarz e5c290a
Merge branch 'master' into issue_718
michael-schwarz f2fe2bc
derive compare for MutexType
michael-schwarz 48f154a
Use bespoke V, reduce boilerplate
michael-schwarz 655c1be
Simplify
michael-schwarz 01b9841
Attempt at reuse
michael-schwarz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.