about summary refs log tree commit diff
path: root/src/tools/miri/tests/fail
diff options
context:
space:
mode:
authorBen Kimock <kimockb@gmail.com>2023-06-16 19:10:54 -0400
committerBen Kimock <kimockb@gmail.com>2023-06-20 10:16:42 -0400
commit69dc7353a15a8a18f4e99d494cffb38ebb36a695 (patch)
tree65c2e2733bd6aad03367f7257614e8c5a5c3c162 /src/tools/miri/tests/fail
parenta00405649b5d11160768ae1f630a261fcc16315c (diff)
downloadrust-69dc7353a15a8a18f4e99d494cffb38ebb36a695.tar.gz
rust-69dc7353a15a8a18f4e99d494cffb38ebb36a695.zip
Make munmap throw unsup errors instead of trying to work
Diffstat (limited to 'src/tools/miri/tests/fail')
-rw-r--r--src/tools/miri/tests/fail/munmap.rs22
-rw-r--r--src/tools/miri/tests/fail/munmap.stderr20
-rw-r--r--src/tools/miri/tests/fail/munmap_partial.rs2
-rw-r--r--src/tools/miri/tests/fail/munmap_partial.stderr4
4 files changed, 40 insertions, 8 deletions
diff --git a/src/tools/miri/tests/fail/munmap.rs b/src/tools/miri/tests/fail/munmap.rs
new file mode 100644
index 00000000000..453437a06cf
--- /dev/null
+++ b/src/tools/miri/tests/fail/munmap.rs
@@ -0,0 +1,22 @@
+//@compile-flags: -Zmiri-disable-isolation
+//@ignore-target-windows: No libc on Windows
+
+#![feature(rustc_private)]
+#![feature(strict_provenance)]
+
+use std::ptr;
+
+fn main() {
+    // Linux specifies that it is not an error if the specified range does not contain any pages.
+    // But we simply do not support such calls. This test checks that we report this as
+    // unsupported, not Undefined Behavior.
+    let res = unsafe {
+        libc::munmap(
+            //~^ ERROR: unsupported operation
+            // Some high address we surely have not allocated anything at
+            ptr::invalid_mut(1 << 30),
+            4096,
+        )
+    };
+    assert_eq!(res, 0);
+}
diff --git a/src/tools/miri/tests/fail/munmap.stderr b/src/tools/miri/tests/fail/munmap.stderr
index a8bcbd098f3..cb47769c063 100644
--- a/src/tools/miri/tests/fail/munmap.stderr
+++ b/src/tools/miri/tests/fail/munmap.stderr
@@ -1,8 +1,13 @@
 warning: integer-to-pointer cast
   --> $DIR/munmap.rs:LL:CC
    |
-LL |         libc::munmap(ptr, 1);
-   |         ^^^^^^^^^^^^^^^^^^^^ integer-to-pointer cast
+LL | /         libc::munmap(
+LL | |
+LL | |             // Some high address we surely have not allocated anything at
+LL | |             ptr::invalid_mut(1 << 30),
+LL | |             4096,
+LL | |         )
+   | |_________^ integer-to-pointer cast
    |
    = help: This program is using integer-to-pointer casts or (equivalently) `ptr::from_exposed_addr`,
    = help: which means that Miri might miss pointer bugs in this program.
@@ -13,11 +18,16 @@ LL |         libc::munmap(ptr, 1);
    = note: BACKTRACE:
    = note: inside `main` at $DIR/munmap.rs:LL:CC
 
-error: unsupported operation: Miri does not support partial munmap
+error: unsupported operation: Miri only supports munmap on memory allocated directly by mmap
   --> $DIR/munmap.rs:LL:CC
    |
-LL |         libc::munmap(ptr, 1);
-   |         ^^^^^^^^^^^^^^^^^^^^ Miri does not support partial munmap
+LL | /         libc::munmap(
+LL | |
+LL | |             // Some high address we surely have not allocated anything at
+LL | |             ptr::invalid_mut(1 << 30),
+LL | |             4096,
+LL | |         )
+   | |_________^ Miri only supports munmap on memory allocated directly by mmap
    |
    = help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support
    = note: BACKTRACE:
diff --git a/src/tools/miri/tests/fail/munmap_partial.rs b/src/tools/miri/tests/fail/munmap_partial.rs
index 41387ae0b9d..938850ee286 100644
--- a/src/tools/miri/tests/fail/munmap_partial.rs
+++ b/src/tools/miri/tests/fail/munmap_partial.rs
@@ -13,6 +13,6 @@ fn main() {
             0,
         );
         libc::munmap(ptr, 1);
-        //~^ ERROR: unsupported operation: Miri does not support partial munmap
+        //~^ ERROR: unsupported operation
     }
 }
diff --git a/src/tools/miri/tests/fail/munmap_partial.stderr b/src/tools/miri/tests/fail/munmap_partial.stderr
index a8bd999e660..9a084c50437 100644
--- a/src/tools/miri/tests/fail/munmap_partial.stderr
+++ b/src/tools/miri/tests/fail/munmap_partial.stderr
@@ -13,11 +13,11 @@ LL |         libc::munmap(ptr, 1);
    = note: BACKTRACE:
    = note: inside `main` at $DIR/munmap_partial.rs:LL:CC
 
-error: unsupported operation: Miri does not support partial munmap
+error: unsupported operation: Miri only supports munmap calls that exactly unmap a region previously returned by mmap
   --> $DIR/munmap_partial.rs:LL:CC
    |
 LL |         libc::munmap(ptr, 1);
-   |         ^^^^^^^^^^^^^^^^^^^^ Miri does not support partial munmap
+   |         ^^^^^^^^^^^^^^^^^^^^ Miri only supports munmap calls that exactly unmap a region previously returned by mmap
    |
    = help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support
    = note: BACKTRACE: