From d1b6093b56a9684e5b23183888119b3b41fe794e Mon Sep 17 00:00:00 2001 From: Florian Bartels Date: Tue, 12 Jul 2022 10:57:40 +0200 Subject: [PATCH] Add QNX/nto support --- src/lib.rs | 4 +++- src/use_file.rs | 3 ++- src/util_libc.rs | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 39262580..cf36c1f4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,6 +33,7 @@ //! | Web Browser and Node.js | `wasm*‑*‑unknown` | [`Crypto.getRandomValues`] if available, then [`crypto.randomFillSync`] if on Node.js, see [WebAssembly support] //! | SOLID | `*-kmc-solid_*` | `SOLID_RNG_SampleRandomBytes` //! | Nintendo 3DS | `armv6k-nintendo-3ds` | [`getrandom`][1] +//! | QNX Neutrino | `*‑nto-qnx*` | `/dev/urandom` [Random on QNX][14] //! //! There is no blanket implementation on `unix` targets that reads from //! `/dev/urandom`. This ensures all supported targets are using the recommended @@ -160,6 +161,7 @@ //! [11]: https://docs.oracle.com/cd/E88353_01/html/E37841/getrandom-2.html //! [12]: https://docs.oracle.com/cd/E86824_01/html/E54777/random-7d.html //! [13]: https://github.com/emscripten-core/emscripten/pull/12240 +//! [14]: https://www.qnx.com/developers/docs/7.1/index.html#com.qnx.doc.neutrino.utilities/topic/r/random.html //! //! [`BCryptGenRandom`]: https://docs.microsoft.com/en-us/windows/win32/api/bcrypt/nf-bcrypt-bcryptgenrandom //! [`Crypto.getRandomValues`]: https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues @@ -209,7 +211,7 @@ pub use crate::error::Error; // The function MUST NOT ever write uninitialized bytes into `dest`, // regardless of what value it returns. cfg_if! { - if #[cfg(any(target_os = "haiku", target_os = "redox"))] { + if #[cfg(any(target_os = "haiku", target_os = "redox", target_os = "nto"))] { mod util_libc; #[path = "use_file.rs"] mod imp; } else if #[cfg(any(target_os = "android", target_os = "linux"))] { diff --git a/src/use_file.rs b/src/use_file.rs index facd8fad..f9f56c3c 100644 --- a/src/use_file.rs +++ b/src/use_file.rs @@ -30,7 +30,8 @@ const FILE_PATH: &str = "/dev/random\0"; target_os = "redox", target_os = "dragonfly", target_os = "haiku", - target_os = "macos" + target_os = "macos", + target_os = "nto", ))] const FILE_PATH: &str = "/dev/urandom\0"; diff --git a/src/util_libc.rs b/src/util_libc.rs index 6c80b3fe..65207fc6 100644 --- a/src/util_libc.rs +++ b/src/util_libc.rs @@ -26,6 +26,8 @@ cfg_if! { use libc::__error as errno_location; } else if #[cfg(target_os = "haiku")] { use libc::_errnop as errno_location; + } else if #[cfg(target_os = "nto")] { + use libc::__get_errno_ptr as errno_location; } else if #[cfg(all(target_os = "horizon", target_arch = "arm"))] { extern "C" { // Not provided by libc: https://github.com/rust-lang/libc/issues/1995