Skip to content

Commit

Permalink
Add support for armv7-sony-vita-newlibeabihf. (#882)
Browse files Browse the repository at this point in the history
Add `target_os = "vita"` checks as needed for rustix to compile on
armv7-sony-vita-newlibeabihf.

This excludes support for `mm`, `termios`, and a few other things for
now, where the libc bindings seem to be missing key types and constants.

Fixes #881.
  • Loading branch information
sunfishcode committed Oct 18, 2023
1 parent 702c54a commit 30a5ae1
Show file tree
Hide file tree
Showing 47 changed files with 712 additions and 175 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ jobs:
- run: cargo check -Z build-std --target=riscv32imc-esp-espidf --features=all-apis
- run: cargo check -Z build-std --target=aarch64-unknown-nto-qnx710 --features=all-apis
- run: cargo check -Z build-std --target=x86_64-pc-nto-qnx710 --features=all-apis
- run: cargo check -Z build-std --target=armv7-sony-vita-newlibeabihf --features=all-apis
# `std` doesn't appear to build on AIX yet, so test in `no_std` mode.
- run: cargo check -Zbuild-std=core,alloc --target=powerpc64-ibm-aix --features=all-apis --no-default-features
# Disable MIPS entirely for now as it fails with errors like
Expand Down
11 changes: 9 additions & 2 deletions src/backend/libc/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub(super) fn c_str(c: &CStr) -> *const c::c_char {
c.as_ptr()
}

#[cfg(not(any(windows, target_os = "espidf", target_os = "wasi")))]
#[cfg(not(any(windows, target_os = "espidf", target_os = "vita", target_os = "wasi")))]
#[inline]
pub(super) fn no_fd() -> LibcFd {
-1
Expand Down Expand Up @@ -192,7 +192,13 @@ pub(super) fn msg_iov_len(len: usize) -> c::size_t {

/// Convert the value to the `msg_iovlen` field of a `msghdr` struct.
#[cfg(all(
not(any(windows, target_os = "espidf", target_os = "redox", target_os = "wasi")),
not(any(
windows,
target_os = "espidf",
target_os = "redox",
target_os = "vita",
target_os = "wasi"
)),
not(any(
target_os = "android",
all(target_os = "linux", not(target_env = "musl"))
Expand Down Expand Up @@ -232,6 +238,7 @@ pub(crate) fn msg_control_len(len: usize) -> c::socklen_t {
target_os = "haiku",
target_os = "nto",
target_os = "redox",
target_os = "vita",
target_os = "wasi",
)))]
#[inline]
Expand Down
61 changes: 46 additions & 15 deletions src/backend/libc/fs/dir.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
#[cfg(not(any(solarish, target_os = "haiku", target_os = "nto")))]
#[cfg(not(any(solarish, target_os = "haiku", target_os = "nto", target_os = "vita")))]
use super::types::FileType;
use crate::backend::c;
use crate::backend::conv::owned_fd;
use crate::fd::{AsFd, BorrowedFd};
use crate::ffi::{CStr, CString};
use crate::fs::{fcntl_getfl, fstat, openat, Mode, OFlags, Stat};
use crate::fs::{fcntl_getfl, openat, Mode, OFlags};
#[cfg(not(target_os = "vita"))]
use crate::fs::{fstat, Stat};
#[cfg(not(any(
solarish,
target_os = "haiku",
target_os = "netbsd",
target_os = "nto",
target_os = "redox",
target_os = "vita",
target_os = "wasi",
)))]
use crate::fs::{fstatfs, StatFs};
#[cfg(not(any(solarish, target_os = "haiku", target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(
solarish,
target_os = "haiku",
target_os = "redox",
target_os = "vita",
target_os = "wasi"
)))]
use crate::fs::{fstatvfs, StatVfs};
use crate::io;
#[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))]
#[cfg(not(any(target_os = "fuchsia", target_os = "vita", target_os = "wasi")))]
#[cfg(feature = "process")]
use crate::process::fchdir;
use alloc::borrow::ToOwned;
Expand Down Expand Up @@ -128,11 +137,12 @@ impl Dir {
solarish,
target_os = "aix",
target_os = "haiku",
target_os = "nto"
target_os = "nto",
target_os = "vita"
)))]
d_type: dirent.d_type,

