Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved std support for ps vita target #111819

Merged
merged 3 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1902,9 +1902,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"

[[package]]
name = "libc"
version = "0.2.143"
version = "0.2.146"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "edc207893e85c5d6be840e969b496b53d94cec8be2d501b214f50daa97fa8024"
checksum = "f92be4933c13fd498862a9e02a3055f8a8d9c039ce33db97306fd5a6caa7f29b"
dependencies = [
"rustc-std-workspace-core",
]
Expand Down
15 changes: 8 additions & 7 deletions compiler/rustc_target/src/spec/armv7_sony_vita_newlibeabihf.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
use crate::abi::Endian;
use crate::spec::{cvs, Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, TargetOptions};
use crate::spec::{cvs, Cc, LinkerFlavor, Lld, RelocModel, Target, TargetOptions};

/// A base target for PlayStation Vita devices using the VITASDK toolchain (using newlib).
///
/// Requires the VITASDK toolchain on the host system.

pub fn target() -> Target {
let pre_link_args = TargetOptions::link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-Wl,-q"]);
let pre_link_args = TargetOptions::link_args(
LinkerFlavor::Gnu(Cc::Yes, Lld::No),
&["-Wl,-q", "-Wl,--pic-veneer"],
);

Target {
llvm_target: "armv7a-vita-eabihf".into(),
llvm_target: "thumbv7a-vita-eabihf".into(),
pointer_width: 32,
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(),
arch: "arm".into(),
Expand All @@ -18,21 +21,19 @@ pub fn target() -> Target {
os: "vita".into(),
endian: Endian::Little,
c_int_width: "32".into(),
dynamic_linking: false,
env: "newlib".into(),
vendor: "sony".into(),
abi: "eabihf".into(),
linker_flavor: LinkerFlavor::Gnu(Cc::Yes, Lld::No),
no_default_libraries: false,
cpu: "cortex-a9".into(),
executables: true,
families: cvs!["unix"],
linker: Some("arm-vita-eabi-gcc".into()),
relocation_model: RelocModel::Static,
features: "+v7,+neon".into(),
features: "+v7,+neon,+vfp3,+thumb2,+thumb-mode".into(),
pre_link_args,
exe_suffix: ".elf".into(),
panic_strategy: PanicStrategy::Abort,
has_thumb_interworking: true,
max_atomic_width: Some(64),
..Default::default()
},
Expand Down
2 changes: 1 addition & 1 deletion library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
panic_unwind = { path = "../panic_unwind", optional = true }
panic_abort = { path = "../panic_abort" }
core = { path = "../core", public = true }
libc = { version = "0.2.143", default-features = false, features = ['rustc-dep-of-std'], public = true }
libc = { version = "0.2.146", default-features = false, features = ['rustc-dep-of-std'], public = true }
compiler_builtins = { version = "0.1.92" }
profiler_builtins = { path = "../profiler_builtins", optional = true }
unwind = { path = "../unwind" }
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/os/unix/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
use cfg_if::cfg_if;

cfg_if! {
if #[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon"))] {
if #[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon", target_os = "vita"))] {
type UserId = u16;
type GroupId = u16;
} else if #[cfg(target_os = "nto")] {
Expand Down
11 changes: 7 additions & 4 deletions library/std/src/sys/unix/fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,10 @@ impl FileDesc {
}
}
#[cfg(any(
all(target_env = "newlib", not(any(target_os = "espidf", target_os = "horizon"))),
all(
target_env = "newlib",
not(any(target_os = "espidf", target_os = "horizon", target_os = "vita"))
),
target_os = "solaris",
target_os = "illumos",
target_os = "emscripten",
Expand All @@ -424,10 +427,10 @@ impl FileDesc {
Ok(())
}
}
#[cfg(any(target_os = "espidf", target_os = "horizon"))]
#[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "vita"))]
pub fn set_cloexec(&self) -> io::Result<()> {
// FD_CLOEXEC is not supported in ESP-IDF and Horizon OS but there's no need to,
// because neither supports spawning processes.
// FD_CLOEXEC is not supported in ESP-IDF, Horizon OS and Vita but there's no need to,
// because none of them supports spawning processes.
Ok(())
}

