From 1af049be06b5317dfbc0a499bfcade1240b63aa2 Mon Sep 17 00:00:00 2001 From: Nikolay Arhipov Date: Tue, 2 May 2023 13:39:25 +0300 Subject: [PATCH 1/3] Add support for PS Vita (armv7-sony-vita-newlibeabihf) --- src/lib.rs | 4 ++++ src/util_libc.rs | 2 +- src/vita.rs | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/vita.rs diff --git a/src/lib.rs b/src/lib.rs index 931856f7..e6d77249 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] +//! | PS Vita | `armv7-sony-vita-newlibeabihf` | [`getentropy`][13] //! | QNX Neutrino | `*‑nto-qnx*` | [`/dev/urandom`][14] (identical to `/dev/random`) //! | AIX | `*-ibm-aix` | [`/dev/urandom`][15] //! @@ -262,6 +263,9 @@ cfg_if! { // uses Horizon OS (it is aarch64). mod util_libc; #[path = "3ds.rs"] mod imp; + } else if #[cfg(target_os = "vita")] { + mod util_libc; + #[path = "vita.rs"] mod imp; } else if #[cfg(target_os = "emscripten")] { mod util_libc; #[path = "emscripten.rs"] mod imp; diff --git a/src/util_libc.rs b/src/util_libc.rs index de1455c5..4b94144d 100644 --- a/src/util_libc.rs +++ b/src/util_libc.rs @@ -29,7 +29,7 @@ cfg_if! { 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"))] { + } else if #[cfg(any(all(target_os = "horizon", target_arch = "arm"), target_os = "vita"))] { extern "C" { // Not provided by libc: https://github.com/rust-lang/libc/issues/1995 fn __errno() -> *mut libc::c_int; diff --git a/src/vita.rs b/src/vita.rs new file mode 100644 index 00000000..4f19b9cb --- /dev/null +++ b/src/vita.rs @@ -0,0 +1,21 @@ +// 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 PS Vita +use crate::{util_libc::last_os_error, Error}; +use core::mem::MaybeUninit; + +pub fn getrandom_inner(dest: &mut [MaybeUninit]) -> Result<(), Error> { + for chunk in dest.chunks_mut(256) { + let ret = unsafe { libc::getentropy(chunk.as_mut_ptr() as *mut libc::c_void, chunk.len()) }; + if ret == -1 { + return Err(last_os_error()); + } + } + Ok(()) +} From c04f7a16f19e62e29f38f8e14ccf463bab3f54cc Mon Sep 17 00:00:00 2001 From: Nikolay Arhipov Date: Tue, 2 May 2023 14:06:55 +0300 Subject: [PATCH 2/3] CI --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0c9f3f15..800a4361 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -297,6 +297,7 @@ jobs: x86_64-wrs-vxworks, aarch64-kmc-solid_asp3, armv6k-nintendo-3ds, + armv7-sony-vita-newlibeabihf, riscv32imc-esp-espidf, aarch64-unknown-nto-qnx710, # `std` support still in progress. Can be moved up with the other From 62b6fe413bc02e2aa390b02f7e192559b7fd06aa Mon Sep 17 00:00:00 2001 From: Nikolay Arhipov Date: Sat, 6 May 2023 20:14:10 +0300 Subject: [PATCH 3/3] Bumped libc --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 5622c323..6653f1e4 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.139", default-features = false } +libc = { version = "0.2.143", default-features = false } [target.'cfg(target_os = "wasi")'.dependencies] wasi = { version = "0.11", default-features = false }