Skip to content

Commit 26d791b

Browse files
authored
Rollup merge of #101994 - devnexen:rand_fbsd_update, r=workingjubilee
rand: freebsd update, using getrandom. supported since the 12th release, while 11.4 is EOL since 2021.
2 parents 601a34d + a7e0bab commit 26d791b

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

library/std/src/sys/unix/rand.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ pub fn hashmap_random_keys() -> (u64, u64) {
1717
not(target_os = "tvos"),
1818
not(target_os = "watchos"),
1919
not(target_os = "openbsd"),
20-
not(target_os = "freebsd"),
2120
not(target_os = "netbsd"),
2221
not(target_os = "fuchsia"),
2322
not(target_os = "redox"),
@@ -68,11 +67,25 @@ mod imp {
6867
unsafe { libc::getrandom(buf.as_mut_ptr().cast(), buf.len(), 0) }
6968
}
7069

70+
#[cfg(target_os = "freebsd")]
71+
fn getrandom(buf: &mut [u8]) -> libc::ssize_t {
72+
// FIXME: using the above when libary std's libc is updated
73+
extern "C" {
74+
fn getrandom(
75+
buffer: *mut libc::c_void,
76+
length: libc::size_t,
77+
flags: libc::c_uint,
78+
) -> libc::ssize_t;
79+
}
80+
unsafe { getrandom(buf.as_mut_ptr().cast(), buf.len(), 0) }
81+
}
82+
7183
#[cfg(not(any(
7284
target_os = "linux",
7385
target_os = "android",
7486
target_os = "espidf",
75-
target_os = "horizon"
87+
target_os = "horizon",
88+
target_os = "freebsd"
7689
)))]
7790
fn getrandom_fill_bytes(_buf: &mut [u8]) -> bool {
7891
false
@@ -82,7 +95,8 @@ mod imp {
8295
target_os = "linux",
8396
target_os = "android",
8497
target_os = "espidf",
85-
target_os = "horizon"
98+
target_os = "horizon",
99+
target_os = "freebsd"
86100
))]
87101
fn getrandom_fill_bytes(v: &mut [u8]) -> bool {
88102
use crate::sync::atomic::{AtomicBool, Ordering};
@@ -222,7 +236,7 @@ mod imp {
222236
}
223237
}
224238

225-
#[cfg(any(target_os = "freebsd", target_os = "netbsd"))]
239+
#[cfg(target_os = "netbsd")]
226240
mod imp {
227241
use crate::ptr;
228242

0 commit comments

Comments
 (0)