Skip to content

Commit 07985a3

Browse files
committed
Auto merge of #914 - christianpoveda:use-host-rng, r=oli-obk
Use host's rng when communication is enabled This uses the host's randomness when the communication enabled flag is used. I am not sure about the error handling. I was thinking about fallbacking to `rand` if `getrandom` fails and also print something so the user knows miri is not using the host's rng because it failed. Let me know what you think. Related issue: #800. r? @RalfJung @oli-obk
2 parents fd078e4 + b44fd97 commit 07985a3

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ byteorder = { version = "1.1", features = ["i128"]}
3535
cargo_metadata = { version = "0.8", optional = true }
3636
directories = { version = "2.0", optional = true }
3737
rustc_version = { version = "0.2.3", optional = true }
38+
getrandom = "0.1.10"
3839
env_logger = "0.6"
3940
log = "0.4"
4041
shell-escape = "0.1.4"

src/helpers.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
9797
Align::from_bytes(1).unwrap()
9898
)?.expect("we already checked for size 0");
9999

100-
let rng = this.memory_mut().extra.rng.get_mut();
101100
let mut data = vec![0; len];
102-
rng.fill_bytes(&mut data);
101+
102+
if this.machine.communicate {
103+
// Fill the buffer using the host's rng.
104+
getrandom::getrandom(&mut data).map_err(|err| {
105+
InterpError::Unsupported(UnsupportedOpInfo::Unsupported(err.to_string()))
106+
})?;
107+
}
108+
else {
109+
let rng = this.memory_mut().extra.rng.get_mut();
110+
rng.fill_bytes(&mut data);
111+
}
103112

104113
let tcx = &{this.tcx.tcx};
105114
this.memory_mut().get_mut(ptr.alloc_id)?.write_bytes(tcx, ptr, &data)

0 commit comments

Comments
 (0)