about summary refs log tree commit diff
path: root/src/tools
diff options
context:
space:
mode:
authorJubilee <46493976+workingjubilee@users.noreply.github.com>2024-03-11 09:29:36 -0700
committerGitHub <noreply@github.com>2024-03-11 09:29:36 -0700
commitf6ca4258d219979c78e80f688872458a4ad49419 (patch)
tree718d44be98b3547b15ad42825f743738c803bd3b /src/tools
parentafa058179d3237a009174106576d6d6e1543e9e8 (diff)
parentbf47df8b0be83dde623a1057e63fd728c0ae5dec (diff)
Rollup merge of #122249 - RalfJung:machine-read-hook, r=oli-obk
interpret: do not call machine read hooks during validation

Fixes https://github.com/rust-lang/miri/issues/3347

r? ``@oli-obk``
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/miri/tests/pass/alloc-access-tracking.rs25
-rw-r--r--src/tools/miri/tests/pass/alloc-access-tracking.stderr37
2 files changed, 62 insertions, 0 deletions
diff --git a/src/tools/miri/tests/pass/alloc-access-tracking.rs b/src/tools/miri/tests/pass/alloc-access-tracking.rs
new file mode 100644
index 00000000000..5c782fca2df
--- /dev/null
+++ b/src/tools/miri/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/src/tools/miri/tests/pass/alloc-access-tracking.stderr b/src/tools/miri/tests/pass/alloc-access-tracking.stderr
new file mode 100644
index 00000000000..5e219fa1bed
--- /dev/null
+++ b/src/tools/miri/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
+