about summary refs log tree commit diff
path: root/library/std/src
diff options
context:
space:
mode:
authorNikolay Arhipov <n@arhipov.net>2023-06-04 17:44:43 +0300
committerNikolay Arhipov <n@arhipov.net>2023-06-05 19:14:09 +0300
commit50117af409ada03f7ee895c12e0009060f8ba4c1 (patch)
tree83a8eaa50c78ef150caa34043a58788918722b94 /library/std/src
parent7452822843cf461b56742f0fc648af35889a3070 (diff)
downloadrust-50117af409ada03f7ee895c12e0009060f8ba4c1.tar.gz
rust-50117af409ada03f7ee895c12e0009060f8ba4c1.zip
Std support improvement for ps vita target
Diffstat (limited to 'library/std/src')
-rw-r--r--library/std/src/os/unix/process.rs2
-rw-r--r--library/std/src/sys/unix/fd.rs11
-rw-r--r--library/std/src/sys/unix/fs.rs37
-rw-r--r--library/std/src/sys/unix/mod.rs12
-rw-r--r--library/std/src/sys/unix/net.rs11
-rw-r--r--library/std/src/sys/unix/thread_parking/pthread.rs3
6 files changed, 58 insertions, 18 deletions
diff --git a/library/std/src/os/unix/process.rs b/library/std/src/os/unix/process.rs
index 729c63d184f..2b40b672d9f 100644
--- a/library/std/src/os/unix/process.rs
+++ b/library/std/src/os/unix/process.rs
@@ -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")] {
diff --git a/library/std/src/sys/unix/fd.rs b/library/std/src/sys/unix/fd.rs
index cb630eede6d..69c93c92003 100644
--- a/library/std/src/sys/unix/fd.rs
+++ b/library/std/src/sys/unix/fd.rs
@@ -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",
@@ -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(())
     }
 
diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs
index 0e5691d40d1..d2fb6238387 100644
--- a/library/std/src/sys/unix/fs.rs
+++ b/library/std/src/sys/unix/fs.rs
@@ -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};
@@ -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")]
@@ -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")]
@@ -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>,
@@ -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,
 }
 
@@ -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>,
@@ -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! {
@@ -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))
+    }
 }
 
 #[cfg(target_os = "nto")]
@@ -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 {
@@ -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(
@@ -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(),
@@ -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 {
@@ -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())
@@ -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 {
@@ -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()) }
@@ -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
@@ -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.
@@ -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
@@ -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
 ))]
@@ -1861,6 +1891,7 @@ mod remove_dir_impl {
     target_os = "redox",
     target_os = "espidf",
     target_os = "horizon",
+    target_os = "vita",
     target_os = "nto",
     miri
 )))]
diff --git a/library/std/src/sys/unix/mod.rs b/library/std/src/sys/unix/mod.rs
index 54e2f20b317..24566d96bcd 100644
--- a/library/std/src/sys/unix/mod.rs
+++ b/library/std/src/sys/unix/mod.rs
@@ -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
@@ -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);
@@ -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)
@@ -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" {}
     }
 }
 
diff --git a/library/std/src/sys/unix/net.rs b/library/std/src/sys/unix/net.rs
index 39edb136c24..ca80cabc3b0 100644
--- a/library/std/src/sys/unix/net.rs
+++ b/library/std/src/sys/unix/net.rs
@@ -454,12 +454,21 @@ 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 = match nonblocking {
+            true => 1,
+            false => 0,
+        };
+        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
diff --git a/library/std/src/sys/unix/thread_parking/pthread.rs b/library/std/src/sys/unix/thread_parking/pthread.rs
index 43046ed07b8..8bf4bae7a3f 100644
--- a/library/std/src/sys/unix/thread_parking/pthread.rs
+++ b/library/std/src/sys/unix/thread_parking/pthread.rs
@@ -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"))] {