rand: freebsd update, using getrandom.

supported since the 12th release, while 11.4 is EOL since 2021.
This commit is contained in:
David CARLIER 2022-09-18 20:23:32 +01:00 committed by David Carlier
parent 7c306f6dcd
commit a7e0bab76b

View File

@ -16,7 +16,6 @@ pub fn hashmap_random_keys() -> (u64, u64) {
not(target_os = "ios"), not(target_os = "ios"),
not(target_os = "watchos"), not(target_os = "watchos"),
not(target_os = "openbsd"), not(target_os = "openbsd"),
not(target_os = "freebsd"),
not(target_os = "netbsd"), not(target_os = "netbsd"),
not(target_os = "fuchsia"), not(target_os = "fuchsia"),
not(target_os = "redox"), not(target_os = "redox"),
@ -65,11 +64,25 @@ mod imp {
unsafe { libc::getrandom(buf.as_mut_ptr().cast(), buf.len(), 0) } unsafe { libc::getrandom(buf.as_mut_ptr().cast(), buf.len(), 0) }
} }
#[cfg(target_os = "freebsd")]
fn getrandom(buf: &mut [u8]) -> libc::ssize_t {
// FIXME: using the above when libary std's libc is updated
extern "C" {
fn getrandom(
buffer: *mut libc::c_void,
length: libc::size_t,
flags: libc::c_uint,
) -> libc::ssize_t;
}
unsafe { getrandom(buf.as_mut_ptr().cast(), buf.len(), 0) }
}
#[cfg(not(any( #[cfg(not(any(
target_os = "linux", target_os = "linux",
target_os = "android", target_os = "android",
target_os = "espidf", target_os = "espidf",
target_os = "horizon" target_os = "horizon",
target_os = "freebsd"
)))] )))]
fn getrandom_fill_bytes(_buf: &mut [u8]) -> bool { fn getrandom_fill_bytes(_buf: &mut [u8]) -> bool {
false false
@ -79,7 +92,8 @@ mod imp {
target_os = "linux", target_os = "linux",
target_os = "android", target_os = "android",
target_os = "espidf", target_os = "espidf",
target_os = "horizon" target_os = "horizon",
target_os = "freebsd"
))] ))]
fn getrandom_fill_bytes(v: &mut [u8]) -> bool { fn getrandom_fill_bytes(v: &mut [u8]) -> bool {
use crate::sync::atomic::{AtomicBool, Ordering}; use crate::sync::atomic::{AtomicBool, Ordering};
@ -219,7 +233,7 @@ mod imp {
} }
} }
#[cfg(any(target_os = "freebsd", target_os = "netbsd"))] #[cfg(target_os = "netbsd")]
mod imp { mod imp {
use crate::ptr; use crate::ptr;