-
Notifications
You must be signed in to change notification settings - Fork 341
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #3951 - RalfJung:release-clock, r=RalfJung
fix behavior of release_clock() Fixes #3947 Thanks to `@FrankReh` for noticing this and suggesting the right approach for the fix!
- Loading branch information
Showing
9 changed files
with
90 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//! This is a regression test for <https://github.com/rust-lang/miri/issues/3947>: we had some | ||
//! faulty logic around `release_clock` that led to this code not reporting a data race. | ||
//@ignore-target: windows # no libc socketpair on Windows | ||
//@compile-flags: -Zmiri-preemption-rate=0 | ||
use std::thread; | ||
|
||
fn main() { | ||
static mut VAL: u8 = 0; | ||
let mut fds = [-1, -1]; | ||
let res = unsafe { libc::socketpair(libc::AF_UNIX, libc::SOCK_STREAM, 0, fds.as_mut_ptr()) }; | ||
assert_eq!(res, 0); | ||
let thread1 = thread::spawn(move || { | ||
let data = "a".as_bytes().as_ptr(); | ||
let res = unsafe { libc::write(fds[0], data as *const libc::c_void, 1) }; | ||
assert_eq!(res, 1); | ||
// The write to VAL is *after* the write to the socket, so there's no proper synchronization. | ||
unsafe { VAL = 1 }; | ||
}); | ||
thread::yield_now(); | ||
|
||
let mut buf: [u8; 1] = [0; 1]; | ||
let res: i32 = unsafe { | ||
libc::read(fds[1], buf.as_mut_ptr().cast(), buf.len() as libc::size_t).try_into().unwrap() | ||
}; | ||
assert_eq!(res, 1); | ||
assert_eq!(buf, "a".as_bytes()); | ||
|
||
unsafe { assert_eq!({ VAL }, 1) }; //~ERROR: Data race | ||
|
||
thread1.join().unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
error: Undefined Behavior: Data race detected between (1) non-atomic write on thread `unnamed-ID` and (2) non-atomic read on thread `main` at ALLOC. (2) just happened here | ||
--> tests/fail-dep/libc/socketpair-data-race.rs:LL:CC | ||
| | ||
LL | unsafe { assert_eq!({ VAL }, 1) }; | ||
| ^^^ Data race detected between (1) non-atomic write on thread `unnamed-ID` and (2) non-atomic read on thread `main` at ALLOC. (2) just happened here | ||
| | ||
help: and (1) occurred earlier here | ||
--> tests/fail-dep/libc/socketpair-data-race.rs:LL:CC | ||
| | ||
LL | unsafe { VAL = 1 }; | ||
| ^^^^^^^ | ||
= 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 (of the first span): | ||
= note: inside `main` at tests/fail-dep/libc/socketpair-data-race.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 | ||
|