-
Notifications
You must be signed in to change notification settings - Fork 84
Malloc uniqueness #722
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
Malloc uniqueness #722
Changes from 3 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
83e413c
malloc uniqueness analysis
TDacik 8e68873
enable strong updates of unique heap variables
TDacik 674c31f
Merge branch 'master' into malloc_uniqueness
TDacik 68db36d
Fix JSON syntax error in options schema
michael-schwarz d4fe8f2
Remove explicit enabling of recording of backtraces (done via `-v`)
michael-schwarz c963049
Merge branch 'master' into malloc_uniqueness
michael-schwarz 2ce399a
Fix indentation
michael-schwarz 2c40bb7
Modify ChainLattice to have function n: unit -> int instead of int: n
michael-schwarz 41aa0e7
typo
michael-schwarz 768963f
Better readable output for malloc nodes
michael-schwarz 5234d22
Simplify logic in combine
michael-schwarz 82b2454
Simplify mallocWrapper
michael-schwarz bd22bfa
mallocWrapper: rm `has_wrapper_node`
michael-schwarz 932c752
simplify
michael-schwarz 53b8102
simplify
michael-schwarz 8fdc8a6
save a line
michael-schwarz 430f1ad
Pull out alias for Queroes, use consistently
michael-schwarz 6f4f80c
Merge branch 'master' into malloc_uniqueness
michael-schwarz a992328
Add example for unsoundness for calloc
michael-schwarz c0da1e4
Fix incorrect size for calloc blobs (Introduced in 3d27f41c665c60a608…
michael-schwarz e256f80
Add linear search regression
michael-schwarz dba164a
Comment that counter is per thread
michael-schwarz 0f70fbc
Rm spurious pattern match on `f.vname`
michael-schwarz 77c0423
Use `ctx.node` instead of `ctx.prev_node` again
michael-schwarz 309e5b3
Merge branch 'master' into malloc_uniqueness
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // No race should be reported because thread1 and thread2 are both unique | ||
| // and work with their own allocated memory | ||
|
|
||
| #include <stdlib.h> | ||
| #include <pthread.h> | ||
|
|
||
| int *f() | ||
| { | ||
| int *x = malloc(sizeof(int)); | ||
| return x; | ||
| } | ||
|
|
||
| void *thread1(void *v) | ||
| { | ||
| int *x = f(); | ||
| (*x)++; // NORACE | ||
| } | ||
|
|
||
| void *thread2(void *v) | ||
| { | ||
| int *x = f(); | ||
| (*x)++; // NORACE | ||
| } | ||
|
|
||
| int main(int argc, char **argv) | ||
| { | ||
| pthread_t tid1; | ||
| pthread_t tid2; | ||
|
|
||
| pthread_create(&tid1, NULL, thread1, NULL); | ||
| pthread_create(&tid2, NULL, thread2, NULL); | ||
|
|
||
| pthread_join(tid1, NULL); | ||
| pthread_join(tid2, NULL); | ||
| } |
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,27 @@ | ||
| // PARAM: --set ana.malloc.unique_address_count 2 | ||
|
|
||
| // Copied from 29/07. Here, unique addresses are allocated for both x and y. | ||
| // Therefore, it is not necessary to specify wrapper function. | ||
|
|
||
| #include <stdlib.h> | ||
| #include <stdint.h> | ||
|
|
||
| void* myalloc(size_t s) { | ||
| return malloc(s); | ||
| } | ||
|
|
||
| int main() { | ||
| int* x = myalloc(sizeof(int)); | ||
| int* y = myalloc(sizeof(int)); | ||
| int *p; | ||
|
|
||
| *x = 0; | ||
| *y = 1; | ||
|
|
||
| assert(*x == 0); | ||
| assert(*y == 1); | ||
|
|
||
| p = x; x = y; y = p; | ||
| assert(*x == 1); | ||
| assert(*y == 0); | ||
| } |
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,23 @@ | ||
| // PARAM: --set ana.malloc.unique_address_count 1 | ||
|
|
||
| // Copied from 11/05. Here, malloc will allocate an unique address for x only. | ||
|
|
||
| #include <stdlib.h> | ||
| #include <stdint.h> | ||
|
|
||
| void* myalloc(size_t s) { | ||
| return malloc(s); | ||
| } | ||
|
|
||
| int main() { | ||
| int* x = myalloc(sizeof(int)); | ||
| int* y = myalloc(sizeof(int)); | ||
| int* z = myalloc(sizeof(int)); | ||
|
|
||
| *x = 0; | ||
| *y = 1; | ||
| *z = 0; | ||
|
|
||
| assert(*x == 0); | ||
| assert(*y == 1); // UNKNOWN! | ||
| } |
34 changes: 34 additions & 0 deletions
34
tests/regression/11-heap/06-wrapper_plus_unique_addresses.c
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,34 @@ | ||
| // PARAM: --set ana.malloc.wrappers "['myalloc2']" --set ana.malloc.unique_address_count 2 | ||
|
|
||
|
|
||
| // Copied from 02/21. Here, only the inner wrapper function is specified. This should tests | ||
| // the combination of uniqueness analysis and malloc wrapper analysis. | ||
|
|
||
| #include <stdlib.h> | ||
| #include <assert.h> | ||
|
|
||
| void *myalloc(size_t n) { | ||
| return malloc(n); | ||
| } | ||
|
|
||
| void *myalloc2(size_t n) { | ||
| return myalloc(n); | ||
| } | ||
|
|
||
| int main() { | ||
| int *x = myalloc2(sizeof(int)); | ||
| int *y = myalloc2(sizeof(int)); | ||
| int *p; | ||
|
|
||
| *x = 0; | ||
| *y = 1; | ||
|
|
||
| assert(*x == 0); | ||
| assert(*y == 1); | ||
|
|
||
| p = x; x = y; y = p; | ||
| assert(*x == 1); | ||
| assert(*y == 0); | ||
|
|
||
| return 0; | ||
| } |
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,25 @@ | ||
| // PARAM: --set ana.malloc.unique_address_count 2 | ||
|
|
||
| // Both variables x and y are unique and can be strongly (destructively) updated. | ||
|
|
||
| #include <assert.h> | ||
| #include <stdlib.h> | ||
| #include <stdint.h> | ||
|
|
||
| void* myalloc(size_t s) { | ||
| return malloc(s); | ||
| } | ||
|
|
||
| int main() { | ||
| int* x = myalloc(sizeof(int)); | ||
| int* y = myalloc(sizeof(int)); | ||
|
|
||
| *x = 0; | ||
| *y = 1; | ||
|
|
||
| *x = 2; | ||
| *y = 3; | ||
|
|
||
| assert (*x == 2); | ||
| assert (*y == 3); | ||
| } |
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,25 @@ | ||
| // PARAM: --set ana.malloc.unique_address_count 1 | ||
|
|
||
| // Copied from 11/05. Here, variable y is not unique and cannot be strongly updated. | ||
|
|
||
| #include <stdlib.h> | ||
| #include <stdint.h> | ||
|
|
||
| void* myalloc(size_t s) { | ||
| return malloc(s); | ||
| } | ||
|
|
||
| int main() { | ||
| int* x = myalloc(sizeof(int)); | ||
| int* y = myalloc(sizeof(int)); | ||
| int *p; | ||
|
|
||
| *x = 0; | ||
| *y = 1; | ||
|
|
||
| *x = 2; | ||
| *y = 3; | ||
|
|
||
| assert (*x == 2); | ||
| assert (*y == 3); // UNKNOWN! | ||
| } |
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.