Skip to content

Commit

Permalink
Detect MIPS64 R6
Browse files Browse the repository at this point in the history
  • Loading branch information
chenx97 committed Aug 2, 2023
1 parent d8cb8bb commit 312fcad
Show file tree
Hide file tree
Showing 20 changed files with 677 additions and 51 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ once_cell = { version = "1.5.2", optional = true }
# addition to the libc backend. The linux_raw backend is used by default. The
# libc backend can be selected via adding `--cfg=rustix_use_libc` to
# `RUSTFLAGS` or enabling the `use-libc` cargo feature.
[target.'cfg(all(not(rustix_use_libc), not(miri), target_os = "linux", target_endian = "little", any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips64"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64"))))'.dependencies]
[target.'cfg(all(not(rustix_use_libc), not(miri), target_os = "linux", target_endian = "little", any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64"))))'.dependencies]
linux-raw-sys = { version = "0.4.3", default-features = false, features = ["general", "errno", "ioctl", "no_std"] }
libc_errno = { package = "errno", version = "0.3.1", default-features = false, optional = true }
libc = { version = "0.2.147", features = ["extra_traits"], optional = true }
Expand All @@ -44,15 +44,15 @@ libc = { version = "0.2.147", features = ["extra_traits"], optional = true }
#
# On all other Unix-family platforms, and under Miri, we always use the libc
# backend, so enable its dependencies unconditionally.
[target.'cfg(all(not(windows), any(rustix_use_libc, miri, not(all(target_os = "linux", target_endian = "little", any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips64"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64")))))))'.dependencies]
[target.'cfg(all(not(windows), any(rustix_use_libc, miri, not(all(target_os = "linux", target_endian = "little", any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64")))))))'.dependencies]
libc_errno = { package = "errno", version = "0.3.1", default-features = false }
libc = { version = "0.2.147", features = ["extra_traits"] }

# Additional dependencies for Linux with the libc backend:
#
# Some syscalls do not have libc wrappers, such as in `io_uring`. For these,
# the libc backend uses the linux-raw-sys ABI and `libc::syscall`.
[target.'cfg(all(any(target_os = "android", target_os = "linux"), any(rustix_use_libc, miri, not(all(target_os = "linux", target_endian = "little", any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips64"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64")))))))'.dependencies]
[target.'cfg(all(any(target_os = "android", target_os = "linux"), any(rustix_use_libc, miri, not(all(target_os = "linux", target_endian = "little", any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64")))))))'.dependencies]
linux-raw-sys = { version = "0.4.3", default-features = false, features = ["general", "ioctl", "no_std"] }