Expand Down
37 changes: 34 additions & 3 deletions library/std/src/sys/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::mem;
target_os = "redox",
target_os = "illumos",
target_os = "nto",
target_os = "vita",
))]
use crate::mem::MaybeUninit;
use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd};
Expand Down Expand Up @@ -58,6 +59,7 @@ use libc::fstatat64;
target_os = "redox",
target_os = "illumos",
target_os = "nto",
target_os = "vita",
))]
use libc::readdir as readdir64;
#[cfg(target_os = "linux")]
Expand All @@ -74,6 +76,7 @@ use libc::readdir64_r;
target_os = "fuchsia",
target_os = "redox",
target_os = "nto",
target_os = "vita",
)))]
use libc::readdir_r as readdir64_r;
#[cfg(target_os = "android")]
Expand Down Expand Up @@ -283,6 +286,7 @@ unsafe impl Sync for Dir {}
target_os = "fuchsia",
target_os = "redox",
target_os = "nto",
target_os = "vita"
))]
pub struct DirEntry {
dir: Arc<InnerReadDir>,
Expand All @@ -304,10 +308,16 @@ pub struct DirEntry {
target_os = "fuchsia",
target_os = "redox",
target_os = "nto",
target_os = "vita",
))]
struct dirent64_min {
d_ino: u64,
#[cfg(not(any(target_os = "solaris", target_os = "illumos", target_os = "nto")))]
#[cfg(not(any(
target_os = "solaris",
target_os = "illumos",
target_os = "nto",
target_os = "vita"
)))]
d_type: u8,
}

Expand All @@ -319,6 +329,7 @@ struct dirent64_min {
target_os = "fuchsia",
target_os = "redox",
target_os = "nto",
target_os = "vita",
)))]
pub struct DirEntry {
dir: Arc<InnerReadDir>,
Expand Down Expand Up @@ -520,6 +531,7 @@ impl FileAttr {
target_os = "macos",
target_os = "ios",
target_os = "watchos",
target_os = "vita",
)))]
pub fn created(&self) -> io::Result<SystemTime> {
cfg_has_statx! {
Expand All @@ -541,6 +553,11 @@ impl FileAttr {
currently",
))
}

#[cfg(target_os = "vita")]
pub fn created(&self) -> io::Result<SystemTime> {
Ok(SystemTime::new(self.stat.st_ctime as i64, 0))
}
nikarh marked this conversation as resolved.
Show resolved Hide resolved
}

