Skip to content

Commit 3b8882c

Browse files
committed
Detect MIPS64 R6
1 parent 4e817b8 commit 3b8882c

File tree

20 files changed

+676
-51
lines changed

20 files changed

+676
-51
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ once_cell = { version = "1.5.2", optional = true }
3434
# addition to the libc backend. The linux_raw backend is used by default. The
3535
# libc backend can be selected via adding `--cfg=rustix_use_libc` to
3636
# `RUSTFLAGS` or enabling the `use-libc` cargo feature.
37-
[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]
37+
[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]
3838
linux-raw-sys = { version = "0.4.3", default-features = false, features = ["general", "errno", "ioctl", "no_std"] }
3939
libc_errno = { package = "errno", version = "0.3.1", default-features = false, optional = true }
4040
libc = { version = "0.2.147", features = ["extra_traits"], optional = true }
@@ -43,15 +43,15 @@ libc = { version = "0.2.147", features = ["extra_traits"], optional = true }
4343
#
4444
# On all other Unix-family platforms, and under Miri, we always use the libc
4545
# backend, so enable its dependencies unconditionally.
46-
[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]
46+
[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]
4747
libc_errno = { package = "errno", version = "0.3.1", default-features = false }
4848
libc = { version = "0.2.147", features = ["extra_traits"] }
4949

5050
# Additional dependencies for Linux with the libc backend:
5151
#
5252
# Some syscalls do not have libc wrappers, such as in `io_uring`. For these,
5353
# the libc backend uses the linux-raw-sys ABI and `libc::syscall`.
54-
[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]
54+
[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]
5555
linux-raw-sys = { version = "0.4.3", default-features = false, features = ["general", "ioctl", "no_std"] }
5656

5757
# For the libc backend on Windows, use the Winsock2 API in windows-sys.

build.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ fn main() {
3333
let is_x32 = arch == "x86_64" && pointer_width == "32";
3434
let is_arm64_ilp32 = arch == "aarch64" && pointer_width == "32";
3535
let is_powerpc64be = arch == "powerpc64" && endian == "big";
36-
let is_mipseb = arch == "mips" && endian == "big";
37-
let is_mips64eb = arch == "mips64" && endian == "big";
36+
let is_mipseb = (arch == "mips" || arch == "mips32r6") && endian == "big";
37+
let is_mips64eb = arch.contains("mips64") && endian == "big";
3838
let is_unsupported_abi = is_x32 || is_arm64_ilp32 || is_powerpc64be || is_mipseb || is_mips64eb;
3939

4040
// Check for `--features=use-libc`. This allows crate users to enable the
@@ -66,7 +66,7 @@ fn main() {
6666
|| !inline_asm_name_present
6767
|| is_unsupported_abi
6868
|| miri
69-
|| ((arch == "powerpc64" || arch == "mips" || arch == "mips64")
69+
|| ((arch == "powerpc64" || arch == "mips" || arch == "mips64" || arch == "mips64r6")
7070
&& !rustix_use_experimental_asm);
7171
if libc {
7272
// Use the libc backend.

src/backend/libc/c.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub(crate) const ETH_P_MCTP: c_int = linux_raw_sys::if_ether::ETH_P_MCTP as _;
6363
any(
6464
target_arch = "mips",
6565
target_arch = "mips64",
66+
target_arch = "mips64r6",
6667
target_arch = "sparc",
6768
target_arch = "sparc64"
6869
)
@@ -123,7 +124,14 @@ pub(super) use libc::{
123124
host_info64_t as host_info_t, host_statistics64 as host_statistics,
124125
vm_statistics64_t as vm_statistics_t,
125126
};
126-
#[cfg(not(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64"))))]
127+
#[cfg(not(all(
128+
linux_kernel,
129+
any(
130+
target_pointer_width = "32",
131+
target_arch = "mips64",
132+
target_arch = "mips64r6"
133+
)
134+
)))]
127135
#[cfg(any(linux_like, target_os = "aix"))]
128136
pub(super) use libc::{lstat64 as lstat, stat64 as stat};
129137
#[cfg(any(linux_kernel, target_os = "aix", target_os = "emscripten"))]

src/backend/libc/fs/syscalls.rs

