diff options
| author | bors <bors@rust-lang.org> | 2023-10-06 05:52:07 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-10-06 05:52:07 +0000 |
| commit | f9003c08ab2e5d331ebd9285cc3a205d0b4c956c (patch) | |
| tree | 4bff245df198263fbb25ef452ac196aefc5dbb7f /src | |
| parent | 1a6ab015d00e36b974ef8bbde0e3b054e96b1e2d (diff) | |
| parent | dff7d5aa2f041f833901318ab8d301aeeb8ef06c (diff) | |
| download | rust-f9003c08ab2e5d331ebd9285cc3a205d0b4c956c.tar.gz rust-f9003c08ab2e5d331ebd9285cc3a205d0b4c956c.zip | |
Auto merge of #3098 - BlackHoleFox:apple-entropy, r=RalfJung
Support getentropy on macOS as a foreign item Prior this was always assumed to be accessed via `dlsym` shim, but in `std` I'm attempting to start [unconditionally linking](https://github.com/rust-lang/rust/pull/116319) to `getentropy` on macOS now that Rust's platform version support allows it. This just moves the main logic of the previous `dlsym` handler into an eval context extension so it can be used via both call paths. The `dlsym` handler is still needed as `getrandom` uses it.
Diffstat (limited to 'src')
| -rw-r--r-- | src/tools/miri/src/shims/unix/macos/dlsym.rs | 7 | ||||
| -rw-r--r-- | src/tools/miri/src/shims/unix/macos/foreign_items.rs | 23 |
2 files changed, 26 insertions, 4 deletions
diff --git a/src/tools/miri/src/shims/unix/macos/dlsym.rs b/src/tools/miri/src/shims/unix/macos/dlsym.rs index 63ad680de60..fa809452875 100644 --- a/src/tools/miri/src/shims/unix/macos/dlsym.rs +++ b/src/tools/miri/src/shims/unix/macos/dlsym.rs @@ -2,6 +2,7 @@ use rustc_middle::mir; use log::trace; +use super::foreign_items::EvalContextExt as _; use crate::*; use helpers::check_arg_count; @@ -38,10 +39,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { match dlsym { Dlsym::getentropy => { let [ptr, len] = check_arg_count(args)?; - let ptr = this.read_pointer(ptr)?; - let len = this.read_target_usize(len)?; - this.gen_random(ptr, len)?; - this.write_null(dest)?; + let result = this.getentropy(ptr, len)?; + this.write_scalar(result, dest)?; } } diff --git a/src/tools/miri/src/shims/unix/macos/foreign_items.rs b/src/tools/miri/src/shims/unix/macos/foreign_items.rs index 0ee3cea05d5..b514097c5df 100644 --- a/src/tools/miri/src/shims/unix/macos/foreign_items.rs +++ b/src/tools/miri/src/shims/unix/macos/foreign_items.rs @@ -109,6 +109,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { this.write_scalar(result, dest)?; } + // Random generation related shims + "getentropy" => { + let [buf, bufsize] = + this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; + let result = this.getentropy(buf, bufsize)?; + this.write_scalar(result, dest)?; + } + // Access to command-line arguments "_NSGetArgc" => { let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; @@ -198,4 +206,19 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { Ok(EmulateByNameResult::NeedsJumping) } + + fn getentropy( + &mut self, + buffer_op: &OpTy<'tcx, Provenance>, + length_op: &OpTy<'tcx, Provenance>, + ) -> InterpResult<'tcx, Scalar<Provenance>> { + let this = self.eval_context_mut(); + this.assert_target_os("macos", "getentropy"); + + let ptr = this.read_pointer(buffer_op)?; + let len = this.read_target_usize(length_op)?; + this.gen_random(ptr, len)?; + + Ok(Scalar::from_i32(0)) // KERN_SUCCESS + } } |
