Skip to content

Commit b3dd578

Browse files
committed
Auto merge of #111819 - nikarh:vita-improved, r=Amanieu
Improved std support for ps vita target Fixed a couple of things in std support for ps vita via Vita SDK newlib oss implementation: - Added missing hardware features to target spec - Compile in thumb by default (newlib is also compiled in thumb) - Fixed fs calls. Vita newlib has a not-very-posix dirent. Also vita does not expose inodes, it's stubbed as 0 in stat, and I'm stubbing it here for dirent (because vita newlibs's dirent doesn't even have that field) - Enabled signal handlers for panic unwinding - Dropped static link requirement from the platform support md. Also, rearranged sections to better stick with the template.
2 parents 7b28a6b + 032857e commit b3dd578

File tree

10 files changed

+81
-88
lines changed

10 files changed

+81
-88
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -1902,9 +1902,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
19021902

19031903
[[package]]
19041904
name = "libc"
1905-
version = "0.2.143"
1905+
version = "0.2.146"
19061906
source = "registry+https://github.com/rust-lang/crates.io-index"
1907-
checksum = "edc207893e85c5d6be840e969b496b53d94cec8be2d501b214f50daa97fa8024"
1907+
checksum = "f92be4933c13fd498862a9e02a3055f8a8d9c039ce33db97306fd5a6caa7f29b"
19081908
dependencies = [
19091909
"rustc-std-workspace-core",
19101910
]

compiler/rustc_target/src/spec/armv7_sony_vita_newlibeabihf.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
use crate::abi::Endian;
2-
use crate::spec::{cvs, Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, TargetOptions};
2+
use crate::spec::{cvs, Cc, LinkerFlavor, Lld, RelocModel, Target, TargetOptions};
33

44
/// A base target for PlayStation Vita devices using the VITASDK toolchain (using newlib).
55
///
66
/// Requires the VITASDK toolchain on the host system.
77
88
pub fn target() -> Target {
9-
let pre_link_args = TargetOptions::link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-Wl,-q"]);
9+
let pre_link_args = TargetOptions::link_args(
10+
LinkerFlavor::Gnu(Cc::Yes, Lld::No),
11+
&["-Wl,-q", "-Wl,--pic-veneer"],
12+
);
1013

1114
Target {
12-
llvm_target: "armv7a-vita-eabihf".into(),
15+
llvm_target: "thumbv7a-vita-eabihf".into(),
1316
pointer_width: 32,
1417
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(),
1518
arch: "arm".into(),
@@ -18,21 +21,19 @@ pub fn target() -> Target {
1821
os: "vita".into(),
1922
endian: Endian::Little,
2023
c_int_width: "32".into(),
21-
dynamic_linking: false,
2224
env: "newlib".into(),
2325
vendor: "sony".into(),
2426
abi: "eabihf".into(),
2527
linker_flavor: LinkerFlavor::Gnu(Cc::Yes, Lld::No),
2628
no_default_libraries: false,
2729
cpu: "cortex-a9".into(),
28-
executables: true,
2930
families: cvs!["unix"],
3031
linker: Some("arm-vita-eabi-gcc".into()),
3132
relocation_model: RelocModel::Static,
32-
features: "+v7,+neon".into(),
33+
features: "+v7,+neon,+vfp3,+thumb2,+thumb-mode".into(),
3334
pre_link_args,
3435
exe_suffix: ".elf".into(),
35-
panic_strategy: PanicStrategy::Abort,
36+
has_thumb_interworking: true,
3637
max_atomic_width: Some(64),
3738
..Default::default()
3839
},

library/std/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
1717
panic_unwind = { path = "../panic_unwind", optional = true }
1818
panic_abort = { path = "../panic_abort" }
1919
core = { path = "../core", public = true }
20-
libc = { version = "0.2.143", default-features = false, features = ['rustc-dep-of-std'], public = true }
20+
libc = { version = "0.2.146", default-features = false, features = ['rustc-dep-of-std'], public = true }
2121
compiler_builtins = { version = "0.1.92" }
2222
profiler_builtins = { path = "../profiler_builtins", optional = true }
2323
unwind = { path = "../unwind" }

library/std/src/os/unix/process.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
1515
use cfg_if::cfg_if;
1616

1717
cfg_if! {
18-
if #[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon"))] {
18+
if #[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon", target_os = "vita"))] {
1919
type UserId = u16;
2020
type GroupId = u16;
2121
} else if #[cfg(target_os = "nto")] {

library/std/src/sys/unix/fd.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,10 @@ impl FileDesc {
402402
}
403403
}
404404
#[cfg(any(
405-
all(target_env = "newlib", not(any(target_os = "espidf", target_os = "horizon"))),
405+
all(
406+
target_env = "newlib",
407+
not(any(target_os = "espidf", target_os = "horizon", target_os = "vita"))
408+
),
406409
target_os = "solaris",
407410
target_os = "illumos",
408411
target_os = "emscripten",
@@ -424,10 +427,10 @@ impl FileDesc {
424427
Ok(())
425428
}
426429
}
427-
#[cfg(any(target_os = "espidf", target_os = "horizon"))]
430+
#[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "vita"))]
428431
pub fn set_cloexec(&self) -> io::Result<()> {
429-
// FD_CLOEXEC is not supported in ESP-IDF and Horizon OS but there's no need to,
430-
// because neither supports spawning processes.
432+
// FD_CLOEXEC is not supported in ESP-IDF, Horizon OS and Vita but there's no need to,
433+
// because none of them supports spawning processes.
431434
Ok(())
432435
}
433436

