Skip to content

Commit 4045d4c

Browse files
authored
Detect MIPS R6 (#750)
* Detect MIPS64 R6 * Detect MIPS32 R6
1 parent d8cb8bb commit 4045d4c

24 files changed

+1325
-66
lines changed

Cargo.toml

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

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

5858
# 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
@@ -22,8 +22,8 @@ fn main() {
2222
let is_x32 = arch == "x86_64" && pointer_width == "32";
2323
let is_arm64_ilp32 = arch == "aarch64" && pointer_width == "32";
2424
let is_powerpc64be = arch == "powerpc64" && endian == "big";
25-
let is_mipseb = arch == "mips" && endian == "big";
26-
let is_mips64eb = arch == "mips64" && endian == "big";
25+
let is_mipseb = (arch == "mips" || arch == "mips32r6") && endian == "big";
26+
let is_mips64eb = arch.contains("mips64") && endian == "big";
2727
let is_unsupported_abi = is_x32 || is_arm64_ilp32 || is_powerpc64be || is_mipseb || is_mips64eb;
2828

2929
// Check for `--features=use-libc`. This allows crate users to enable the
@@ -83,7 +83,7 @@ fn main() {
8383
|| !inline_asm_name_present
8484
|| is_unsupported_abi
8585
|| miri
86-
|| ((arch == "powerpc64" || arch == "mips" || arch == "mips64")
86+
|| ((arch == "powerpc64" || arch == "mips" || arch == "mips64" || arch == "mips64r6")
8787
&& !rustix_use_experimental_asm);
8888
if libc {
8989
// Use the libc backend.

src/backend/libc/c.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ pub(crate) const ETH_P_MCTP: c_int = linux_raw_sys::if_ether::ETH_P_MCTP as _;
6262
linux_kernel,
6363
any(
6464
target_arch = "mips",
65+
target_arch = "mips32r6",
6566
target_arch = "mips64",
67+
target_arch = "mips64r6",
6668
target_arch = "sparc",
6769
target_arch = "sparc64"
6870
)
@@ -123,7 +125,14 @@ pub(super) use libc::{
123125
host_info64_t as host_info_t, host_statistics64 as host_statistics,
124126
vm_statistics64_t as vm_statistics_t,
125127
};
126-
#[cfg(not(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64"))))]
128+
#[cfg(not(all(
129+
linux_kernel,
130+
any(
131+
target_pointer_width = "32",
132+
target_arch = "mips64",
133+
target_arch = "mips64r6"
134+
)
135+
)))]
127136
#[cfg(any(linux_like, target_os = "aix"))]
128137
pub(super) use libc::{lstat64 as lstat, stat64 as stat};
129138
#[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
@@ -536,7 +536,14 @@ pub(crate) fn symlinkat(
536536

537537
pub(crate) fn stat(path: &CStr) -> io::Result<Stat> {
538538
// See the comments in `fstat` about using `crate::fs::statx` here.
539-
#[cfg(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64")))]
539+
#[cfg(all(
540+
linux_kernel,
541+
any(
542+
target_pointer_width = "32",
543+
target_arch = "mips64",
544+
target_arch = "mips64r6"
545+
)
546+
))]
540547
{
541548
match crate::fs::statx(
542549
crate::fs::CWD,
@@ -552,7 +559,14 @@ pub(crate) fn stat(path: &CStr) -> io::Result<Stat> {
552559

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

563577
pub(crate) fn lstat(path: &CStr) -> io::Result<Stat> {
564578
// See the comments in `fstat` about using `crate::fs::statx` here.
565-
#[cfg(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64")))]
579+
#[cfg(all(
580+
linux_kernel,
581+
any(
582+
target_pointer_width = "32",
583+
target_arch = "mips64",
584+
target_arch = "mips64r6"
585+
)
586+
))]
566587
{
567588
match crate::fs::statx(
568589
crate::fs::CWD,
@@ -578,7 +599,14 @@ pub(crate) fn lstat(path: &CStr) -> io::Result<Stat> {
578599

579600
// Main version: libc is y2038 safe. Or, the platform is not y2038 safe and
580601
// there's nothing practical we can do.
581-
#[cfg(not(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64"))))]
602+
#[cfg(not(all(
603+
linux_kernel,
604+
any(
605+
target_pointer_width = "32",
606+
target_arch = "mips64",
607+
target_arch = "mips64r6"
608+
)
609+
)))]
582610
unsafe {
583611
let mut stat = MaybeUninit::<Stat>::uninit();
584612
ret(c::lstat(c_str(path), stat.as_mut_ptr()))?;
@@ -589,7 +617,14 @@ pub(crate) fn lstat(path: &CStr) -> io::Result<Stat> {
589617
#[cfg(not(any(target_os = "espidf", target_os = "redox")))]
590618
pub(crate) fn statat(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::Result<Stat> {
591619
// See the comments in `fstat` about using `crate::fs::statx` here.
592-
#[cfg(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64")))]
620+
#[cfg(all(
621+
linux_kernel,
622+
any(
623+
target_pointer_width = "32",
624+
target_arch = "mips64",
625+
target_arch = "mips64r6"
626+
)
627+
))]
593628
{
594629
match crate::fs::statx(dirfd, path, flags, StatxFlags::BASIC_STATS) {
595630
Ok(x) => statx_to_stat(x),
@@ -600,7 +635,14 @@ pub(crate) fn statat(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::
600635

601636
// Main version: libc is y2038 safe. Or, the platform is not y2038 safe and
602637
// there's nothing practical we can do.
603-
#[cfg(not(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64"))))]
638+
#[cfg(not(all(
639+
linux_kernel,
640+
any(
641+
target_pointer_width = "32",
642+
target_arch = "mips64",
643+
target_arch = "mips64r6"
644+
)
645+
)))]
604646
unsafe {
605647
let mut stat = MaybeUninit::<Stat>::uninit();
606648
ret(c::fstatat(
@@ -613,7 +655,14 @@ pub(crate) fn statat(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::
613655
}
614656
}
615657

616-
#[cfg(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64")))]
658+
#[cfg(all(
659+
linux_kernel,
660+
any(
661+
target_pointer_width = "32",
662+
target_arch = "mips64",
663+
target_arch = "mips64r6"
664+
)
665+
))]
617666
fn statat_old(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::Result<Stat> {
618667
unsafe {
619668
let mut result = MaybeUninit::<c::stat64>::uninit();
@@ -1284,7 +1333,14 @@ pub(crate) fn fstat(fd: BorrowedFd<'_>) -> io::Result<Stat> {
12841333
// And, some old platforms don't support `statx`, and some fail with a
12851334
// confusing error code, so we call `crate::fs::statx` to handle that. If
12861335
// `statx` isn't available, fall back to the buggy system call.
1287-
#[cfg(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64")))]
1336+
#[cfg(all(
1337+
linux_kernel,
1338+
any(
1339+
target_pointer_width = "32",
1340+
target_arch = "mips64",
1341+
target_arch = "mips64r6"
1342+
)
1343+
))]
12881344
{
12891345
match crate::fs::statx(fd, cstr!(""), AtFlags::EMPTY_PATH, StatxFlags::BASIC_STATS) {
12901346
Ok(x) => statx_to_stat(x),
@@ -1295,15 +1351,29 @@ pub(crate) fn fstat(fd: BorrowedFd<'_>) -> io::Result<Stat> {
12951351

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

1306-
#[cfg(all(linux_kernel, any(target_pointer_width = "32", target_arch = "mips64")))]
1369+
#[cfg(all(
1370+
linux_kernel,
1371+
any(
1372+
target_pointer_width = "32",
1373+
target_arch = "mips64",
1374+
target_arch = "mips64r6"
1375+
)
1376+
))]
13071377
fn fstat_old(fd: BorrowedFd<'_>) -> io::Result<Stat> {
13081378
unsafe {
13091379
let mut result = MaybeUninit::<c::stat64>::uninit();
@@ -1663,7 +1733,7 @@ fn statx_to_stat(x: crate::fs::Statx) -> io::Result<Stat> {
16631733
/// Convert from a Linux `statx` value to rustix's `Stat`.
16641734
///
16651735
/// mips64' `struct stat64` in libc has private fields, and `stx_blocks`
1666-
#[cfg(all(linux_kernel, target_arch = "mips64"))]
1736+
#[cfg(all(linux_kernel, any(target_arch = "mips64", target_arch = "mips64r6")))]
16671737
fn statx_to_stat(x: crate::fs::Statx) -> io::Result<Stat> {
16681738
let mut result: Stat = unsafe { core::mem::zeroed() };
16691739

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

src/backend/libc/mm/types.rs

Lines changed: 10 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 = "mips32r6", target_arch = "mips64", target_arch = "mips64r6"),
205205
)
206206
)))]
207207
const SYNC = bitcast!(c::MAP_SYNC);
@@ -333,7 +333,15 @@ 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(
339+
target_arch = "mips",
340+
target_arch = "mips32r6",
341+
target_arch = "mips64",
342+
target_arch = "mips64r6"
343+
))
344+
))]
337345
LinuxSoftOffline = bitcast!(c::MADV_SOFT_OFFLINE),
338346
/// `MADV_MERGEABLE`
339347
#[cfg(linux_kernel)]

src/backend/libc/termios/syscalls.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,12 @@ 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 = "mips32r6",
121+
target_arch = "mips64",
122+
target_arch = "mips64r6"
123+
)) {
119124
optional_actions as u32 - TCSETS
120125
} else {
121126
optional_actions as u32

0 commit comments

Comments
 (0)