Some final cleanup

This commit is contained in:
Aaron Hill 2019-04-09 15:49:34 -04:00
parent c6e0d09714
commit 0837d630f7
No known key found for this signature in database
GPG key ID: B4087E510E98B164
2 changed files with 10 additions and 9 deletions

View file

@ -213,11 +213,11 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
"syscall" => {
let sys_getrandom = this.eval_path_scalar(&["libc", "SYS_getrandom"])?
.expect("Failed to get libc::SYS_getrandom")
.to_usize(this)? as i64;
.to_usize(this)?;
// `libc::syscall(NR_GETRANDOM, buf.as_mut_ptr(), buf.len(), GRND_NONBLOCK)`
// is called if a `HashMap` is created the regular way (e.g. HashMap<K, V>).
match this.read_scalar(args[0])?.to_usize(this)? as i64 {
match this.read_scalar(args[0])?.to_usize(this)? {
id if id == sys_getrandom => {
let ptr = this.read_scalar(args[1])?.to_ptr()?;
let len = this.read_scalar(args[2])?.to_usize(this)?;
@ -795,13 +795,15 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
}
}
fn gen_random<'a, 'mir, 'tcx>(this: &mut MiriEvalContext<'a, 'mir, 'tcx>,
len: usize) -> Result<Vec<u8>, EvalError<'tcx>> {
fn gen_random<'a, 'mir, 'tcx>(
this: &mut MiriEvalContext<'a, 'mir, 'tcx>,
len: usize,
) -> Result<Vec<u8>, EvalError<'tcx>> {
match this.machine.rng.as_ref() {
match &mut this.machine.rng {
Some(rng) => {
let mut data = vec![0; len];
rng.borrow_mut().fill_bytes(&mut data);
rng.fill_bytes(&mut data);
Ok(data)
}
None => {

View file

@ -23,7 +23,6 @@ mod stacked_borrows;
use std::collections::HashMap;
use std::borrow::Cow;
use std::cell::RefCell;
use rand::rngs::StdRng;
use rand::SeedableRng;
@ -336,7 +335,7 @@ pub struct Evaluator<'tcx> {
/// The random number generator to use if Miri
/// is running in non-deterministic mode
pub(crate) rng: Option<RefCell<StdRng>>
pub(crate) rng: Option<StdRng>
}
impl<'tcx> Evaluator<'tcx> {
@ -350,7 +349,7 @@ impl<'tcx> Evaluator<'tcx> {
tls: TlsData::default(),
validate,
stacked_borrows: stacked_borrows::State::default(),
rng: seed.map(|s| RefCell::new(StdRng::seed_from_u64(s)))
rng: seed.map(|s| StdRng::seed_from_u64(s))
}
}
}