Skip to content

Commit a25b71b

Browse files
committed
implement SecRandomCopyBytes for macOS RNG
1 parent 8fd40db commit a25b71b

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

Diff for: src/fn_call.rs

+12
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,18 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
712712
"_NSGetArgv" => {
713713
this.write_scalar(Scalar::Ptr(this.machine.argv.unwrap()), dest)?;
714714
},
715+
"SecRandomCopyBytes" => {
716+
let len = this.read_scalar(args[1])?.to_usize()?;
717+
let ptr = this.read_scalar(args[2])?.to_ptr()?;
718+
719+
if len > 0 {
720+
let data = gen_random(this, len as usize)?;
721+
this.memory_mut().get_mut(ptr.alloc_id)?
722+
.write_bytes(tcx, ptr, &data)?;
723+
}
724+
725+
this.write_null(dest)?;
726+
}
715727

716728
// Windows API stubs.
717729
// HANDLE = isize

Diff for: test-cargo-miri/tests/test.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,13 @@ fn fixed_rng() {
2121

2222
#[test]
2323
fn entropy_rng() {
24-
#[cfg(not(target_os="macos"))] // FIXME entropy does not work on macOS
25-
// (Not disabling the entire test as that would change the output.)
26-
{
27-
// Use this opportunity to test querying the RNG (needs an external crate, hence tested here and not in the compiletest suite)
28-
let mut rng = SmallRng::from_entropy();
29-
let _val = rng.gen::<i32>();
24+
// Use this opportunity to test querying the RNG (needs an external crate, hence tested here and not in the compiletest suite)
25+
let mut rng = SmallRng::from_entropy();
26+
let _val = rng.gen::<i32>();
3027

31-
// Also try per-thread RNG.
32-
let mut rng = rand::thread_rng();
33-
let _val = rng.gen::<i32>();
34-
}
28+
// Also try per-thread RNG.
29+
let mut rng = rand::thread_rng();
30+
let _val = rng.gen::<i32>();
3531
}
3632

3733
// A test that won't work on miri

0 commit comments

Comments
 (0)