Skip to content
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

MayLock Analysis & Sanity Checks of Mutex Usage & Analysis of Mutex Types #839

Merged
merged 57 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
52de056
Simplify Lockset
michael-schwarz Sep 22, 2022
dde2b1a
Steps
michael-schwarz Sep 22, 2022
c982337
Add case where no warning should be issued
michael-schwarz Sep 22, 2022
37155af
More tests
michael-schwarz Sep 22, 2022
24c7563
Rm spurious code
michael-schwarz Sep 22, 2022
06f98a9
Adapt comments
michael-schwarz Sep 22, 2022
28dc103
Cleanup test
michael-schwarz Sep 22, 2022
575cb54
Add warning if MayLockset is not empty
michael-schwarz Sep 22, 2022
430c376
Account for returning from thread via pthread_exit
michael-schwarz Sep 22, 2022
f471f47
Add warning when unlocking mutex that may not held
michael-schwarz Sep 22, 2022
014481e
Rudimentary, flow-insensitive analysis of mutex types
michael-schwarz Sep 25, 2022
8ccfb9e
Fix indentation
michael-schwarz Sep 25, 2022
15131fe
Add test for recurisve mutexes
michael-schwarz Sep 25, 2022
1c17d61
Track value of mutexAttrT locally
michael-schwarz Sep 25, 2022
5f32337
Add mutex type tracking for local mutexes
michael-schwarz Sep 25, 2022
6236e48
Skip 60/05 on OS X
michael-schwarz Sep 25, 2022
e8b09f1
Category for Double Locking
michael-schwarz Sep 25, 2022
95f249a
OS X :(
michael-schwarz Sep 25, 2022
afd4153
Merge branch 'master' into issue_718
michael-schwarz Oct 24, 2022
32257f8
Merge branch 'master' into issue_718
michael-schwarz Nov 27, 2022
8dc1e84
Merge branch 'master' into issue_718
michael-schwarz Jan 5, 2023
ee4b452
Merge branch 'master' into issue_718
michael-schwarz Mar 21, 2023
53112a0
Dynamically lookup constants
michael-schwarz Mar 27, 2023
99f4261
Cleanup
michael-schwarz Mar 27, 2023
792e4ec
Make conditions more clear
michael-schwarz Mar 27, 2023
208fcf1
Slim down tests by removing unused code
michael-schwarz Mar 27, 2023
bab294b
Only trace if tracing is enabled
michael-schwarz Mar 27, 2023
e8d0219
Finally fix it for OS X
michael-schwarz Mar 28, 2023
7e91913
Merge branch 'master' into issue_718
michael-schwarz Mar 28, 2023
5d82c5c
Fix compilation warnings for test cases with GCC.
jerhard Mar 31, 2023
ca53009
Merge branch 'master' into issue_718
michael-schwarz May 24, 2023
01fb38a
Warning for unlocking definitely not-held mutex
michael-schwarz May 24, 2023
282b671
Add comments about other types of mutexes
michael-schwarz May 24, 2023
97713d3
Add further dynamic mutex
michael-schwarz May 24, 2023
3a813de
Change queries, fix unlock for recursive mutexes
michael-schwarz May 24, 2023
b548422
Adapt tests to correct maylockset
michael-schwarz May 24, 2023
cc95869
Fix test 09
michael-schwarz May 24, 2023
283ec75
Merge branch 'master' into issue_718
michael-schwarz May 24, 2023
3d064ce
Make example smaller
michael-schwarz May 24, 2023
e7e15fa
Fix whitespace
michael-schwarz May 25, 2023
550c4f3
Style improvement
michael-schwarz May 25, 2023
f90bbd7
Indentation
michael-schwarz May 25, 2023
aa29d4c
Indentation
michael-schwarz May 25, 2023
1b0ffc4
Fix annotation
michael-schwarz May 25, 2023
9f99115
Comments on why 71/07 contains no assertions.
michael-schwarz May 25, 2023
52c701f
Fix test 71/08 on OS X which doesn't define some constants
michael-schwarz May 25, 2023
fec7dd3
71/07: Do not include pthread.h so OS X tests can have asserts
michael-schwarz May 25, 2023
5758ff7
Ensure `MutexAttr` survives joins
michael-schwarz May 25, 2023
fe5c49f
Support for Lvals
michael-schwarz May 25, 2023
eeb11fa
Support mutexes in structs also for assignments
michael-schwarz May 25, 2023
be5432c
Add comment
michael-schwarz May 25, 2023
fbc3df4
Cleanup
michael-schwarz May 25, 2023
e5c290a
Merge branch 'master' into issue_718
michael-schwarz May 25, 2023
f2fe2bc
derive compare for MutexType
michael-schwarz May 26, 2023
48f154a
Use bespoke V, reduce boilerplate
michael-schwarz May 26, 2023
655c1be
Simplify
michael-schwarz May 26, 2023
01b9841
Attempt at reuse
michael-schwarz May 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions src/analyses/mutexTypeAnalysis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,30 @@ struct

(* transfer functions *)
let assign ctx (lval:lval) (rval:exp) : D.t =
(* replaces the rightmost offset with r *)
let rec replace_no_offset o r = match o with
| `NoOffset -> r
| `Field (f,o) -> `Field (f, replace_no_offset o r)
| `Index (i,o) -> `Index (i, replace_no_offset o r)
michael-schwarz marked this conversation as resolved.
Show resolved Hide resolved
in
match lval with
| Var v, Field ({fname = "__data"; _}, Field ({fname = "__kind"; _}, NoOffset)) when ValueDomain.Compound.is_mutex_type v.vtype ->
let kind =
(match Cil.constFold true rval with
| Const (CInt (c, _, _)) -> MAttr.of_int c
| _ -> `Top)
| (Var v, o) ->
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