# For the libc backend on Windows, use the Winsock2 API in windows-sys.
Expand Down
6 changes: 3 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ fn main() {
let is_x32 = arch == "x86_64" && pointer_width == "32";
let is_arm64_ilp32 = arch == "aarch64" && pointer_width == "32";
let is_powerpc64be = arch == "powerpc64" && endian == "big";
let is_mipseb = arch == "mips" && endian == "big";
let is_mips64eb = arch == "mips64" && endian == "big";
let is_mipseb = (arch == "mips" || arch == "mips32r6") && endian == "big";
let is_mips64eb = arch.contains("mips64") && endian == "big";
let is_unsupported_abi = is_x32 || is_arm64_ilp32 || is_powerpc64be || is_mipseb || is_mips64eb;

// Check for `--features=use-libc`. This allows crate users to enable the
Expand Down Expand Up @@ -83,7 +83,7 @@ fn main() {
|| !inline_asm_name_present
|| is_unsupported_abi
|| miri
|| ((arch == "powerpc64" || arch == "mips" || arch == "mips64")
|| ((arch == "powerpc64" || arch == "mips" || arch == "mips64" || arch == "mips64r6")
&& !rustix_use_experimental_asm);
if libc {
// Use the libc backend.
Expand Down
10 changes: 9 additions & 1 deletion src/backend/libc/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub(crate) const ETH_P_MCTP: c_int = linux_raw_sys::if_ether::ETH_P_MCTP as _;
any(
target_arch = "mips",
target_arch = "mips64",
target_arch = "mips64r6",
target_arch = "sparc",
target_arch = "sparc64"
)
Expand Down Expand Up @@ -123,7 +124,14 @@ pub(super) use libc::{
host_info64_t as host_info_t, host_statistics64 as host_statistics,
vm_statistics64_t as vm_statistics_t,
};
#[cfg(not(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64"))))]
#[cfg(not(all(
linux_kernel,
any(
target_pointer_width = "32",
target_arch = "mips64",
target_arch = "mips64r6"
)
)))]
#[cfg(any(linux_like, target_os = "aix"))]
pub(super) use libc::{lstat64 as lstat, stat64 as stat};
#[cfg(any(linux_kernel, target_os = "aix", target_os = "emscripten"))]
Expand Down
94 changes: 82 additions & 12 deletions src/backend/libc/fs/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,14 @@ pub(crate) fn symlinkat(

pub(crate) fn stat(path: &CStr) -> io::Result<Stat> {
// See the comments in `fstat` about using `crate::fs::statx` here.
#[cfg(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64")))]
#[cfg(all(
linux_kernel,
any(
target_pointer_width = "32",
target_arch = "mips64",
target_arch = "mips64r6"
)
))]
{
match crate::fs::statx(
crate::fs::CWD,
Expand All @@ -552,7 +559,14 @@ pub(crate) fn stat(path: &CStr) -> io::Result<Stat> {

// Main version: libc is y2038 safe. Or, the platform is not y2038 safe and
// there's nothing practical we can do.
#[cfg(not(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64"))))]
#[cfg(not(all(
linux_kernel,
any(
target_pointer_width = "32",
target_arch = "mips64",
target_arch = "mips64r6"
)
)))]
unsafe {
let mut stat = MaybeUninit::<Stat>::uninit();
ret(c::stat(c_str(path), stat.as_mut_ptr()))?;
Expand All @@ -562,7 +576,14 @@ pub(crate) fn stat(path: &CStr) -> io::Result<Stat> {

pub(crate) fn lstat(path: &CStr) -> io::Result<Stat> {
// See the comments in `fstat` about using `crate::fs::statx` here.
#[cfg(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64")))]
#[cfg(all(
linux_kernel,
any(
target_pointer_width = "32",
target_arch = "mips64",
target_arch = "mips64r6"
)
))]
{
match crate::fs::statx(
crate::fs::CWD,
Expand All @@ -578,7 +599,14 @@ pub(crate) fn lstat(path: &CStr) -> io::Result<Stat> {

// Main version: libc is y2038 safe. Or, the platform is not y2038 safe and
// there's nothing practical we can do.
#[cfg(not(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64"))))]
#[cfg(not(all(
linux_kernel,
any(
target_pointer_width = "32",
target_arch = "mips64",
target_arch = "mips64r6"
)
)))]
unsafe {
let mut stat = MaybeUninit::<Stat>::uninit();
ret(c::lstat(c_str(path), stat.as_mut_ptr()))?;
Expand All @@ -589,7 +617,14 @@ pub(crate) fn lstat(path: &CStr) -> io::Result<Stat> {
#[cfg(not(any(target_os = "espidf", target_os = "redox")))]
pub(crate) fn statat(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::Result<Stat> {
// See the comments in `fstat` about using `crate::fs::statx` here.
#[cfg(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64")))]
#[cfg(all(
linux_kernel,
any(
target_pointer_width = "32",
target_arch = "mips64",
target_arch = "mips64r6"
)
))]
{
match crate::fs::statx(dirfd, path, flags, StatxFlags::BASIC_STATS) {
Ok(x) => statx_to_stat(x),
Expand All @@ -600,7 +635,14 @@ pub(crate) fn statat(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::

// Main version: libc is y2038 safe. Or, the platform is not y2038 safe and
// there's nothing practical we can do.
#[cfg(not(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64"))))]
#[cfg(not(all(
linux_kernel,
any(
target_pointer_width = "32",
target_arch = "mips64",
target_arch = "mips64r6"
)
)))]
unsafe {
let mut stat = MaybeUninit::<Stat>::uninit();
ret(c::fstatat(
Expand All @@ -613,7 +655,14 @@ pub(crate) fn statat(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::
}
}

#[cfg(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64")))]
#[cfg(all(
linux_kernel,
any(
target_pointer_width = "32",
target_arch = "mips64",
target_arch = "mips64r6"
)
))]
fn statat_old(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::Result<Stat> {
unsafe {
let mut result = MaybeUninit::<c::stat64>::uninit();
Expand Down Expand Up @@ -1284,7 +1333,14 @@ pub(crate) fn fstat(fd: BorrowedFd<'_>) -> io::Result<Stat> {
// And, some old platforms don't support `statx`, and some fail with a
// confusing error code, so we call `crate::fs::statx` to handle that. If
// `statx` isn't available, fall back to the buggy system call.
#[cfg(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64")))]
#[cfg(all(
linux_kernel,
any(
target_pointer_width = "32",
target_arch = "mips64",
target_arch = "mips64r6"
)
))]
{
match crate::fs::statx(fd, cstr!(""), AtFlags::EMPTY_PATH, StatxFlags::BASIC_STATS) {
Ok(x) => statx_to_stat(x),
Expand All @@ -1295,15 +1351,29 @@ pub(crate) fn fstat(fd: BorrowedFd<'_>) -> io::Result<Stat> {

// Main version: libc is y2038 safe. Or, the platform is not y2038 safe and
// there's nothing practical we can do.
#[cfg(not(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64"))))]
#[cfg(not(all(
linux_kernel,
any(
target_pointer_width = "32",
target_arch = "mips64",
target_arch = "mips64r6"
)
)))]
unsafe {
let mut stat = MaybeUninit::<Stat>::uninit();
ret(c::fstat(borrowed_fd(fd), stat.as_mut_ptr()))?;
Ok(stat.assume_init())
}
}