#[cfg(not(any(freebsdlike, netbsdlike)))]
#[cfg(not(any(freebsdlike, netbsdlike, target_os = "vita")))]
d_ino: dirent.d_ino,

#[cfg(any(freebsdlike, netbsdlike))]
Expand All @@ -147,6 +157,7 @@ impl Dir {
}

/// `fstat(self)`
#[cfg(not(target_os = "vita"))]
#[inline]
pub fn stat(&self) -> io::Result<Stat> {
fstat(unsafe { BorrowedFd::borrow_raw(c::dirfd(self.libc_dir.as_ptr())) })
Expand All @@ -159,6 +170,7 @@ impl Dir {
target_os = "netbsd",
target_os = "nto",
target_os = "redox",
target_os = "vita",
target_os = "wasi",
)))]
#[inline]
Expand All @@ -167,15 +179,21 @@ impl Dir {
}

/// `fstatvfs(self)`
#[cfg(not(any(solarish, target_os = "haiku", target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(
solarish,
target_os = "haiku",
target_os = "redox",
target_os = "vita",
target_os = "wasi"
)))]
#[inline]
pub fn statvfs(&self) -> io::Result<StatVfs> {
fstatvfs(unsafe { BorrowedFd::borrow_raw(c::dirfd(self.libc_dir.as_ptr())) })
}

/// `fchdir(self)`
#[cfg(feature = "process")]
#[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))]
#[cfg(not(any(target_os = "fuchsia", target_os = "vita", target_os = "wasi")))]
#[cfg_attr(doc_cfg, doc(cfg(feature = "process")))]
#[inline]
pub fn chdir(&self) -> io::Result<()> {
Expand Down Expand Up @@ -207,19 +225,26 @@ impl Iterator for Dir {

impl fmt::Debug for Dir {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Dir")
.field("fd", unsafe { &c::dirfd(self.libc_dir.as_ptr()) })
.finish()
let mut s = f.debug_struct("Dir");
#[cfg(not(target_os = "vita"))]
s.field("fd", unsafe { &c::dirfd(self.libc_dir.as_ptr()) });
s.finish()
}
}

/// `struct dirent`
#[derive(Debug)]
pub struct DirEntry {
#[cfg(not(any(solarish, target_os = "aix", target_os = "haiku", target_os = "nto")))]
#[cfg(not(any(
solarish,
target_os = "aix",
target_os = "haiku",
target_os = "nto",
target_os = "vita"
)))]
d_type: u8,

#[cfg(not(any(freebsdlike, netbsdlike)))]
#[cfg(not(any(freebsdlike, netbsdlike, target_os = "vita")))]
d_ino: c::ino_t,

#[cfg(any(freebsdlike, netbsdlike))]
Expand All @@ -236,14 +261,20 @@ impl DirEntry {
}

/// Returns the type of this directory entry.
#[cfg(not(any(solarish, target_os = "aix", target_os = "haiku", target_os = "nto")))]
#[cfg(not(any(
solarish,
target_os = "aix",
target_os = "haiku",
target_os = "nto",
target_os = "vita"
)))]
#[inline]
pub fn file_type(&self) -> FileType {
FileType::from_dirent_d_type(self.d_type)
}