library/std/src/sys/unix/fs.rs

+34-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::mem;
1515
target_os = "redox",
1616
target_os = "illumos",
1717
target_os = "nto",
18+
target_os = "vita",
1819
))]
1920
use crate::mem::MaybeUninit;
2021
use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd};
@@ -58,6 +59,7 @@ use libc::fstatat64;
5859
target_os = "redox",
5960
target_os = "illumos",
6061
target_os = "nto",
62+
target_os = "vita",
6163
))]
6264
use libc::readdir as readdir64;
6365
#[cfg(target_os = "linux")]
@@ -74,6 +76,7 @@ use libc::readdir64_r;
7476
target_os = "fuchsia",
7577
target_os = "redox",
7678
target_os = "nto",
79+
target_os = "vita",
7780
)))]
7881
use libc::readdir_r as readdir64_r;
7982
#[cfg(target_os = "android")]
@@ -283,6 +286,7 @@ unsafe impl Sync for Dir {}
283286
target_os = "fuchsia",
284287
target_os = "redox",
285288
target_os = "nto",
289+
target_os = "vita"
286290
))]
287291
pub struct DirEntry {
288292
dir: Arc<InnerReadDir>,
@@ -304,10 +308,16 @@ pub struct DirEntry {
304308
target_os = "fuchsia",
305309
target_os = "redox",
306310
target_os = "nto",
311+
target_os = "vita",
307312
))]
308313
struct dirent64_min {
309314
d_ino: u64,
310-
#[cfg(not(any(target_os = "solaris", target_os = "illumos", target_os = "nto")))]
315+
#[cfg(not(any(
316+
target_os = "solaris",
317+
target_os = "illumos",
318+
target_os = "nto",
319+
target_os = "vita"
320+
)))]
311321
d_type: u8,
312322
}
313323

@@ -319,6 +329,7 @@ struct dirent64_min {
319329
target_os = "fuchsia",
320330
target_os = "redox",
321331
target_os = "nto",
332+
target_os = "vita",
322333
)))]
323334
pub struct DirEntry {
324335
dir: Arc<InnerReadDir>,
@@ -520,6 +531,7 @@ impl FileAttr {
520531
target_os = "macos",
521532
target_os = "ios",
522533
target_os = "watchos",
534+
target_os = "vita",
523535
)))]
524536
pub fn created(&self) -> io::Result<SystemTime> {
525537
cfg_has_statx! {
@@ -541,6 +553,11 @@ impl FileAttr {
541553
currently",
542554
))
543555
}
556+
557+
#[cfg(target_os = "vita")]
558+
pub fn created(&self) -> io::Result<SystemTime> {
559+
Ok(SystemTime::new(self.stat.st_ctime as i64, 0))
560+
}
544561
}
545562