Lines changed: 82 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,14 @@ pub(crate) fn symlinkat(
534534

535535
pub(crate) fn stat(path: &CStr) -> io::Result<Stat> {
536536
// See the comments in `fstat` about using `crate::fs::statx` here.
537-
#[cfg(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64")))]
537+
#[cfg(all(
538+
linux_kernel,
539+
any(
540+
target_pointer_width = "32",
541+
target_arch = "mips64",
542+
target_arch = "mips64r6"
543+
)
544+
))]
538545
{
539546
match crate::fs::statx(
540547
crate::fs::CWD,
@@ -550,7 +557,14 @@ pub(crate) fn stat(path: &CStr) -> io::Result<Stat> {
550557

551558
// Main version: libc is y2038 safe. Or, the platform is not y2038 safe and
552559
// there's nothing practical we can do.
553-
#[cfg(not(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64"))))]
560+
#[cfg(not(all(
561+
linux_kernel,
562+
any(
563+
target_pointer_width = "32",
564+
target_arch = "mips64",
565+
target_arch = "mips64r6"
566+
)
567+
)))]
554568
unsafe {
555569
let mut stat = MaybeUninit::<Stat>::uninit();
556570
ret(c::stat(c_str(path), stat.as_mut_ptr()))?;
@@ -560,7 +574,14 @@ pub(crate) fn stat(path: &CStr) -> io::Result<Stat> {
560574

561575
pub(crate) fn lstat(path: &CStr) -> io::Result<Stat> {
562576
// See the comments in `fstat` about using `crate::fs::statx` here.
563-
#[cfg(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64")))]
577+
#[cfg(all(
578+
linux_kernel,
579+
any(
580+
target_pointer_width = "32",
581+
target_arch = "mips64",
582+
target_arch = "mips64r6"
583+
)
584+
))]
564585
{
565586
match crate::fs::statx(
566587
crate::fs::CWD,
@@ -576,7 +597,14 @@ pub(crate) fn lstat(path: &CStr) -> io::Result<Stat> {
576597

577598
// Main version: libc is y2038 safe. Or, the platform is not y2038 safe and
578599
// there's nothing practical we can do.
579-
#[cfg(not(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64"))))]
600+
#[cfg(not(all(
601+
linux_kernel,
602+
any(
603+
target_pointer_width = "32",
604+
target_arch = "mips64",
605+
target_arch = "mips64r6"
606+
)
607+
)))]
580608
unsafe {
581609
let mut stat = MaybeUninit::<Stat>::uninit();
582610
ret(c::lstat(c_str(path), stat.as_mut_ptr()))?;
@@ -587,7 +615,14 @@ pub(crate) fn lstat(path: &CStr) -> io::Result<Stat> {
587615
#[cfg(not(any(target_os = "espidf", target_os = "redox")))]
588616
pub(crate) fn statat(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::Result<Stat> {
589617
// See the comments in `fstat` about using `crate::fs::statx` here.
590-
#[cfg(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64")))]
618+
#[cfg(all(
619+
linux_kernel,
620+
any(
621+
target_pointer_width = "32",
622+
target_arch = "mips64",
623+
target_arch = "mips64r6"
624+
)
625+
))]
591626
{
592627
match crate::fs::statx(dirfd, path, flags, StatxFlags::BASIC_STATS) {
593628
Ok(x) => statx_to_stat(x),
@@ -598,7 +633,14 @@ pub(crate) fn statat(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::
598633

599634
// Main version: libc is y2038 safe. Or, the platform is not y2038 safe and
600635
// there's nothing practical we can do.
601-
#[cfg(not(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64"))))]
636+
#[cfg(not(all(
637+
linux_kernel,
638+
any(
639+
target_pointer_width = "32",
640+
target_arch = "mips64",
641+
target_arch = "mips64r6"
642+
)
643+
)))]
602644
unsafe {
603645
let mut stat = MaybeUninit::<Stat>::uninit();
604646
ret(c::fstatat(
@@ -611,7 +653,14 @@ pub(crate) fn statat(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::
611653
}
612654
}
613655

614-
#[cfg(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64")))]
656+
#[cfg(all(
657+
linux_kernel,
658+
any(
659+
target_pointer_width = "32",
660+
target_arch = "mips64",
661+
target_arch = "mips64r6"
662+
)
663+
))]
615664
fn statat_old(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::Result<Stat> {
616665
unsafe {
617666
let mut result = MaybeUninit::<c::stat64>::uninit();
@@ -1282,7 +1331,14 @@ pub(crate) fn fstat(fd: BorrowedFd<'_>) -> io::Result<Stat> {
12821331
// And, some old platforms don't support `statx`, and some fail with a
12831332
// confusing error code, so we call `crate::fs::statx` to handle that. If
12841333
// `statx` isn't available, fall back to the buggy system call.
1285-
#[cfg(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64")))]
1334+
#[cfg(all(
1335+
linux_kernel,
1336+
any(
1337+
target_pointer_width = "32",
1338+
target_arch = "mips64",
1339+
target_arch = "mips64r6"
1340+
)
1341+
))]
12861342
{
12871343
match crate::fs::statx(fd, cstr!(""), AtFlags::EMPTY_PATH, StatxFlags::BASIC_STATS) {
12881344
Ok(x) => statx_to_stat(x),
@@ -1293,15 +1349,29 @@ pub(crate) fn fstat(fd: BorrowedFd<'_>) -> io::Result<Stat> {
12931349

12941350
// Main version: libc is y2038 safe. Or, the platform is not y2038 safe and
12951351
// there's nothing practical we can do.
1296-
#[cfg(not(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64"))))]
1352+
#[cfg(not(all(
1353+
linux_kernel,
1354+
any(
1355+
target_pointer_width = "32",
1356+
target_arch = "mips64",
1357+
target_arch = "mips64r6"
1358+
)
1359+
)))]
12971360
unsafe {
12981361
let mut stat = MaybeUninit::<Stat>::uninit();
12991362
ret(c::fstat(borrowed_fd(fd), stat.as_mut_ptr()))?;
13001363
Ok(stat.assume_init())
13011364
}
13021365
}
13031366

