about summary refs log tree commit diff
path: root/src/tools/miri/tests
diff options
context:
space:
mode:
authorKonstantinos Andrikopoulos <andrikopoulos@google.com>2024-09-09 02:32:19 +0200
committerKonstantinos Andrikopoulos <andrikopoulos@google.com>2024-09-09 02:44:43 +0200
commitff28977c065762160d35ca81dc85a199ac7d460d (patch)
tree5c7a05dd2f14278066b62589e4ed2f9c686e6cf5 /src/tools/miri/tests
parent59cb24dc76eb999390541241cfc45217fe2f6326 (diff)
downloadrust-ff28977c065762160d35ca81dc85a199ac7d460d.tar.gz
rust-ff28977c065762160d35ca81dc85a199ac7d460d.zip
detect when pthread_rwlock_t is moved
For some implementations of pthreads, the address of pthread_rwlock_t
(or its fields) is used to identify the lock. That means that if the
contents of a pthread_rwlock_t are moved in memory, effectively a new
lock object is created, which is completely independted from the
original. Thus we want to detect when when such objects are moved and
show an error.
Diffstat (limited to 'src/tools/miri/tests')
-rw-r--r--src/tools/miri/tests/fail-dep/concurrency/libx_pthread_rwlock_moved.rs14
-rw-r--r--src/tools/miri/tests/fail-dep/concurrency/libx_pthread_rwlock_moved.stderr15
2 files changed, 29 insertions, 0 deletions
diff --git a/src/tools/miri/tests/fail-dep/concurrency/libx_pthread_rwlock_moved.rs b/src/tools/miri/tests/fail-dep/concurrency/libx_pthread_rwlock_moved.rs
new file mode 100644
index 00000000000..b51bae79849
--- /dev/null
+++ b/src/tools/miri/tests/fail-dep/concurrency/libx_pthread_rwlock_moved.rs
@@ -0,0 +1,14 @@
+//@ignore-target-windows: No pthreads on Windows
+
+fn main() {
+    unsafe {
+        let mut rw = libc::PTHREAD_RWLOCK_INITIALIZER;
+
+        libc::pthread_rwlock_rdlock(&mut rw as *mut _);
+
+        // Move rwlock
+        let mut rw2 = rw;
+
+        libc::pthread_rwlock_unlock(&mut rw2 as *mut _); //~ ERROR: pthread_rwlock_t can't be moved after first use
+    }
+}
diff --git a/src/tools/miri/tests/fail-dep/concurrency/libx_pthread_rwlock_moved.stderr b/src/tools/miri/tests/fail-dep/concurrency/libx_pthread_rwlock_moved.stderr
new file mode 100644
index 00000000000..8a5ec4aa98d
--- /dev/null
+++ b/src/tools/miri/tests/fail-dep/concurrency/libx_pthread_rwlock_moved.stderr
@@ -0,0 +1,15 @@
+error: Undefined Behavior: pthread_rwlock_t can't be moved after first use
+  --> $DIR/libx_pthread_rwlock_moved.rs:LL:CC
+   |
+LL |         libc::pthread_rwlock_unlock(&mut rw2 as *mut _);
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pthread_rwlock_t can't be moved after first use
+   |
+   = 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 `main` at $DIR/libx_pthread_rwlock_moved.rs:LL:CC
+
+note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
+
+error: aborting due to 1 previous error
+