From b5f7e1b1ee3ed15d41a662cdab1bf77a71ffb2f0 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Tue, 17 Jan 2023 20:31:09 +0000 Subject: [PATCH] netbsd 10 adding getentropy/getrandom. --- libc-test/build.rs | 3 +++ libc-test/semver/netbsd.txt | 5 +++++ src/unix/bsd/netbsdlike/mod.rs | 1 + src/unix/bsd/netbsdlike/netbsd/mod.rs | 6 ++++++ src/unix/bsd/netbsdlike/openbsd/mod.rs | 1 - 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 602bb89ffbb85..5bad58171cf80 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1159,6 +1159,7 @@ fn test_netbsd(target: &str) { "MS_NOUSER" => true, "MS_RMT_MASK" => true, // updated in glibc 2.22 and musl 1.1.13 "BOTHER" => true, + "GRND_RANDOM" | "GRND_INSECURE" | "GRND_NONBLOCK" => true, // netbsd 10 minimum _ => false, } @@ -1168,6 +1169,8 @@ fn test_netbsd(target: &str) { match name { // FIXME: https://github.com/rust-lang/libc/issues/1272 "execv" | "execve" | "execvp" => true, + // FIXME: netbsd 10 minimum + "getentropy" | "getrandom" => true, "getrlimit" | "getrlimit64" | // non-int in 1st arg "setrlimit" | "setrlimit64" | // non-int in 1st arg diff --git a/libc-test/semver/netbsd.txt b/libc-test/semver/netbsd.txt index 71cd0d3a48cdc..bd60cdce3efea 100644 --- a/libc-test/semver/netbsd.txt +++ b/libc-test/semver/netbsd.txt @@ -396,6 +396,9 @@ GLOB_NOMATCH GLOB_NOSORT GLOB_NOSPACE GLOB_NOSYS +GRND_INSECURE +GRND_NONBLOCK +GRND_RANDOM HW_NCPU IFF_ALLMULTI IFF_BROADCAST @@ -1238,6 +1241,7 @@ getdiskrawname getdistcookedname getdomainname getdtablesize +getentropy getfsspecname getgrent getgrent_r @@ -1260,6 +1264,7 @@ getprogname getpwent getpwent_r getpwnam_r +getrandom getrlimit getrusage getservbyport diff --git a/src/unix/bsd/netbsdlike/mod.rs b/src/unix/bsd/netbsdlike/mod.rs index b71531c253db1..c43a4b9e8e4e3 100644 --- a/src/unix/bsd/netbsdlike/mod.rs +++ b/src/unix/bsd/netbsdlike/mod.rs @@ -746,6 +746,7 @@ extern "C" { pub fn dirname(path: *mut ::c_char) -> *mut ::c_char; pub fn basename(path: *mut ::c_char) -> *mut ::c_char; + pub fn getentropy(buf: *mut ::c_void, buflen: ::size_t) -> ::c_int; } cfg_if! { diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index 41f6b23d123ee..fec6ec3e45cd2 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -2321,6 +2321,11 @@ pub const XATTR_REPLACE: ::c_int = 0x02; // sys/extattr.h pub const EXTATTR_NAMESPACE_EMPTY: ::c_int = 0; +// For getrandom() +pub const GRND_NONBLOCK: ::c_uint = 0x1; +pub const GRND_RANDOM: ::c_uint = 0x2; +pub const GRND_INSECURE: ::c_uint = 0x4; + const_fn! { {const} fn _ALIGN(p: usize) -> usize { (p + _ALIGNBYTES) & !_ALIGNBYTES @@ -2870,6 +2875,7 @@ extern "C" { fd: ::c_int, newfd: ::c_int, ) -> ::c_int; + pub fn getrandom(buf: *mut ::c_void, buflen: ::size_t, flags: ::c_uint) -> ::ssize_t; } #[link(name = "util")] diff --git a/src/unix/bsd/netbsdlike/openbsd/mod.rs b/src/unix/bsd/netbsdlike/openbsd/mod.rs index daefde3fbc98e..63a7cdd983187 100644 --- a/src/unix/bsd/netbsdlike/openbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/openbsd/mod.rs @@ -1822,7 +1822,6 @@ extern "C" { newp: *mut ::c_void, newlen: ::size_t, ) -> ::c_int; - pub fn getentropy(buf: *mut ::c_void, buflen: ::size_t) -> ::c_int; pub fn setresgid(rgid: ::gid_t, egid: ::gid_t, sgid: ::gid_t) -> ::c_int; pub fn setresuid(ruid: ::uid_t, euid: ::uid_t, suid: ::uid_t) -> ::c_int; pub fn ptrace(request: ::c_int, pid: ::pid_t, addr: caddr_t, data: ::c_int) -> ::c_int;