/// Return the inode number of this directory entry.
#[cfg(not(any(freebsdlike, netbsdlike)))]
#[cfg(not(any(freebsdlike, netbsdlike, target_os = "vita")))]
#[inline]
pub fn ino(&self) -> u64 {
self.d_ino as u64
Expand Down
1 change: 1 addition & 0 deletions src/backend/libc/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod inotify;
target_os = "espidf",
target_os = "haiku",
target_os = "redox",
target_os = "vita",
target_os = "wasi"
)))]
pub(crate) mod makedev;
Expand Down
64 changes: 51 additions & 13 deletions src/backend/libc/fs/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use crate::fd::{BorrowedFd, OwnedFd};
use crate::ffi::CStr;
#[cfg(apple)]
use crate::ffi::CString;
#[cfg(not(any(target_os = "espidf", target_os = "vita")))]
use crate::fs::Access;
#[cfg(not(any(
apple,
netbsdlike,
Expand All @@ -21,6 +23,7 @@ use crate::ffi::CString;
target_os = "espidf",
target_os = "haiku",
target_os = "redox",
target_os = "vita",
)))]
use crate::fs::Advice;
#[cfg(not(any(target_os = "espidf", target_os = "redox")))]
Expand All @@ -33,9 +36,10 @@ use crate::fs::AtFlags;
target_os = "espidf",
target_os = "nto",
target_os = "redox",
target_os = "vita",
)))]
use crate::fs::FallocateFlags;
#[cfg(not(any(target_os = "espidf", target_os = "wasi")))]
#[cfg(not(any(target_os = "espidf", target_os = "vita", target_os = "wasi")))]
use crate::fs::FlockOperation;
#[cfg(any(linux_kernel, target_os = "freebsd"))]
use crate::fs::MemfdFlags;
Expand All @@ -48,12 +52,19 @@ use crate::fs::SealFlags;
target_os = "netbsd",
target_os = "nto",
target_os = "redox",
target_os = "vita",
target_os = "wasi",
)))]
use crate::fs::StatFs;
#[cfg(not(target_os = "espidf"))]
use crate::fs::{Access, Timestamps};
#[cfg(not(any(apple, target_os = "espidf", target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(target_os = "espidf", target_os = "vita")))]
use crate::fs::Timestamps;
#[cfg(not(any(
apple,
target_os = "espidf",
target_os = "redox",
target_os = "vita",
target_os = "wasi"
)))]
use crate::fs::{Dev, FileType};
use crate::fs::{Mode, OFlags, SeekFrom, Stat};
#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))]
Expand Down Expand Up @@ -232,6 +243,7 @@ pub(crate) fn openat(
target_os = "netbsd",
target_os = "nto",
target_os = "redox",
target_os = "vita",
target_os = "wasi",
)))]
#[inline]
Expand Down Expand Up @@ -688,12 +700,17 @@ fn statat_old(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::Result<
}
}

#[cfg(not(any(target_os = "espidf", target_os = "emscripten")))]
#[cfg(not(any(target_os = "espidf", target_os = "emscripten", target_os = "vita")))]
pub(crate) fn access(path: &CStr, access: Access) -> io::Result<()> {
unsafe { ret(c::access(c_str(path), access.bits())) }
}

#[cfg(not(any(target_os = "emscripten", target_os = "espidf", target_os = "redox")))]
#[cfg(not(any(
target_os = "emscripten",
target_os = "espidf",
target_os = "redox",
target_os = "vita"
)))]
pub(crate) fn accessat(
dirfd: BorrowedFd<'_>,
path: &CStr,
Expand Down Expand Up @@ -759,7 +776,7 @@ pub(crate) fn accessat(
Ok(())
}

#[cfg(not(any(target_os = "espidf", target_os = "redox")))]
#[cfg(not(any(target_os = "espidf", target_os = "redox", target_os = "vita")))]
pub(crate) fn utimensat(
dirfd: BorrowedFd<'_>,
path: &CStr,
Expand Down Expand Up @@ -1070,7 +1087,13 @@ pub(crate) fn chownat(
}
}

#[cfg(not(any(apple, target_os = "espidf", target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(
apple,
target_os = "espidf",
target_os = "redox",
target_os = "vita",
target_os = "wasi"
)))]
pub(crate) fn mknodat(
dirfd: BorrowedFd<'_>,
path: &CStr,
Expand Down Expand Up @@ -1149,6 +1172,7 @@ pub(crate) fn copy_file_range(
target_os = "espidf",
target_os = "haiku",
target_os = "redox",
target_os = "vita",
)))]
pub(crate) fn fadvise(fd: BorrowedFd<'_>, offset: u64, len: u64, advice: Advice) -> io::Result<()> {
let offset = offset as i64;
Expand Down Expand Up @@ -1205,6 +1229,7 @@ pub(crate) fn fcntl_add_seals(fd: BorrowedFd<'_>, seals: SealFlags) -> io::Resul
target_os = "espidf",
target_os = "fuchsia",
target_os = "redox",
target_os = "vita",
target_os = "wasi"
)))]
#[inline]
Expand Down Expand Up @@ -1250,8 +1275,8 @@ pub(crate) fn seek(fd: BorrowedFd<'_>, pos: SeekFrom) -> io::Result<u64> {
SeekFrom::Hole(offset) => (c::SEEK_HOLE, offset),
};