546563
#[cfg(target_os = "nto")]
@@ -645,6 +662,7 @@ impl Iterator for ReadDir {
645662
target_os = "redox",
646663
target_os = "illumos",
647664
target_os = "nto",
665+
target_os = "vita",
648666
))]
649667
fn next(&mut self) -> Option<io::Result<DirEntry>> {
650668
if self.end_of_stream {
@@ -725,6 +743,7 @@ impl Iterator for ReadDir {
725743
continue;
726744
}
727745

746+
#[cfg(not(target_os = "vita"))]
728747
let entry = dirent64_min {
729748
d_ino: *offset_ptr!(entry_ptr, d_ino) as u64,
730749
#[cfg(not(any(
@@ -735,6 +754,9 @@ impl Iterator for ReadDir {
735754
d_type: *offset_ptr!(entry_ptr, d_type) as u8,
736755
};
737756

757+
#[cfg(target_os = "vita")]
758+
let entry = dirent64_min { d_ino: 0u64 };
759+
738760
return Some(Ok(DirEntry {
739761
entry,
740762
name: name.to_owned(),
@@ -752,6 +774,7 @@ impl Iterator for ReadDir {
752774
target_os = "redox",
753775
target_os = "illumos",
754776
target_os = "nto",
777+
target_os = "vita",
755778
)))]
756779
fn next(&mut self) -> Option<io::Result<DirEntry>> {
757780
if self.end_of_stream {
@@ -842,6 +865,7 @@ impl DirEntry {
842865
target_os = "haiku",
843866
target_os = "vxworks",
844867
target_os = "nto",
868+
target_os = "vita",
845869
))]
846870
pub fn file_type(&self) -> io::Result<FileType> {
847871
self.metadata().map(|m| m.file_type())
@@ -853,6 +877,7 @@ impl DirEntry {
853877
target_os = "haiku",
854878
target_os = "vxworks",
855879
target_os = "nto",
880+
target_os = "vita",
856881
)))]
857882
pub fn file_type(&self) -> io::Result<FileType> {
858883
match self.entry.d_type {
@@ -939,6 +964,7 @@ impl DirEntry {
939964
target_os = "fuchsia",
940965
target_os = "redox",
941966
target_os = "nto",
967+
target_os = "vita",
942968
)))]
943969
fn name_cstr(&self) -> &CStr {
944970
unsafe { CStr::from_ptr(self.entry.d_name.as_ptr()) }
@@ -951,6 +977,7 @@ impl DirEntry {
951977
target_os = "fuchsia",
952978
target_os = "redox",
953979
target_os = "nto",
980+
target_os = "vita",
954981
))]
955982
fn name_cstr(&self) -> &CStr {
956983
&self.name
@@ -1543,7 +1570,7 @@ pub fn link(original: &Path, link: &Path) -> io::Result<()> {
15431570
run_path_with_cstr(original, |original| {
15441571
run_path_with_cstr(link, |link| {
15451572
cfg_if::cfg_if! {
1546-
if #[cfg(any(target_os = "vxworks", target_os = "redox", target_os = "android", target_os = "espidf", target_os = "horizon"))] {
1573+
if #[cfg(any(target_os = "vxworks", target_os = "redox", target_os = "android", target_os = "espidf", target_os = "horizon", target_os = "vita"))] {
15471574
// VxWorks, Redox and ESP-IDF lack `linkat`, so use `link` instead. POSIX leaves
15481575
// it implementation-defined whether `link` follows symlinks, so rely on the
15491576
// `symlink_hard_link` test in library/std/src/fs/tests.rs to check the behavior.
@@ -1666,6 +1693,8 @@ fn open_to_and_set_permissions(
16661693
.truncate(true)
16671694
.open(to)?;
16681695
let writer_metadata = writer.metadata()?;
1696+
// fchmod is broken on vita
1697+
#[cfg(not(target_os = "vita"))]
16691698
if writer_metadata.is_file() {
16701699
// Set the correct file permissions, in case the file already existed.
16711700
// Don't set the permissions on already existing non-files like
@@ -1844,11 +1873,12 @@ pub fn chroot(dir: &Path) -> io::Result<()> {
18441873

18451874
pub use remove_dir_impl::remove_dir_all;
18461875

1847-
// Fallback for REDOX, ESP-ID, Horizon, and Miri
1876+
// Fallback for REDOX, ESP-ID, Horizon, Vita and Miri
18481877
#[cfg(any(
18491878
target_os = "redox",
18501879
target_os = "espidf",
18511880
target_os = "horizon",
1881+
target_os = "vita",
18521882
target_os = "nto",
18531883
miri
18541884
))]
@@ -1861,6 +1891,7 @@ mod remove_dir_impl {
18611891
target_os = "redox",
18621892
target_os = "espidf",
18631893
target_os = "horizon",
1894+
target_os = "vita",
18641895
target_os = "nto",
18651896
miri
18661897
)))]

library/std/src/sys/unix/mod.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,7 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
163163
}
164164

165165
unsafe fn reset_sigpipe(#[allow(unused_variables)] sigpipe: u8) {
166-
#[cfg(not(any(
167-
target_os = "emscripten",
168-
target_os = "fuchsia",
169-
target_os = "horizon",
170-
target_os = "vita"
171-
)))]
166+
#[cfg(not(any(target_os = "emscripten", target_os = "fuchsia", target_os = "horizon")))]
172167
{
173168
// We don't want to add this as a public type to std, nor do we
174169
// want to `include!` a file from the compiler (which would break
@@ -206,7 +201,6 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
206201
target_os = "emscripten",
207202
target_os = "fuchsia",
208203
target_os = "horizon",
209-
target_os = "vita"
210204
)))]
211205
static UNIX_SIGPIPE_ATTR_SPECIFIED: crate::sync::atomic::AtomicBool =
212206
crate::sync::atomic::AtomicBool::new(false);
@@ -216,7 +210,6 @@ static UNIX_SIGPIPE_ATTR_SPECIFIED: crate::sync::atomic::AtomicBool =
216210
target_os = "emscripten",
217211
target_os = "fuchsia",
218212
target_os = "horizon",
219-
target_os = "vita",
220213
)))]
221214
pub(crate) fn unix_sigpipe_attr_specified() -> bool {
222215
UNIX_SIGPIPE_ATTR_SPECIFIED.load(crate::sync::atomic::Ordering::Relaxed)
@@ -407,6 +400,9 @@ cfg_if::cfg_if! {
407400
} else if #[cfg(all(target_os = "linux", target_env = "uclibc"))] {
408401
#[link(name = "dl")]
409402
extern "C" {}
403+
} else if #[cfg(target_os = "vita")] {
404+
#[link(name = "pthread", kind = "static", modifiers = "-bundle")]
405+
extern "C" {}
410406
}
411407
}
412408

