Skip to content

Commit 53cf0cc

Browse files
authored
Add support for PS Vita (armv7-sony-vita-newlibeabihf) (#359)
1 parent 666b2d4 commit 53cf0cc

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

.github/workflows/tests.yml

+1
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ jobs:
297297
x86_64-wrs-vxworks,
298298
aarch64-kmc-solid_asp3,
299299
armv6k-nintendo-3ds,
300+
armv7-sony-vita-newlibeabihf,
300301
riscv32imc-esp-espidf,
301302
aarch64-unknown-nto-qnx710,
302303
# `std` support still in progress. Can be moved up with the other

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ compiler_builtins = { version = "0.1", optional = true }
1818
core = { version = "1.0", optional = true, package = "rustc-std-workspace-core" }
1919

2020
[target.'cfg(unix)'.dependencies]
21-
libc = { version = "0.2.139", default-features = false }
21+
libc = { version = "0.2.143", default-features = false }
2222

2323
[target.'cfg(target_os = "wasi")'.dependencies]
2424
wasi = { version = "0.11", default-features = false }

src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
//! | Web Browser and Node.js | `wasm*‑*‑unknown` | [`Crypto.getRandomValues`] if available, then [`crypto.randomFillSync`] if on Node.js, see [WebAssembly support]
3434
//! | SOLID | `*-kmc-solid_*` | `SOLID_RNG_SampleRandomBytes`
3535
//! | Nintendo 3DS | `armv6k-nintendo-3ds` | [`getrandom`][1]
36+
//! | PS Vita | `armv7-sony-vita-newlibeabihf` | [`getentropy`][13]
3637
//! | QNX Neutrino | `*‑nto-qnx*` | [`/dev/urandom`][14] (identical to `/dev/random`)
3738
//! | AIX | `*-ibm-aix` | [`/dev/urandom`][15]
3839
//!
@@ -262,6 +263,9 @@ cfg_if! {
262263
// uses Horizon OS (it is aarch64).
263264
mod util_libc;
264265
#[path = "3ds.rs"] mod imp;
266+
} else if #[cfg(target_os = "vita")] {
267+
mod util_libc;
268+
#[path = "vita.rs"] mod imp;
265269
} else if #[cfg(target_os = "emscripten")] {
266270
mod util_libc;
267271
#[path = "emscripten.rs"] mod imp;

src/util_libc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ cfg_if! {
2929
use libc::_errnop as errno_location;
3030
} else if #[cfg(target_os = "nto")] {
3131
use libc::__get_errno_ptr as errno_location;
32-
} else if #[cfg(all(target_os = "horizon", target_arch = "arm"))] {
32+
} else if #[cfg(any(all(target_os = "horizon", target_arch = "arm"), target_os = "vita"))] {
3333
extern "C" {
3434
// Not provided by libc: https://github.com/rust-lang/libc/issues/1995
3535
fn __errno() -> *mut libc::c_int;

src/vita.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2021 Developers of the Rand project.
2+
//
3+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4+
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5+
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6+
// option. This file may not be copied, modified, or distributed
7+
// except according to those terms.
8+
9+
//! Implementation for PS Vita
10+
use crate::{util_libc::last_os_error, Error};
11+
use core::mem::MaybeUninit;
12+
13+
pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
14+
for chunk in dest.chunks_mut(256) {
15+
let ret = unsafe { libc::getentropy(chunk.as_mut_ptr() as *mut libc::c_void, chunk.len()) };
16+
if ret == -1 {
17+
return Err(last_os_error());
18+
}
19+
}
20+
Ok(())
21+
}

0 commit comments

Comments
 (0)