Skip to content

Commit

Permalink
macOs intercepting CCRandomGenerateBytes.
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen committed Feb 1, 2024
1 parent 4db61c9 commit 4e6237a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/shims/unix/macos/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
this.write_scalar(res, dest)?;
}

"CCRandomGenerateBytes" => {
let [buf, bufsize] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
let buf = this.read_pointer(buf)?;
let bufsize = this.read_target_usize(bufsize)?;
this.gen_random(buf, bufsize)?;
// returning 0 (kCCSuccess)
this.write_scalar(Scalar::from_i32(0), dest)?;
}

_ => return Ok(EmulateForeignItemResult::NotSupported),
};

Expand Down
11 changes: 11 additions & 0 deletions tests/pass-dep/shims/libc-ccrandomgeneratebytes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//@ignore-target-windows: no libc
//@ignore-target-linux: macOs only
//@ignore-target-freebsd: macOs only

fn main() {
let mut buf = [0u8; 1024];
unsafe {
assert_eq!(libc::CCRandomGenerateBytes(buf.as_mut_ptr() as *mut libc::c_void, buf.len()), libc::kCCSuccess);
}
}

0 comments on commit 4e6237a

Please sign in to comment.