library/std/src/sys/unix/net.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -454,12 +454,18 @@ impl Socket {
454454
Ok(passcred != 0)
455455
}
456456

457-
#[cfg(not(any(target_os = "solaris", target_os = "illumos")))]
457+
#[cfg(not(any(target_os = "solaris", target_os = "illumos", target_os = "vita")))]
458458
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
459459
let mut nonblocking = nonblocking as libc::c_int;
460460
cvt(unsafe { libc::ioctl(self.as_raw_fd(), libc::FIONBIO, &mut nonblocking) }).map(drop)
461461
}
462462

463+
#[cfg(target_os = "vita")]
464+
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
465+
let option = nonblocking as libc::c_int;
466+
setsockopt(self, libc::SOL_SOCKET, libc::SO_NONBLOCK, option)
467+
}
468+
463469
#[cfg(any(target_os = "solaris", target_os = "illumos"))]
464470
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
465471
// FIONBIO is inadequate for sockets on illumos/Solaris, so use the

library/std/src/sys/unix/thread_parking/pthread.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ impl Parker {
123123
target_os = "watchos",
124124
target_os = "l4re",
125125
target_os = "android",
126-
target_os = "redox"
126+
target_os = "redox",
127+
target_os = "vita",
127128
))] {
128129
addr_of_mut!((*parker).cvar).write(UnsafeCell::new(libc::PTHREAD_COND_INITIALIZER));
129130
} else if #[cfg(any(target_os = "espidf", target_os = "horizon"))] {

0 commit comments

Comments
 (0)