Skip to content

Commit

Permalink
Add support for PS Vita (armv7-sony-vita-newlibeabihf) (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikarh authored May 7, 2023
1 parent 666b2d4 commit 53cf0cc
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
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.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 }
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
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]
//! | 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]
//!
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/util_libc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 21 additions & 0 deletions src/vita.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2021 Developers of the Rand project.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, 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<u8>]) -> 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(())
}

0 comments on commit 53cf0cc

Please sign in to comment.