forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
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 rust-lang#3184 - RalfJung:getenv, r=RalfJung
detect and test for data races between setenv and getenv But only on Unix; Windows doesn't have such a data race. Also make target_os_is_unix properly check for unix, which then makes our completely empty android files useless.
Showing
10 changed files
with
79 additions
and
71 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -5,7 +5,6 @@ mod mem; | |
mod sync; | ||
mod thread; | ||
|
||
mod android; | ||
mod freebsd; | ||
mod linux; | ||
mod macos; | ||
|
17 changes: 17 additions & 0 deletions
17
src/tools/miri/tests/fail-dep/shims/env-set_var-data-race.rs
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,17 @@ | ||
//@compile-flags: -Zmiri-disable-isolation -Zmiri-preemption-rate=0 | ||
//@ignore-target-windows: No libc on Windows | ||
|
||
use std::env; | ||
use std::thread; | ||
|
||
fn main() { | ||
let t = thread::spawn(|| unsafe { | ||
// Access the environment in another thread without taking the env lock. | ||
// This represents some C code that queries the environment. | ||
libc::getenv(b"TZ\0".as_ptr().cast()); //~ERROR: Data race detected | ||
}); | ||
// Meanwhile, the main thread uses the "safe" Rust env accessor. | ||
env::set_var("MY_RUST_VAR", "Ferris"); | ||
|
||
t.join().unwrap(); | ||
} |
20 changes: 20 additions & 0 deletions
20
src/tools/miri/tests/fail-dep/shims/env-set_var-data-race.stderr
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 `main` and (2) non-atomic read on thread `<unnamed>` at ALLOC. (2) just happened here | ||
--> $DIR/env-set_var-data-race.rs:LL:CC | ||
| | ||
LL | libc::getenv(b"TZ/0".as_ptr().cast()); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between (1) non-atomic write on thread `main` and (2) non-atomic read on thread `<unnamed>` at ALLOC. (2) just happened here | ||
| | ||
help: and (1) occurred earlier here | ||
--> $DIR/env-set_var-data-race.rs:LL:CC | ||
| | ||
LL | env::set_var("MY_RUST_VAR", "Ferris"); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= 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 closure at $DIR/env-set_var-data-race.rs:LL:CC | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to previous error | ||
|
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