diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d4965a49..b4e937e0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -316,6 +316,8 @@ jobs: run: cargo build -Z build-std=core --target=x86_64-wrs-vxworks - name: SOLID run: cargo build -Z build-std=core --target=aarch64-kmc-solid_asp3 + - name: Nintendo 3DS + run: cargo build -Z build-std=core --target=armv6k-nintendo-3ds clippy-fmt: name: Clippy + rustfmt diff --git a/Cargo.toml b/Cargo.toml index 3b42b760..b09a27d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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.64", default-features = false } +libc = { version = "0.2.120", default-features = false } [target.'cfg(target_os = "wasi")'.dependencies] wasi = "0.10" diff --git a/src/3ds.rs b/src/3ds.rs new file mode 100644 index 00000000..60305127 --- /dev/null +++ b/src/3ds.rs @@ -0,0 +1,17 @@ +// Copyright 2021 Developers of the Rand project. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Implementation for Nintendo 3DS +use crate::util_libc::sys_fill_exact; +use crate::Error; + +pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> { + sys_fill_exact(dest, |buf| unsafe { + libc::getrandom(buf.as_mut_ptr() as *mut libc::c_void, buf.len(), 0) + }) +} diff --git a/src/lib.rs b/src/lib.rs index 336c8ae1..b0ab0065 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,6 +33,7 @@ //! | Web Browser | `wasm32‑*‑unknown` | [`Crypto.getRandomValues()`][14], see [WebAssembly support][16] //! | Node.js | `wasm32‑*‑unknown` | [`crypto.randomBytes`][15], see [WebAssembly support][16] //! | SOLID | `*-kmc-solid_*` | `SOLID_RNG_SampleRandomBytes` +//! | Nintendo 3DS | `armv6k-nintendo-3ds` | [`getrandom`][1] //! //! There is no blanket implementation on `unix` targets that reads from //! `/dev/urandom`. This ensures all supported targets are using the recommended @@ -223,6 +224,11 @@ cfg_if! { } else if #[cfg(all(feature = "js", target_arch = "wasm32", target_os = "unknown"))] { #[path = "js.rs"] mod imp; + } else if #[cfg(all(target_os = "horizon", target_arch = "arm"))] { + // We check for target_arch = "arm" because the Nintendo Switch also + // uses Horizon OS (it is aarch64). + mod util_libc; + #[path = "3ds.rs"] mod imp; } else if #[cfg(feature = "custom")] { use custom as imp; } else if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { diff --git a/src/util_libc.rs b/src/util_libc.rs index 68236097..7e955b94 100644 --- a/src/util_libc.rs +++ b/src/util_libc.rs @@ -20,6 +20,12 @@ cfg_if! { use libc::__error as errno_location; } else if #[cfg(target_os = "haiku")] { use libc::_errnop 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 + fn __errno() -> *mut libc::c_int; + } + use __errno as errno_location; } }