std: enabling new netbsd (10) calls.

Introducing a new config for this purpose as NetBSD 9 or 8 will be still around
for a good while. For now, we re finally enabling sys::unix::rand::getrandom.
This commit is contained in:
David Carlier 2023-12-08 12:00:37 +00:00
parent 9aa232ecc7
commit 114b0c799d
3 changed files with 10 additions and 5 deletions

View File

@ -7,7 +7,9 @@ fn main() {
let target_vendor = let target_vendor =
env::var("CARGO_CFG_TARGET_VENDOR").expect("CARGO_CFG_TARGET_VENDOR was not set"); env::var("CARGO_CFG_TARGET_VENDOR").expect("CARGO_CFG_TARGET_VENDOR was not set");
let target_env = env::var("CARGO_CFG_TARGET_ENV").expect("CARGO_CFG_TARGET_ENV was not set"); let target_env = env::var("CARGO_CFG_TARGET_ENV").expect("CARGO_CFG_TARGET_ENV was not set");
if target_os == "netbsd" && env::var("RUSTC_STD_NETBSD10").is_ok() {
println!("cargo:rustc-cfg=netbsd10");
}
if target_os == "linux" if target_os == "linux"
|| target_os == "android" || target_os == "android"
|| target_os == "netbsd" || target_os == "netbsd"

View File

@ -62,7 +62,7 @@ fn getrandom(
unsafe { getrandom(buf.as_mut_ptr().cast(), buf.len(), libc::GRND_NONBLOCK) } unsafe { getrandom(buf.as_mut_ptr().cast(), buf.len(), libc::GRND_NONBLOCK) }
} }
#[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "freebsd"))] #[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "freebsd", netbsd10))]
fn getrandom(buf: &mut [u8]) -> libc::ssize_t { fn getrandom(buf: &mut [u8]) -> libc::ssize_t {
unsafe { libc::getrandom(buf.as_mut_ptr().cast(), buf.len(), 0) } unsafe { libc::getrandom(buf.as_mut_ptr().cast(), buf.len(), 0) }
} }
@ -72,7 +72,8 @@ fn getrandom(buf: &mut [u8]) -> libc::ssize_t {
target_os = "android", target_os = "android",
target_os = "espidf", target_os = "espidf",
target_os = "horizon", target_os = "horizon",
target_os = "freebsd" target_os = "freebsd",
netbsd10
)))] )))]
fn getrandom_fill_bytes(_buf: &mut [u8]) -> bool { fn getrandom_fill_bytes(_buf: &mut [u8]) -> bool {
false false
@ -83,7 +84,8 @@ fn getrandom_fill_bytes(_buf: &mut [u8]) -> bool {
target_os = "android", target_os = "android",
target_os = "espidf", target_os = "espidf",
target_os = "horizon", target_os = "horizon",
target_os = "freebsd" target_os = "freebsd",
netbsd10
))] ))]
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};
@ -230,7 +232,7 @@ pub fn fill_bytes(v: &mut [u8]) {
} }
// FIXME: once the 10.x release becomes the minimum, this can be dropped for simplification. // FIXME: once the 10.x release becomes the minimum, this can be dropped for simplification.
#[cfg(target_os = "netbsd")] #[cfg(all(target_os = "netbsd", not(netbsd10)))]
mod imp { mod imp {
use crate::ptr; use crate::ptr;

View File

@ -86,6 +86,7 @@
(Some(Mode::Std), "no_global_oom_handling", None), (Some(Mode::Std), "no_global_oom_handling", None),
(Some(Mode::Std), "no_rc", None), (Some(Mode::Std), "no_rc", None),
(Some(Mode::Std), "no_sync", None), (Some(Mode::Std), "no_sync", None),
(Some(Mode::Std), "netbsd10", None),
(Some(Mode::Std), "backtrace_in_libstd", None), (Some(Mode::Std), "backtrace_in_libstd", None),
/* Extra values not defined in the built-in targets yet, but used in std */ /* Extra values not defined in the built-in targets yet, but used in std */
(Some(Mode::Std), "target_env", Some(&["libnx"])), (Some(Mode::Std), "target_env", Some(&["libnx"])),