Skip to content

Commit 0533425

Browse files
committed
Auto merge of #3164 - devnexen:fbsd_upd3, r=RalfJung
freebsd adding getrandom interception. note that os support was added in same time as getentropy.
2 parents 1bb84d2 + 2ef304c commit 0533425

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

ci.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ case $HOST_TARGET in
108108
MIRI_TEST_TARGET=aarch64-unknown-linux-gnu run_tests
109109
MIRI_TEST_TARGET=aarch64-apple-darwin run_tests
110110
MIRI_TEST_TARGET=i686-pc-windows-gnu run_tests
111-
MIRI_TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal hello integer vec panic/panic concurrency/simple pthreads libc-getentropy atomic env/var
111+
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
112112
MIRI_TEST_TARGET=aarch64-linux-android run_tests_minimal hello integer vec panic/panic
113113
MIRI_TEST_TARGET=wasm32-wasi run_tests_minimal no_std integer strings wasm
114114
MIRI_TEST_TARGET=wasm32-unknown-unknown run_tests_minimal no_std integer strings wasm

src/shims/unix/freebsd/foreign_items.rs

+15
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
4747
this.read_scalar(len)?,
4848
)?;
4949
}
50+
"getrandom" => {
51+
let [ptr, len, flags] =
52+
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
53+
let ptr = this.read_pointer(ptr)?;
54+
let len = this.read_target_usize(len)?;
55+
let _flags = this.read_scalar(flags)?.to_i32()?;
56+
// flags on freebsd does not really matter
57+
// in practice, GRND_RANDOM does not particularly draw from /dev/random
58+
// since it is the same as to /dev/urandom.
59+
// GRND_INSECURE is only an alias of GRND_NONBLOCK, which
60+
// does not affect the RNG.
61+
// https://man.freebsd.org/cgi/man.cgi?query=getrandom&sektion=2&n=1
62+
this.gen_random(ptr, len)?;
63+
this.write_scalar(Scalar::from_target_usize(len, this), dest)?;
64+
}
5065

5166
// errno
5267
"__error" => {

tests/pass-dep/shims/libc-getrandom.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
//@only-target-linux
1+
//@ignore-target-windows: no libc
2+
//@ignore-target-apple: no getrandom
23

34
use std::ptr;
45

56
fn main() {
67
let mut buf = [0u8; 5];
78
unsafe {
9+
#[cfg(target_os = "linux")]
810
assert_eq!(
911
libc::syscall(
1012
libc::SYS_getrandom,
@@ -14,6 +16,7 @@ fn main() {
1416
),
1517
0,
1618
);
19+
#[cfg(target_os = "linux")]
1720
assert_eq!(
1821
libc::syscall(
1922
libc::SYS_getrandom,

0 commit comments

Comments
 (0)