Skip to content

Commit 6e3bbde

Browse files
authored
Add support for getrandom syscall on NetBSD ≥ 10.0 (#331)
NetBSD supports the getrandom system call since version 10.0 [1]. Use it if available, otherwise fall back to kern.arandom like on FreeBSD. [1] https://man.netbsd.org/getrandom.2
1 parent 7f73e3c commit 6e3bbde

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/bsd_arandom.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn kern_arnd(buf: &mut [MaybeUninit<u8>]) -> libc::ssize_t {
3232

3333
pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
3434
// getrandom(2) was introduced in FreeBSD 12.0 and NetBSD 10.0
35-
#[cfg(target_os = "freebsd")]
35+
#[cfg(any(target_os = "freebsd", target_os = "netbsd"))]
3636
{
3737
use crate::util_libc::Weak;
3838
static GETRANDOM: Weak = unsafe { Weak::new("getrandom\0") };

src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//! | iOS, tvOS, watchOS | `*‑apple‑ios`, `*-apple-tvos`, `*-apple-watchos` | [`SecRandomCopyBytes`]
1919
//! | FreeBSD | `*‑freebsd` | [`getrandom`][5] if available, otherwise [`kern.arandom`][6]
2020
//! | OpenBSD | `*‑openbsd` | [`getentropy`][7]
21-
//! | NetBSD | `*‑netbsd` | [`kern.arandom`][8]
21+
//! | NetBSD | `*‑netbsd` | [`getrandom`][16] if available, otherwise [`kern.arandom`][8]
2222
//! | Dragonfly BSD | `*‑dragonfly` | [`getrandom`][9] if available, otherwise [`/dev/urandom`][10] (identical to `/dev/random`)
2323
//! | Solaris, illumos | `*‑solaris`, `*‑illumos` | [`getrandom`][11] if available, otherwise [`/dev/random`][12]
2424
//! | Fuchsia OS | `*‑fuchsia` | [`cprng_draw`]
@@ -164,6 +164,7 @@
164164
//! [13]: https://github.com/emscripten-core/emscripten/pull/12240
165165
//! [14]: https://www.qnx.com/developers/docs/7.1/index.html#com.qnx.doc.neutrino.utilities/topic/r/random.html
166166
//! [15]: https://www.ibm.com/docs/en/aix/7.3?topic=files-random-urandom-devices
167+
//! [16]: https://man.netbsd.org/getrandom.2
167168
//!
168169
//! [`BCryptGenRandom`]: https://docs.microsoft.com/en-us/windows/win32/api/bcrypt/nf-bcrypt-bcryptgenrandom
169170
//! [`Crypto.getRandomValues`]: https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues

0 commit comments

Comments
 (0)