From ab392a86a335d63e9fdeff74ce8c99a89ef7fafd Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 9 Mar 2024 19:13:18 +0100 Subject: [PATCH] interpret: do not call machine read hooks during validation --- tests/pass/alloc-access-tracking.rs | 25 +++++++++++++++++ tests/pass/alloc-access-tracking.stderr | 37 +++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 tests/pass/alloc-access-tracking.rs create mode 100644 tests/pass/alloc-access-tracking.stderr diff --git a/tests/pass/alloc-access-tracking.rs b/tests/pass/alloc-access-tracking.rs new file mode 100644 index 0000000000..5c782fca2d --- /dev/null +++ b/tests/pass/alloc-access-tracking.rs @@ -0,0 +1,25 @@ +#![feature(start)] +#![no_std] +//@compile-flags: -Zmiri-track-alloc-id=17 -Zmiri-track-alloc-accesses -Cpanic=abort +//@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 {} +} diff --git a/tests/pass/alloc-access-tracking.stderr b/tests/pass/alloc-access-tracking.stderr new file mode 100644 index 0000000000..5e219fa1be --- /dev/null +++ b/tests/pass/alloc-access-tracking.stderr @@ -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 +