#[cfg(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64")))]
#[cfg(all(
linux_kernel,
any(
target_pointer_width = "32",
target_arch = "mips64",
target_arch = "mips64r6"
)
))]
fn fstat_old(fd: BorrowedFd<'_>) -> io::Result<Stat> {
unsafe {
let mut result = MaybeUninit::<c::stat64>::uninit();
Expand Down Expand Up @@ -1663,7 +1733,7 @@ fn statx_to_stat(x: crate::fs::Statx) -> io::Result<Stat> {
/// Convert from a Linux `statx` value to rustix's `Stat`.
///
/// mips64' `struct stat64` in libc has private fields, and `stx_blocks`
#[cfg(all(linux_kernel, target_arch = "mips64"))]
#[cfg(all(linux_kernel, any(target_arch = "mips64", target_arch = "mips64r6")))]
fn statx_to_stat(x: crate::fs::Statx) -> io::Result<Stat> {
let mut result: Stat = unsafe { core::mem::zeroed() };

Expand Down Expand Up @@ -1735,7 +1805,7 @@ fn stat64_to_stat(s64: c::stat64) -> io::Result<Stat> {
///
/// mips64' `struct stat64` in libc has private fields, and `st_blocks` has
/// type `i64`.
#[cfg(all(linux_kernel, target_arch = "mips64"))]
#[cfg(all(linux_kernel, any(target_arch = "mips64", target_arch = "mips64r6")))]
fn stat64_to_stat(s64: c::stat64) -> io::Result<Stat> {
let mut result: Stat = unsafe { core::mem::zeroed() };

Expand Down
7 changes: 5 additions & 2 deletions src/backend/libc/mm/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ bitflags! {
target_os = "redox",
all(
linux_kernel,
any(target_arch = "mips", target_arch = "mips64"),
any(target_arch = "mips", target_arch = "mips64", target_arch = "mips64r6"),
)
)))]
const SYNC = bitcast!(c::MAP_SYNC);
Expand Down Expand Up @@ -333,7 +333,10 @@ pub enum Advice {
#[cfg(linux_kernel)]
LinuxHwPoison = bitcast!(c::MADV_HWPOISON),
/// `MADV_SOFT_OFFLINE`
#[cfg(all(linux_kernel, not(any(target_arch = "mips", target_arch = "mips64"))))]
#[cfg(all(
linux_kernel,
not(any(target_arch = "mips", target_arch = "mips64", target_arch = "mips64r6"))
))]
LinuxSoftOffline = bitcast!(c::MADV_SOFT_OFFLINE),
/// `MADV_MERGEABLE`
#[cfg(linux_kernel)]
Expand Down
6 changes: 5 additions & 1 deletion src/backend/libc/termios/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ pub(crate) fn tcsetattr(
// Translate from `optional_actions` into an ioctl request code. On MIPS,
// `optional_actions` already has `TCGETS` added to it.
let request = TCSETS2
+ if cfg!(any(target_arch = "mips", target_arch = "mips64")) {
+ if cfg!(any(
target_arch = "mips",
target_arch = "mips64",
target_arch = "mips64r6"
)) {
optional_actions as u32 - TCSETS
} else {
optional_actions as u32
Expand Down
Loading

0 comments on commit 312fcad

Please sign in to comment.