diff --git a/Cargo.toml b/Cargo.toml index 644a3476a6dd..1ab0580cc631 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ byteorder = { version = "1.1", features = ["i128"]} cargo_metadata = { version = "0.8", optional = true } directories = { version = "2.0", optional = true } rustc_version = { version = "0.2.3", optional = true } +getrandom = "0.1.10" env_logger = "0.6" log = "0.4" shell-escape = "0.1.4" diff --git a/README.md b/README.md index f34569d865a8..502c562d1357 100644 --- a/README.md +++ b/README.md @@ -158,8 +158,8 @@ Several `-Z` flags are relevant for Miri: will miss bugs in your program. However, this can also help to make Miri run faster. * `-Zmiri-enable-communication` enables communication between the host - environment and Miri, i.e., all the host environment variables are available - during Miri runtime. + environment and Miri, i.e., Miri uses the host's random number generator and + all the host environment variables are available during runtime. * `-Zmir-opt-level` controls how many MIR optimizations are performed. Miri overrides the default to be `0`; be advised that using any higher level can make Miri miss bugs in your program because they got optimized away. diff --git a/src/helpers.rs b/src/helpers.rs index c0e1ec2cd75b..330d6bc996b7 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -97,9 +97,17 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx Align::from_bytes(1).unwrap() )?.expect("we already checked for size 0"); - let rng = this.memory_mut().extra.rng.get_mut(); let mut data = vec![0; len]; - rng.fill_bytes(&mut data); + + if this.machine.communicate { + // Fill the buffer using the host's rng. + getrandom::getrandom(&mut data) + .map_err(|err| err_unsup_format!("getrandom failed: {}", err))?; + } + else { + let rng = this.memory_mut().extra.rng.get_mut(); + rng.fill_bytes(&mut data); + } let tcx = &{this.tcx.tcx}; this.memory_mut().get_mut(ptr.alloc_id)?.write_bytes(tcx, ptr, &data) diff --git a/src/machine.rs b/src/machine.rs index 9d50c77c7c4c..8989062b513a 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -93,7 +93,8 @@ pub struct Evaluator<'tcx> { /// TLS state. pub(crate) tls: TlsData<'tcx>, - /// If enabled, the `env_vars` field is populated with the host env vars during initialization. + /// If enabled, the `env_vars` field is populated with the host env vars during initialization + /// and random number generation is delegated to the host. pub(crate) communicate: bool, }