let r = G.singleton ((v,o)) kind in
ctx.sideg v r;
ctx.local
| Index (i,o') -> helper (replace_no_offset o (`Index (Lval.any_index_exp,`NoOffset))) (Cilfacade.typeOffset t (Index (i,NoOffset))) o'
| Field (f,o') -> helper (replace_no_offset o (`Field (f,`NoOffset))) (Cilfacade.typeOffset t (Field (f,NoOffset))) o'
| NoOffset -> ctx.local
in
let r = G.singleton ((v,`NoOffset)) kind in
ctx.sideg v r;
ctx.local
helper `NoOffset v.vtype o
| _ -> ctx.local

let branch ctx (exp:exp) (tv:bool) : D.t =
Expand Down
53 changes: 53 additions & 0 deletions tests/regression/71-doublelocking/13-rec-struct.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// PARAM: --set ana.activated[+] 'maylocks' --set ana.activated[+] 'pthreadMutexType'
#define _GNU_SOURCE
#include<pthread.h>
#include<stdio.h>
#include<unistd.h>
#include <assert.h>


int g;

struct s {
pthread_mutex_t m;
};

typedef struct s s_t;

s_t mut = { PTHREAD_MUTEX_INITIALIZER };

#ifndef __APPLE__
s_t mut2 = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP };
#endif


void* f1(void* ptr) {
int top;

g = 1;
if(top) {
pthread_mutex_lock(&mut.m);
}
pthread_mutex_lock(&mut.m); //WARN
pthread_mutex_unlock(&mut.m);
return NULL;
}


int main(int argc, char const *argv[])
{
pthread_t t1;
pthread_t t2;

pthread_create(&t1,NULL,f1,NULL);
pthread_join(t1, NULL);

#ifndef __APPLE__
pthread_mutex_lock(&mut2.m); //NOWARN
pthread_mutex_lock(&mut2.m); //NOWARN
pthread_mutex_unlock(&mut2.m);
pthread_mutex_unlock(&mut2.m);
#endif

return 0;
}