#[cfg(target_os = "nto")]
Expand Down Expand Up @@ -645,6 +662,7 @@ impl Iterator for ReadDir {
target_os = "redox",
target_os = "illumos",
target_os = "nto",
target_os = "vita",
))]
fn next(&mut self) -> Option<io::Result<DirEntry>> {
if self.end_of_stream {
Expand Down Expand Up @@ -725,6 +743,7 @@ impl Iterator for ReadDir {
continue;
}

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

#[cfg(target_os = "vita")]
let entry = dirent64_min { d_ino: 0u64 };

return Some(Ok(DirEntry {
entry,
name: name.to_owned(),
Expand All @@ -752,6 +774,7 @@ impl Iterator for ReadDir {
target_os = "redox",
target_os = "illumos",
target_os = "nto",
target_os = "vita",
)))]
fn next(&mut self) -> Option<io::Result<DirEntry>> {
if self.end_of_stream {
Expand Down Expand Up @@ -842,6 +865,7 @@ impl DirEntry {
target_os = "haiku",
target_os = "vxworks",
target_os = "nto",
target_os = "vita",
))]
pub fn file_type(&self) -> io::Result<FileType> {
self.metadata().map(|m| m.file_type())
Expand All @@ -853,6 +877,7 @@ impl DirEntry {
target_os = "haiku",
target_os = "vxworks",
target_os = "nto",
target_os = "vita",
)))]
pub fn file_type(&self) -> io::Result<FileType> {
match self.entry.d_type {
Expand Down Expand Up @@ -939,6 +964,7 @@ impl DirEntry {
target_os = "fuchsia",
target_os = "redox",
target_os = "nto",
target_os = "vita",
)))]
fn name_cstr(&self) -> &CStr {
unsafe { CStr::from_ptr(self.entry.d_name.as_ptr()) }
Expand All @@ -951,6 +977,7 @@ impl DirEntry {
target_os = "fuchsia",
target_os = "redox",
target_os = "nto",
target_os = "vita",
))]
fn name_cstr(&self) -> &CStr {
&self.name
Expand Down Expand Up @@ -1543,7 +1570,7 @@ pub fn link(original: &Path, link: &Path) -> io::Result<()> {
run_path_with_cstr(original, |original| {
run_path_with_cstr(link, |link| {
cfg_if::cfg_if! {
if #[cfg(any(target_os = "vxworks", target_os = "redox", target_os = "android", target_os = "espidf", target_os = "horizon"))] {
if #[cfg(any(target_os = "vxworks", target_os = "redox", target_os = "android", target_os = "espidf", target_os = "horizon", target_os = "vita"))] {
// VxWorks, Redox and ESP-IDF lack `linkat`, so use `link` instead. POSIX leaves
// it implementation-defined whether `link` follows symlinks, so rely on the
// `symlink_hard_link` test in library/std/src/fs/tests.rs to check the behavior.
Expand Down Expand Up @@ -1666,6 +1693,8 @@ fn open_to_and_set_permissions(
.truncate(true)
.open(to)?;
let writer_metadata = writer.metadata()?;
// fchmod is broken on vita
#[cfg(not(target_os = "vita"))]
if writer_metadata.is_file() {
// Set the correct file permissions, in case the file already existed.
// Don't set the permissions on already existing non-files like
Expand Down Expand Up @@ -1844,11 +1873,12 @@ pub fn chroot(dir: &Path) -> io::Result<()> {

pub use remove_dir_impl::remove_dir_all;

// Fallback for REDOX, ESP-ID, Horizon, and Miri
// Fallback for REDOX, ESP-ID, Horizon, Vita and Miri
#[cfg(any(
target_os = "redox",
target_os = "espidf",
target_os = "horizon",
target_os = "vita",
target_os = "nto",
miri
))]
Expand All @@ -1861,6 +1891,7 @@ mod remove_dir_impl {
target_os = "redox",
target_os = "espidf",
target_os = "horizon",
target_os = "vita",
target_os = "nto",
miri
)))]
Expand Down
12 changes: 4 additions & 8 deletions library/std/src/sys/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,7 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
}

unsafe fn reset_sigpipe(#[allow(unused_variables)] sigpipe: u8) {
#[cfg(not(any(
target_os = "emscripten",
target_os = "fuchsia",
target_os = "horizon",
target_os = "vita"
)))]
#[cfg(not(any(target_os = "emscripten", target_os = "fuchsia", target_os = "horizon")))]
{
// We don't want to add this as a public type to std, nor do we
// want to `include!` a file from the compiler (which would break
Expand Down Expand Up @@ -206,7 +201,6 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
target_os = "emscripten",
target_os = "fuchsia",
target_os = "horizon",
target_os = "vita"
)))]
static UNIX_SIGPIPE_ATTR_SPECIFIED: crate::sync::atomic::AtomicBool =
crate::sync::atomic::AtomicBool::new(false);
Expand All @@ -216,7 +210,6 @@ static UNIX_SIGPIPE_ATTR_SPECIFIED: crate::sync::atomic::AtomicBool =
target_os = "emscripten",
target_os = "fuchsia",
target_os = "horizon",
target_os = "vita",
)))]
pub(crate) fn unix_sigpipe_attr_specified() -> bool {
UNIX_SIGPIPE_ATTR_SPECIFIED.load(crate::sync::atomic::Ordering::Relaxed)
Expand Down Expand Up @@ -407,6 +400,9 @@ cfg_if::cfg_if! {
} else if #[cfg(all(target_os = "linux", target_env = "uclibc"))] {
#[link(name = "dl")]
extern "C" {}
} else if #[cfg(target_os = "vita")] {
#[link(name = "pthread", kind = "static", modifiers = "-bundle")]
extern "C" {}
}
}

Expand Down
8 changes: 7 additions & 1 deletion library/std/src/sys/unix/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,12 +454,18 @@ impl Socket {
Ok(passcred != 0)
}

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

#[cfg(target_os = "vita")]
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
let option = nonblocking as libc::c_int;
setsockopt(self, libc::SOL_SOCKET, libc::SO_NONBLOCK, option)
}

#[cfg(any(target_os = "solaris", target_os = "illumos"))]
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
// FIONBIO is inadequate for sockets on illumos/Solaris, so use the
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/sys/unix/thread_parking/pthread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ impl Parker {
target_os = "watchos",
target_os = "l4re",
target_os = "android",
target_os = "redox"
target_os = "redox",
target_os = "vita",
))] {
addr_of_mut!((*parker).cvar).write(UnsafeCell::new(libc::PTHREAD_COND_INITIALIZER));
} else if #[cfg(any(target_os = "espidf", target_os = "horizon"))] {
Expand Down
Loading