Auto merge of #3164 - devnexen:fbsd_upd3, r=RalfJung

freebsd adding getrandom interception.

note that os support was added in same time as getentropy.
This commit is contained in:
bors 2023-11-15 21:47:54 +00:00
commit 012bd49b8a
3 changed files with 20 additions and 2 deletions

View File

@ -108,7 +108,7 @@ case $HOST_TARGET in
MIRI_TEST_TARGET=aarch64-unknown-linux-gnu run_tests
MIRI_TEST_TARGET=aarch64-apple-darwin run_tests
MIRI_TEST_TARGET=i686-pc-windows-gnu run_tests
MIRI_TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal hello integer vec panic/panic concurrency/simple pthreads libc-getentropy atomic env/var
MIRI_TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal hello integer vec panic/panic concurrency/simple pthreads libc-getentropy libc-getrandom atomic env/var
MIRI_TEST_TARGET=aarch64-linux-android run_tests_minimal hello integer vec panic/panic
MIRI_TEST_TARGET=wasm32-wasi run_tests_minimal no_std integer strings wasm
MIRI_TEST_TARGET=wasm32-unknown-unknown run_tests_minimal no_std integer strings wasm

View File

@ -47,6 +47,21 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
this.read_scalar(len)?,
)?;
}
"getrandom" => {
let [ptr, len, flags] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
let ptr = this.read_pointer(ptr)?;
let len = this.read_target_usize(len)?;
let _flags = this.read_scalar(flags)?.to_i32()?;
// flags on freebsd does not really matter
// in practice, GRND_RANDOM does not particularly draw from /dev/random
// since it is the same as to /dev/urandom.
// GRND_INSECURE is only an alias of GRND_NONBLOCK, which
// does not affect the RNG.
// https://man.freebsd.org/cgi/man.cgi?query=getrandom&sektion=2&n=1
this.gen_random(ptr, len)?;
this.write_scalar(Scalar::from_target_usize(len, this), dest)?;
}
// errno
"__error" => {

View File

@ -1,10 +1,12 @@
//@only-target-linux
//@ignore-target-windows: no libc
//@ignore-target-apple: no getrandom
use std::ptr;
fn main() {
let mut buf = [0u8; 5];
unsafe {
#[cfg(target_os = "linux")]
assert_eq!(
libc::syscall(
libc::SYS_getrandom,
@ -14,6 +16,7 @@ fn main() {
),
0,
);
#[cfg(target_os = "linux")]
assert_eq!(
libc::syscall(
libc::SYS_getrandom,