-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
interpret: do not call machine read hooks during validation #122249
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#![feature(start)] | ||
#![no_std] | ||
//@compile-flags: -Zmiri-track-alloc-id=17 -Zmiri-track-alloc-accesses -Cpanic=abort | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As an isolated no_std test, I think the alloc IDs here should be fully stable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Damn, somehow it is different on macOS... I guess I'll have to add some |
||
//@only-target-linux: alloc IDs differ between OSes for some reason | ||
|
||
extern "Rust" { | ||
fn miri_alloc(size: usize, align: usize) -> *mut u8; | ||
fn miri_dealloc(ptr: *mut u8, size: usize, align: usize); | ||
} | ||
|
||
#[start] | ||
fn start(_: isize, _: *const *const u8) -> isize { | ||
unsafe { | ||
let ptr = miri_alloc(123, 1); | ||
*ptr = 42; // Crucially, only a write is printed here, no read! | ||
assert_eq!(*ptr, 42); | ||
miri_dealloc(ptr, 123, 1); | ||
} | ||
0 | ||
} | ||
|
||
#[panic_handler] | ||
fn panic_handler(_: &core::panic::PanicInfo) -> ! { | ||
loop {} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
note: tracking was triggered | ||
--> $DIR/alloc-access-tracking.rs:LL:CC | ||
| | ||
LL | let ptr = miri_alloc(123, 1); | ||
| ^^^^^^^^^^^^^^^^^^ created Miri bare-metal heap allocation of 123 bytes (alignment ALIGN bytes) with id 17 | ||
| | ||
= note: BACKTRACE: | ||
= note: inside `start` at $DIR/alloc-access-tracking.rs:LL:CC | ||
|
||
note: tracking was triggered | ||
--> $DIR/alloc-access-tracking.rs:LL:CC | ||
| | ||
LL | *ptr = 42; // Crucially, only a write is printed here, no read! | ||
| ^^^^^^^^^ write access to allocation with id 17 | ||
| | ||
= note: BACKTRACE: | ||
= note: inside `start` at $DIR/alloc-access-tracking.rs:LL:CC | ||
|
||
note: tracking was triggered | ||
--> $DIR/alloc-access-tracking.rs:LL:CC | ||
| | ||
LL | assert_eq!(*ptr, 42); | ||
| ^^^^^^^^^^^^^^^^^^^^ read access to allocation with id 17 | ||
| | ||
= note: BACKTRACE: | ||
= note: inside `start` at RUSTLIB/core/src/macros/mod.rs:LL:CC | ||
= note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
note: tracking was triggered | ||
--> $DIR/alloc-access-tracking.rs:LL:CC | ||
| | ||
LL | miri_dealloc(ptr, 123, 1); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ freed allocation with id 17 | ||
| | ||
= note: BACKTRACE: | ||
= note: inside `start` at $DIR/alloc-access-tracking.rs:LL:CC | ||
|
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.
I am a bit torn about whether
before_alloc_read
should be suppressed during validation. OTOH it is nice that we can now remove this code here. On the other hand, now if validation does do a read from this static, it will seeUninit
and show a surprising error rather than triggering a cycle error. I don't know if it is even possible to do that, it would require acopy_op_transmute
from the static to somewhere else.If validation passes, we'll still get the cycle error from the actual read part of
copy_op
.