From a25b71b6e4d55463acac1fec4fb00dcc05aa257f Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 21 Apr 2019 21:37:06 +0200 Subject: [PATCH] implement SecRandomCopyBytes for macOS RNG --- src/fn_call.rs | 12 ++++++++++++ test-cargo-miri/tests/test.rs | 16 ++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/fn_call.rs b/src/fn_call.rs index 9789a76c63..212e3b36d4 100644 --- a/src/fn_call.rs +++ b/src/fn_call.rs @@ -712,6 +712,18 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<' "_NSGetArgv" => { this.write_scalar(Scalar::Ptr(this.machine.argv.unwrap()), dest)?; }, + "SecRandomCopyBytes" => { + let len = this.read_scalar(args[1])?.to_usize()?; + let ptr = this.read_scalar(args[2])?.to_ptr()?; + + if len > 0 { + let data = gen_random(this, len as usize)?; + this.memory_mut().get_mut(ptr.alloc_id)? + .write_bytes(tcx, ptr, &data)?; + } + + this.write_null(dest)?; + } // Windows API stubs. // HANDLE = isize diff --git a/test-cargo-miri/tests/test.rs b/test-cargo-miri/tests/test.rs index 69a31c42a7..1f2f792148 100644 --- a/test-cargo-miri/tests/test.rs +++ b/test-cargo-miri/tests/test.rs @@ -21,17 +21,13 @@ fn fixed_rng() { #[test] fn entropy_rng() { - #[cfg(not(target_os="macos"))] // FIXME entropy does not work on macOS - // (Not disabling the entire test as that would change the output.) - { - // Use this opportunity to test querying the RNG (needs an external crate, hence tested here and not in the compiletest suite) - let mut rng = SmallRng::from_entropy(); - let _val = rng.gen::(); + // Use this opportunity to test querying the RNG (needs an external crate, hence tested here and not in the compiletest suite) + let mut rng = SmallRng::from_entropy(); + let _val = rng.gen::(); - // Also try per-thread RNG. - let mut rng = rand::thread_rng(); - let _val = rng.gen::(); - } + // Also try per-thread RNG. + let mut rng = rand::thread_rng(); + let _val = rng.gen::(); } // A test that won't work on miri