1304-
#[cfg(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64")))]
1367+
#[cfg(all(
1368+
linux_kernel,
1369+
any(
1370+
target_pointer_width = "32",
1371+
target_arch = "mips64",
1372+
target_arch = "mips64r6"
1373+
)
1374+
))]
13051375
fn fstat_old(fd: BorrowedFd<'_>) -> io::Result<Stat> {
13061376
unsafe {
13071377
let mut result = MaybeUninit::<c::stat64>::uninit();
@@ -1661,7 +1731,7 @@ fn statx_to_stat(x: crate::fs::Statx) -> io::Result<Stat> {
16611731
/// Convert from a Linux `statx` value to rustix's `Stat`.
16621732
///
16631733
/// mips64' `struct stat64` in libc has private fields, and `stx_blocks`
1664-
#[cfg(all(linux_kernel, target_arch = "mips64"))]
1734+
#[cfg(all(linux_kernel, any(target_arch = "mips64", target_arch = "mips64r6")))]
16651735
fn statx_to_stat(x: crate::fs::Statx) -> io::Result<Stat> {
16661736
let mut result: Stat = unsafe { core::mem::zeroed() };
16671737

@@ -1733,7 +1803,7 @@ fn stat64_to_stat(s64: c::stat64) -> io::Result<Stat> {
17331803
///
17341804
/// mips64' `struct stat64` in libc has private fields, and `st_blocks` has
17351805
/// type `i64`.
1736-
#[cfg(all(linux_kernel, target_arch = "mips64"))]
1806+
#[cfg(all(linux_kernel, any(target_arch = "mips64", target_arch = "mips64r6")))]
17371807
fn stat64_to_stat(s64: c::stat64) -> io::Result<Stat> {
17381808
let mut result: Stat = unsafe { core::mem::zeroed() };
17391809

src/backend/libc/mm/types.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ bitflags! {
201201
target_os = "redox",
202202
all(
203203
linux_kernel,
204-
any(target_arch = "mips", target_arch = "mips64"),
204+
any(target_arch = "mips", target_arch = "mips64", target_arch = "mips64r6"),
205205
)
206206
)))]
207207
const SYNC = bitcast!(c::MAP_SYNC);
@@ -333,7 +333,10 @@ pub enum Advice {
333333
#[cfg(linux_kernel)]
334334
LinuxHwPoison = bitcast!(c::MADV_HWPOISON),
335335
/// `MADV_SOFT_OFFLINE`
336-
#[cfg(all(linux_kernel, not(any(target_arch = "mips", target_arch = "mips64"))))]
336+
#[cfg(all(
337+
linux_kernel,
338+
not(any(target_arch = "mips", target_arch = "mips64", target_arch = "mips64r6"))
339+
))]
337340
LinuxSoftOffline = bitcast!(c::MADV_SOFT_OFFLINE),
338341
/// `MADV_MERGEABLE`
339342
#[cfg(linux_kernel)]

src/backend/libc/termios/syscalls.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,11 @@ pub(crate) fn tcsetattr(
115115
// Translate from `optional_actions` into an ioctl request code. On MIPS,
116116
// `optional_actions` already has `TCGETS` added to it.
117117
let request = TCSETS2
118-
+ if cfg!(any(target_arch = "mips", target_arch = "mips64")) {
118+
+ if cfg!(any(
119+
target_arch = "mips",
120+
target_arch = "mips64",
121+
target_arch = "mips64r6"
122+
)) {
119123
optional_actions as u32 - TCSETS
120124
} else {
121125
optional_actions as u32

0 commit comments

Comments
 (0)