From 8712807a288c32a0102a122e3bd1024065af1f01 Mon Sep 17 00:00:00 2001 From: joboet Date: Sun, 18 Aug 2024 15:08:39 +0200 Subject: [PATCH 1/2] miri: shim `CCRandomGenerateBytes` --- src/shims/unix/macos/foreign_items.rs | 10 ++++++++++ tests/pass-dep/libc/ccrandomgeneratebytes_apple.rs | 7 +++++++ 2 files changed, 17 insertions(+) create mode 100644 tests/pass-dep/libc/ccrandomgeneratebytes_apple.rs diff --git a/src/shims/unix/macos/foreign_items.rs b/src/shims/unix/macos/foreign_items.rs index 47b887dec9..95a4175205 100644 --- a/src/shims/unix/macos/foreign_items.rs +++ b/src/shims/unix/macos/foreign_items.rs @@ -78,6 +78,16 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { this.write_pointer(environ, dest)?; } + // Random data generation + "CCRandomGenerateBytes" => { + let [bytes, count] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; + let bytes = this.read_pointer(bytes)?; + let count = this.read_target_usize(count)?; + let success = this.eval_libc_i32("kCCSuccess"); + this.gen_random(bytes, count)?; + this.write_int(success, dest)?; + } + // Time related shims "mach_absolute_time" => { let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; diff --git a/tests/pass-dep/libc/ccrandomgeneratebytes_apple.rs b/tests/pass-dep/libc/ccrandomgeneratebytes_apple.rs new file mode 100644 index 0000000000..d06e8622ee --- /dev/null +++ b/tests/pass-dep/libc/ccrandomgeneratebytes_apple.rs @@ -0,0 +1,7 @@ +//@only-target-apple: this directly tests apple-only functions + +fn main() { + let mut bytes = [0u8; 24]; + let ret = unsafe { libc::CCRandomGenerateBytes(bytes.as_mut_ptr().cast(), bytes.len()) }; + assert_eq!(ret, libc::kCCSuccess); +} From 7136cc493d1ea075d7fb1fa4773bf5519e2f842f Mon Sep 17 00:00:00 2001 From: joboet Date: Sun, 22 Sep 2024 18:35:11 +0200 Subject: [PATCH 2/2] update miri test --- tests/pass-dep/libc/ccrandomgeneratebytes_apple.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pass-dep/libc/ccrandomgeneratebytes_apple.rs b/tests/pass-dep/libc/ccrandomgeneratebytes_apple.rs index d06e8622ee..afcc02bc83 100644 --- a/tests/pass-dep/libc/ccrandomgeneratebytes_apple.rs +++ b/tests/pass-dep/libc/ccrandomgeneratebytes_apple.rs @@ -1,4 +1,4 @@ -//@only-target-apple: this directly tests apple-only functions +//@only-target: apple # This directly tests apple-only functions fn main() { let mut bytes = [0u8; 24];