Skip to content

Commit 6e78b60

Browse files
committed
miri: shim CCRandomGenerateBytes
1 parent 5b75ad0 commit 6e78b60

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/tools/miri/src/shims/unix/macos/foreign_items.rs

+10
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
7878
this.write_pointer(environ, dest)?;
7979
}
8080

81+
// Random data generation
82+
"CCRandomGenerateBytes" => {
83+
let [bytes, count] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
84+
let bytes = this.read_pointer(bytes)?;
85+
let count = this.read_target_usize(count)?;
86+
let success = this.eval_libc_i32("kCCSuccess");
87+
this.gen_random(bytes, count)?;
88+
this.write_int(success, dest)?;
89+
}
90+
8191
// Time related shims
8292
"mach_absolute_time" => {
8393
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//@only-target-apple: this directly tests apple-only functions
2+
3+
fn main() {
4+
let mut bytes = [0u8; 24];
5+
let ret = unsafe { libc::CCRandomGenerateBytes(bytes.as_mut_ptr().cast(), bytes.len()) };
6+
assert_eq!(ret, libc::kCCSuccess);
7+
}

0 commit comments

Comments
 (0)