Skip to content

Commit

Permalink
Merge pull request #325 from flba-eb/add_qnx_nto_support
Browse files Browse the repository at this point in the history
Add QNX/nto support
  • Loading branch information
josephlr committed Dec 24, 2022
2 parents 759a9d7 + 993505c commit beb65e2
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Expand Up @@ -294,6 +294,7 @@ jobs:
aarch64-kmc-solid_asp3,
armv6k-nintendo-3ds,
riscv32imc-esp-espidf,
aarch64-unknown-nto-qnx710,
# `std` support still in progress. Can be moved up with the other
# apple targets after https://github.com/rust-lang/rust/pull/103503
aarch64-apple-tvos,
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -18,7 +18,7 @@ compiler_builtins = { version = "0.1", optional = true }
core = { version = "1.0", optional = true, package = "rustc-std-workspace-core" }

[target.'cfg(unix)'.dependencies]
libc = { version = "0.2.136", default-features = false }
libc = { version = "0.2.139", default-features = false }

[target.'cfg(target_os = "wasi")'.dependencies]
wasi = { version = "0.11", default-features = false }
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Expand Up @@ -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`][14] (identical to `/dev/random`)
//!
//! There is no blanket implementation on `unix` targets that reads from
//! `/dev/urandom`. This ensures all supported targets are using the recommended
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"))] {
Expand Down
5 changes: 3 additions & 2 deletions src/use_file.rs
Expand Up @@ -21,7 +21,7 @@ use core::{
// We prefer using /dev/urandom and only use /dev/random if the OS
// documentation indicates that /dev/urandom is insecure.
// On Solaris/Illumos, see src/solaris_illumos.rs
// On Dragonfly, Haiku, and macOS, the devices are identical.
// On Dragonfly, Haiku, macOS, and QNX Neutrino the devices are identical.
#[cfg(any(target_os = "solaris", target_os = "illumos"))]
const FILE_PATH: &str = "/dev/random\0";
#[cfg(any(
Expand All @@ -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";

Expand Down
2 changes: 2 additions & 0 deletions src/util_libc.rs
Expand Up @@ -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
Expand Down

0 comments on commit beb65e2

Please sign in to comment.