Skip to content

Commit

Permalink
Auto merge of #3918 - devnexen:solaris_arc4random_buf, r=RalfJung
Browse files Browse the repository at this point in the history
implements arc4random_buf shim for freebsd/solarish platforms.

close #3914
  • Loading branch information
bors committed Sep 28, 2024
2 parents 5790eb9 + 7cb5a79 commit dd572c4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/tools/miri/ci/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ case $HOST_TARGET in
# Partially supported targets (tier 2)
BASIC="empty_main integer heap_alloc libc-mem vec string btreemap" # ensures we have the basics: pre-main code, system allocator
UNIX="hello panic/panic panic/unwind concurrency/simple atomic libc-mem libc-misc libc-random env num_cpus" # the things that are very similar across all Unixes, and hence easily supported there
TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal $BASIC $UNIX threadname pthread time fs
TEST_TARGET=i686-unknown-freebsd run_tests_minimal $BASIC $UNIX threadname pthread time fs
TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $BASIC $UNIX thread sync available-parallelism time tls
TEST_TARGET=x86_64-pc-solaris run_tests_minimal $BASIC $UNIX thread sync available-parallelism time tls
TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal $BASIC $UNIX hashmap random threadname pthread time fs
TEST_TARGET=i686-unknown-freebsd run_tests_minimal $BASIC $UNIX hashmap random threadname pthread time fs
TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $BASIC $UNIX hashmap thread sync available-parallelism time tls
TEST_TARGET=x86_64-pc-solaris run_tests_minimal $BASIC $UNIX hashmap thread sync available-parallelism time tls
TEST_TARGET=aarch64-linux-android run_tests_minimal $BASIC $UNIX hashmap pthread time --skip threadname
TEST_TARGET=wasm32-wasip2 run_tests_minimal $BASIC wasm
TEST_TARGET=wasm32-unknown-unknown run_tests_minimal no_std empty_main wasm # this target doesn't really have std
Expand Down
14 changes: 14 additions & 0 deletions src/tools/miri/src/shims/unix/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,20 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.gen_random(ptr, len)?;
this.write_scalar(Scalar::from_target_usize(len, this), dest)?;
}
"arc4random_buf" => {
// This function is non-standard but exists with the same signature and
// same behavior (eg never fails) on FreeBSD and Solaris/Illumos.
if !matches!(&*this.tcx.sess.target.os, "freebsd" | "illumos" | "solaris") {
throw_unsup_format!(
"`arc4random_buf` is not supported on {}",
this.tcx.sess.target.os
);
}
let [ptr, len] = this.check_shim(abi, Abi::C { unwind: false}, link_name, args)?;
let ptr = this.read_pointer(ptr)?;
let len = this.read_target_usize(len)?;
this.gen_random(ptr, len)?;
}
"_Unwind_RaiseException" => {
// This is not formally part of POSIX, but it is very wide-spread on POSIX systems.
// It was originally specified as part of the Itanium C++ ABI:
Expand Down
13 changes: 13 additions & 0 deletions src/tools/miri/tests/pass-dep/libc/libc-random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ fn main() {
test_getentropy();
#[cfg(not(target_os = "macos"))]
test_getrandom();
#[cfg(any(target_os = "freebsd", target_os = "illumos", target_os = "solaris"))]
test_arc4random_buf();
}

fn test_getentropy() {
Expand Down Expand Up @@ -61,3 +63,14 @@ fn test_getrandom() {
);
}
}

#[cfg(any(target_os = "freebsd", target_os = "illumos", target_os = "solaris"))]
fn test_arc4random_buf() {
// FIXME: Use declaration from libc once <https://github.com/rust-lang/libc/pull/3944> lands.
extern "C" {
fn arc4random_buf(buf: *mut libc::c_void, size: libc::size_t);
}
let mut buf = [0u8; 5];
unsafe { arc4random_buf(buf.as_mut_ptr() as _, buf.len()) };
assert!(buf != [0u8; 5]);
}

0 comments on commit dd572c4

Please sign in to comment.