// ESP-IDF doesn't support 64-bit offsets.
#[cfg(target_os = "espidf")]
// ESP-IDF and Vita don't support 64-bit offsets.
#[cfg(any(target_os = "espidf", target_os = "vita"))]
let offset: i32 = offset.try_into().map_err(|_| io::Errno::OVERFLOW)?;

let offset = unsafe { ret_off_t(c::lseek(borrowed_fd(fd), offset, whence))? };
Expand Down Expand Up @@ -1318,7 +1343,12 @@ pub(crate) fn fchown(fd: BorrowedFd<'_>, owner: Option<Uid>, group: Option<Gid>)
}
}

#[cfg(not(any(target_os = "espidf", target_os = "solaris", target_os = "wasi")))]
#[cfg(not(any(
target_os = "espidf",
target_os = "solaris",
target_os = "vita",
target_os = "wasi"
)))]
pub(crate) fn flock(fd: BorrowedFd<'_>, operation: FlockOperation) -> io::Result<()> {
unsafe { ret(c::flock(borrowed_fd(fd), operation as c::c_int)) }
}
Expand All @@ -1340,7 +1370,12 @@ pub(crate) fn syncfs(fd: BorrowedFd<'_>) -> io::Result<()> {
unsafe { ret(syncfs(borrowed_fd(fd))) }
}

#[cfg(not(any(target_os = "espidf", target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(
target_os = "espidf",
target_os = "redox",
target_os = "vita",
target_os = "wasi"
)))]
pub(crate) fn sync() {
unsafe { c::sync() }
}
Expand Down Expand Up @@ -1408,6 +1443,7 @@ fn fstat_old(fd: BorrowedFd<'_>) -> io::Result<Stat> {
target_os = "netbsd",
target_os = "nto",
target_os = "redox",
target_os = "vita",
target_os = "wasi",
)))]
pub(crate) fn fstatfs(fd: BorrowedFd<'_>) -> io::Result<StatFs> {
Expand Down Expand Up @@ -1447,7 +1483,7 @@ fn libc_statvfs_to_statvfs(from: c::statvfs) -> StatVfs {
}
}

#[cfg(not(target_os = "espidf"))]
#[cfg(not(any(target_os = "espidf", target_os = "vita")))]
pub(crate) fn futimens(fd: BorrowedFd<'_>, times: &Timestamps) -> io::Result<()> {
// Old 32-bit version: libc has `futimens` but it is not y2038 safe by
// default. But there may be a `__futimens64` we can use.
Expand Down Expand Up @@ -1555,6 +1591,7 @@ fn futimens_old(fd: BorrowedFd<'_>, times: &Timestamps) -> io::Result<()> {
target_os = "espidf",
target_os = "nto",
target_os = "redox",
target_os = "vita",
)))]
pub(crate) fn fallocate(
fd: BorrowedFd<'_>,
Expand Down Expand Up @@ -1632,6 +1669,7 @@ pub(crate) fn fsync(fd: BorrowedFd<'_>) -> io::Result<()> {
target_os = "espidf",
target_os = "haiku",
target_os = "redox",
target_os = "vita",
)))]
pub(crate) fn fdatasync(fd: BorrowedFd<'_>) -> io::Result<()> {
unsafe { ret(c::fdatasync(borrowed_fd(fd))) }
Expand Down

0 comments on commit 30a5ae1

Please sign in to comment.