-
Notifications
You must be signed in to change notification settings - Fork 391
trace: incorporate events #4456
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
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,25 @@ | ||
//@only-target: x86_64-unknown-linux-gnu i686-unknown-linux-gnu | ||
//@compile-flags: -Zmiri-native-lib-enable-tracing | ||
|
||
extern "C" { | ||
fn init_n(n: i32, ptr: *mut u8); | ||
} | ||
|
||
fn main() { | ||
partial_init(); | ||
} | ||
|
||
// Initialise the first 2 elements of the slice from native code, and check | ||
// that the 3rd is correctly deemed uninit. | ||
fn partial_init() { | ||
let mut slice = std::mem::MaybeUninit::<[u8; 3]>::uninit(); | ||
let slice_ptr = slice.as_mut_ptr().cast::<u8>(); | ||
unsafe { | ||
// Initialize the first two elements. | ||
init_n(2, slice_ptr); | ||
assert!(*slice_ptr == 0); | ||
assert!(*slice_ptr.offset(1) == 0); | ||
// Reading the third is UB! | ||
let _val = *slice_ptr.offset(2); //~ ERROR: Undefined Behavior: using uninitialized data | ||
} | ||
} |
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,39 @@ | ||
warning: sharing memory with a native function called via FFI | ||
--> tests/native-lib/fail/tracing/partial_init.rs:LL:CC | ||
| | ||
LL | init_n(2, slice_ptr); | ||
| ^^^^^^^^^^^^^^^^^^^^ sharing memory with a native function | ||
| | ||
= help: when memory is shared with a native function call, Miri can only track initialisation and provenance on a best-effort basis | ||
= help: in particular, Miri assumes that the native call initializes all memory it has written to | ||
= help: Miri also assumes that any part of this memory may be a pointer that is permitted to point to arbitrary exposed memory | ||
= help: what this means is that Miri will easily miss Undefined Behavior related to incorrect usage of this shared memory, so you should not take a clean Miri run as a signal that your FFI code is UB-free | ||
= help: tracing memory accesses in native code is not yet fully implemented, so there can be further imprecisions beyond what is documented here | ||
= note: BACKTRACE: | ||
= note: inside `partial_init` at tests/native-lib/fail/tracing/partial_init.rs:LL:CC | ||
note: inside `main` | ||
--> tests/native-lib/fail/tracing/partial_init.rs:LL:CC | ||
| | ||
LL | partial_init(); | ||
| ^^^^^^^^^^^^^^ | ||
|
||
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory | ||
--> tests/native-lib/fail/tracing/partial_init.rs:LL:CC | ||
| | ||
LL | let _val = *slice_ptr.offset(2); | ||
| ^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here | ||
| | ||
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior | ||
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information | ||
= note: BACKTRACE: | ||
= note: inside `partial_init` at tests/native-lib/fail/tracing/partial_init.rs:LL:CC | ||
note: inside `main` | ||
--> tests/native-lib/fail/tracing/partial_init.rs:LL:CC | ||
| | ||
LL | partial_init(); | ||
| ^^^^^^^^^^^^^^ | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to 1 previous error; 1 warning emitted | ||
|
29 changes: 29 additions & 0 deletions
29
tests/native-lib/fail/tracing/unexposed_reachable_alloc.rs
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,29 @@ | ||
//@only-target: x86_64-unknown-linux-gnu i686-unknown-linux-gnu | ||
//@compile-flags: -Zmiri-permissive-provenance -Zmiri-native-lib-enable-tracing | ||
|
||
extern "C" { | ||
fn do_one_deref(ptr: *const *const *const i32) -> usize; | ||
} | ||
|
||
fn main() { | ||
unexposed_reachable_alloc(); | ||
} | ||
|
||
// Expose 2 pointers by virtue of doing a native read and assert that the 3rd in | ||
// the chain remains properly unexposed. | ||
fn unexposed_reachable_alloc() { | ||
let inner = 42; | ||
let intermediate_a = &raw const inner; | ||
let intermediate_b = &raw const intermediate_a; | ||
let exposed = &raw const intermediate_b; | ||
// Discard the return value; it's just there so the access in C doesn't get optimised away. | ||
unsafe { do_one_deref(exposed) }; | ||
// Native read should have exposed the address of intermediate_b... | ||
let valid: *const i32 = std::ptr::with_exposed_provenance(intermediate_b.addr()); | ||
// but not of intermediate_a. | ||
let invalid: *const i32 = std::ptr::with_exposed_provenance(intermediate_a.addr()); | ||
unsafe { | ||
let _ok = *valid; | ||
let _not_ok = *invalid; //~ ERROR: Undefined Behavior: memory access failed: attempting to access | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
tests/native-lib/fail/tracing/unexposed_reachable_alloc.stderr
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,39 @@ | ||
warning: sharing memory with a native function called via FFI | ||
--> tests/native-lib/fail/tracing/unexposed_reachable_alloc.rs:LL:CC | ||
| | ||
LL | unsafe { do_one_deref(exposed) }; | ||
| ^^^^^^^^^^^^^^^^^^^^^ sharing memory with a native function | ||
| | ||
= help: when memory is shared with a native function call, Miri can only track initialisation and provenance on a best-effort basis | ||
= help: in particular, Miri assumes that the native call initializes all memory it has written to | ||
= help: Miri also assumes that any part of this memory may be a pointer that is permitted to point to arbitrary exposed memory | ||
= help: what this means is that Miri will easily miss Undefined Behavior related to incorrect usage of this shared memory, so you should not take a clean Miri run as a signal that your FFI code is UB-free | ||
= help: tracing memory accesses in native code is not yet fully implemented, so there can be further imprecisions beyond what is documented here | ||
= note: BACKTRACE: | ||
= note: inside `unexposed_reachable_alloc` at tests/native-lib/fail/tracing/unexposed_reachable_alloc.rs:LL:CC | ||
note: inside `main` | ||
--> tests/native-lib/fail/tracing/unexposed_reachable_alloc.rs:LL:CC | ||
| | ||
LL | unexposed_reachable_alloc(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: Undefined Behavior: memory access failed: attempting to access 4 bytes, but got $HEX[noalloc] which is a dangling pointer (it has no provenance) | ||
--> tests/native-lib/fail/tracing/unexposed_reachable_alloc.rs:LL:CC | ||
| | ||
LL | let _not_ok = *invalid; | ||
| ^^^^^^^^ Undefined Behavior occurred here | ||
| | ||
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior | ||
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information | ||
= note: BACKTRACE: | ||
= note: inside `unexposed_reachable_alloc` at tests/native-lib/fail/tracing/unexposed_reachable_alloc.rs:LL:CC | ||
note: inside `main` | ||
--> tests/native-lib/fail/tracing/unexposed_reachable_alloc.rs:LL:CC | ||
| | ||
LL | unexposed_reachable_alloc(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to 1 previous error; 1 warning emitted | ||
|
File renamed without changes.
File renamed without changes.
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a FIXME saying that we should really have a
get_range
onProvenanceMap
.(Here's a next PR for you if you are interested. ;)