From 0c1dc599d108ac2d0de9d2891bbcbc7b549aac36 Mon Sep 17 00:00:00 2001 From: yangzewei Date: Sat, 6 Jul 2024 15:49:52 +0800 Subject: [PATCH] Add loongarch64 support --- Cargo.toml | 4 +- src/backend/linux_raw/arch/loongarch64.rs | 265 ++++++++++++++++++++++ src/backend/linux_raw/arch/mod.rs | 1 + src/backend/linux_raw/conv.rs | 6 +- src/backend/linux_raw/fs/dir.rs | 7 +- src/backend/linux_raw/fs/syscalls.rs | 16 +- src/backend/linux_raw/fs/types.rs | 3 +- src/backend/linux_raw/io/syscalls.rs | 12 +- src/backend/linux_raw/net/syscalls.rs | 4 + src/backend/linux_raw/process/syscalls.rs | 14 +- src/backend/linux_raw/vdso_wrappers.rs | 2 + src/fs/at.rs | 2 +- src/fs/fd.rs | 2 + src/process/rlimit.rs | 2 + tests/process/rlimit.rs | 4 +- 15 files changed, 327 insertions(+), 17 deletions(-) create mode 100644 src/backend/linux_raw/arch/loongarch64.rs diff --git a/Cargo.toml b/Cargo.toml index 9522c87d1..a85e86d4f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 = "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] +[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"), target_arch="loongarch64")))'.dependencies] linux-raw-sys = { version = "0.4.14", default-features = false, features = ["general", "errno", "ioctl", "no_std", "elf"] } libc_errno = { package = "errno", version = "0.3.8", default-features = false, optional = true } libc = { version = "0.2.153", default-features = false, optional = true } @@ -44,7 +44,7 @@ libc = { version = "0.2.153", default-features = false, 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 = "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] +[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"), target_arch = "loongarch64"))))))'.dependencies] libc_errno = { package = "errno", version = "0.3.8", default-features = false } libc = { version = "0.2.153", default-features = false } diff --git a/src/backend/linux_raw/arch/loongarch64.rs b/src/backend/linux_raw/arch/loongarch64.rs new file mode 100644 index 000000000..91216a7e0 --- /dev/null +++ b/src/backend/linux_raw/arch/loongarch64.rs @@ -0,0 +1,265 @@ +//! loongarch64 Linux system calls. + +use crate::backend::reg::{ + ArgReg, FromAsm, RetReg, SyscallNumber, ToAsm, A0, A1, A2, A3, A4, A5, R0, +}; +use core::arch::asm; + +#[inline] +pub(in crate::backend) unsafe fn syscall0_readonly(nr: SyscallNumber<'_>) -> RetReg { + let r0; + asm!( + "syscall 0", + in("$a7") nr.to_asm(), + lateout("$a0") r0, + options(nostack, preserves_flags, readonly) + ); + FromAsm::from_asm(r0) +} + +#[inline] +pub(in crate::backend) unsafe fn syscall1(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> RetReg { + let r0; + asm!( + "syscall 0", + in("$a7") nr.to_asm(), + inlateout("$a0") a0.to_asm() => r0, + options(nostack, preserves_flags) + ); + FromAsm::from_asm(r0) +} + +#[inline] +pub(in crate::backend) unsafe fn syscall1_readonly( + nr: SyscallNumber<'_>, + a0: ArgReg<'_, A0>, +) -> RetReg { + let r0; + asm!( + "syscall 0", + in("$a7") nr.to_asm(), + inlateout("$a0") a0.to_asm() => r0, + options(nostack, preserves_flags, readonly) + ); + FromAsm::from_asm(r0) +} + +#[inline] +pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! { + asm!( + "syscall 0", + in("$a7") nr.to_asm(), + in("$a0") a0.to_asm(), + options(noreturn) + ); +} + +#[inline] +pub(in crate::backend) unsafe fn syscall2( + nr: SyscallNumber<'_>, + a0: ArgReg<'_, A0>, + a1: ArgReg<'_, A1>, +) -> RetReg { + let r0; + asm!( + "syscall 0", + in("$a7") nr.to_asm(), + inlateout("$a0") a0.to_asm() => r0, + in("$a1") a1.to_asm(), + options(nostack, preserves_flags) + ); + FromAsm::from_asm(r0) +} + +#[inline] +pub(in crate::backend) unsafe fn syscall2_readonly( + nr: SyscallNumber<'_>, + a0: ArgReg<'_, A0>, + a1: ArgReg<'_, A1>, +) -> RetReg { + let r0; + asm!( + "syscall 0", + in("$a7") nr.to_asm(), + inlateout("$a0") a0.to_asm() => r0, + in("$a1") a1.to_asm(), + options(nostack, preserves_flags, readonly) + ); + FromAsm::from_asm(r0) +} + +#[inline] +pub(in crate::backend) unsafe fn syscall3( + nr: SyscallNumber<'_>, + a0: ArgReg<'_, A0>, + a1: ArgReg<'_, A1>, + a2: ArgReg<'_, A2>, +) -> RetReg { + let r0; + asm!( + "syscall 0", + in("$a7") nr.to_asm(), + inlateout("$a0") a0.to_asm() => r0, + in("$a1") a1.to_asm(), + in("$a2") a2.to_asm(), + options(nostack, preserves_flags) + ); + FromAsm::from_asm(r0) +} + +#[inline] +pub(in crate::backend) unsafe fn syscall3_readonly( + nr: SyscallNumber<'_>, + a0: ArgReg<'_, A0>, + a1: ArgReg<'_, A1>, + a2: ArgReg<'_, A2>, +) -> RetReg { + let r0; + asm!( + "syscall 0", + in("$a7") nr.to_asm(), + inlateout("$a0") a0.to_asm() => r0, + in("$a1") a1.to_asm(), + in("$a2") a2.to_asm(), + options(nostack, preserves_flags, readonly) + ); + FromAsm::from_asm(r0) +} + +#[inline] +pub(in crate::backend) unsafe fn syscall4( + nr: SyscallNumber<'_>, + a0: ArgReg<'_, A0>, + a1: ArgReg<'_, A1>, + a2: ArgReg<'_, A2>, + a3: ArgReg<'_, A3>, +) -> RetReg { + let r0; + asm!( + "syscall 0", + in("$a7") nr.to_asm(), + inlateout("$a0") a0.to_asm() => r0, + in("$a1") a1.to_asm(), + in("$a2") a2.to_asm(), + in("$a3") a3.to_asm(), + options(nostack, preserves_flags) + ); + FromAsm::from_asm(r0) +} + +#[inline] +pub(in crate::backend) unsafe fn syscall4_readonly( + nr: SyscallNumber<'_>, + a0: ArgReg<'_, A0>, + a1: ArgReg<'_, A1>, + a2: ArgReg<'_, A2>, + a3: ArgReg<'_, A3>, +) -> RetReg { + let r0; + asm!( + "syscall 0", + in("$a7") nr.to_asm(), + inlateout("$a0") a0.to_asm() => r0, + in("$a1") a1.to_asm(), + in("$a2") a2.to_asm(), + in("$a3") a3.to_asm(), + options(nostack, preserves_flags, readonly) + ); + FromAsm::from_asm(r0) +} + +#[inline] +pub(in crate::backend) unsafe fn syscall5( + nr: SyscallNumber<'_>, + a0: ArgReg<'_, A0>, + a1: ArgReg<'_, A1>, + a2: ArgReg<'_, A2>, + a3: ArgReg<'_, A3>, + a4: ArgReg<'_, A4>, +) -> RetReg { + let r0; + asm!( + "syscall 0", + in("$a7") nr.to_asm(), + inlateout("$a0") a0.to_asm() => r0, + in("$a1") a1.to_asm(), + in("$a2") a2.to_asm(), + in("$a3") a3.to_asm(), + in("$a4") a4.to_asm(), + options(nostack, preserves_flags) + ); + FromAsm::from_asm(r0) +} + +#[inline] +pub(in crate::backend) unsafe fn syscall5_readonly( + nr: SyscallNumber<'_>, + a0: ArgReg<'_, A0>, + a1: ArgReg<'_, A1>, + a2: ArgReg<'_, A2>, + a3: ArgReg<'_, A3>, + a4: ArgReg<'_, A4>, +) -> RetReg { + let r0; + asm!( + "syscall 0", + in("$a7") nr.to_asm(), + inlateout("$a0") a0.to_asm() => r0, + in("$a1") a1.to_asm(), + in("$a2") a2.to_asm(), + in("$a3") a3.to_asm(), + in("$a4") a4.to_asm(), + options(nostack, preserves_flags, readonly) + ); + FromAsm::from_asm(r0) +} + +#[inline] +pub(in crate::backend) unsafe fn syscall6( + nr: SyscallNumber<'_>, + a0: ArgReg<'_, A0>, + a1: ArgReg<'_, A1>, + a2: ArgReg<'_, A2>, + a3: ArgReg<'_, A3>, + a4: ArgReg<'_, A4>, + a5: ArgReg<'_, A5>, +) -> RetReg { + let r0; + asm!( + "syscall 0", + in("$a7") nr.to_asm(), + inlateout("$a0") a0.to_asm() => r0, + in("$a1") a1.to_asm(), + in("$a2") a2.to_asm(), + in("$a3") a3.to_asm(), + in("$a4") a4.to_asm(), + in("$a5") a5.to_asm(), + options(nostack, preserves_flags) + ); + FromAsm::from_asm(r0) +} + +#[inline] +pub(in crate::backend) unsafe fn syscall6_readonly( + nr: SyscallNumber<'_>, + a0: ArgReg<'_, A0>, + a1: ArgReg<'_, A1>, + a2: ArgReg<'_, A2>, + a3: ArgReg<'_, A3>, + a4: ArgReg<'_, A4>, + a5: ArgReg<'_, A5>, +) -> RetReg { + let r0; + asm!( + "syscall 0", + in("$a7") nr.to_asm(), + inlateout("$a0") a0.to_asm() => r0, + in("$a1") a1.to_asm(), + in("$a2") a2.to_asm(), + in("$a3") a3.to_asm(), + in("$a4") a4.to_asm(), + in("$a5") a5.to_asm(), + options(nostack, preserves_flags, readonly) + ); + FromAsm::from_asm(r0) +} diff --git a/src/backend/linux_raw/arch/mod.rs b/src/backend/linux_raw/arch/mod.rs index ac9e25fa7..2d68fe4b5 100644 --- a/src/backend/linux_raw/arch/mod.rs +++ b/src/backend/linux_raw/arch/mod.rs @@ -41,6 +41,7 @@ pub(in crate::backend) mod asm; #[cfg(any( target_arch = "arm", target_arch = "aarch64", + target_arch = "loongarch64", target_arch = "mips", target_arch = "mips32r6", target_arch = "mips64", diff --git a/src/backend/linux_raw/conv.rs b/src/backend/linux_raw/conv.rs index ab85c130f..625019866 100644 --- a/src/backend/linux_raw/conv.rs +++ b/src/backend/linux_raw/conv.rs @@ -235,7 +235,11 @@ pub(super) fn opt_mut(t: Option<&mut T>) -> ArgReg<'_, /// Convert an optional immutable reference into a `usize` for passing to a /// syscall. -#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))] +#[cfg(any( + target_arch = "aarch64", + target_arch = "loongarch64", + target_arch = "riscv64" +))] #[inline] pub(super) fn opt_ref(t: Option<&T>) -> ArgReg<'_, Num> { // This optimizes into the equivalent of `transmute(t)`, and has the diff --git a/src/backend/linux_raw/fs/dir.rs b/src/backend/linux_raw/fs/dir.rs index a8c9a5576..a6066ce11 100644 --- a/src/backend/linux_raw/fs/dir.rs +++ b/src/backend/linux_raw/fs/dir.rs @@ -1,8 +1,8 @@ use crate::fd::{AsFd, BorrowedFd, OwnedFd}; use crate::ffi::{CStr, CString}; -use crate::fs::{ - fcntl_getfl, fstat, fstatfs, fstatvfs, openat, FileType, Mode, OFlags, Stat, StatFs, StatVfs, -}; +use crate::fs::{fcntl_getfl, fstatfs, fstatvfs, openat, FileType, Mode, OFlags, StatFs, StatVfs}; +#[cfg(not(target_arch = "loongarch64"))] +use crate::fs::{fstat, Stat}; use crate::io; #[cfg(feature = "process")] use crate::process::fchdir; @@ -215,6 +215,7 @@ impl Dir { } /// `fstat(self)` + #[cfg(not(target_arch = "loongarch64"))] #[inline] pub fn stat(&self) -> io::Result { fstat(&self.fd) diff --git a/src/backend/linux_raw/fs/syscalls.rs b/src/backend/linux_raw/fs/syscalls.rs index b6cf6b7b4..e12426d99 100644 --- a/src/backend/linux_raw/fs/syscalls.rs +++ b/src/backend/linux_raw/fs/syscalls.rs @@ -14,6 +14,7 @@ use crate::backend::conv::fs::oflags_for_open_how; target_arch = "riscv64", target_arch = "mips", target_arch = "mips32r6", + target_arch = "loongarch64", ))] use crate::backend::conv::zero; use crate::backend::conv::{ @@ -27,6 +28,7 @@ use crate::backend::conv::{loff_t, loff_t_from_u64, ret_u64}; target_arch = "riscv64", target_arch = "mips64", target_arch = "mips64r6", + target_arch = "loongarch64", target_pointer_width = "32", ))] use crate::fd::AsFd; @@ -34,6 +36,8 @@ use crate::fd::{BorrowedFd, OwnedFd}; use crate::ffi::CStr; #[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))] use crate::fs::CWD; +[cfg(not(target_arch = "loongarch64"))] +use crate::fs::Stat; use crate::fs::{ inotify, Access, Advice, AtFlags, FallocateFlags, FileType, FlockOperation, Gid, MemfdFlags, Mode, OFlags, RenameFlags, ResolveFlags, SealFlags, SeekFrom, Stat, StatFs, StatVfs, @@ -470,6 +474,7 @@ pub(crate) fn sync() { unsafe { ret_infallible(syscall_readonly!(__NR_sync)) } } +#[cfg(not(target_arch = "loongarch64"))] #[inline] pub(crate) fn fstat(fd: BorrowedFd<'_>) -> io::Result { // 32-bit and mips64 Linux: `struct stat64` is not y2038 compatible; use @@ -524,6 +529,7 @@ fn fstat_old(fd: BorrowedFd<'_>) -> io::Result { } } +#[cfg(not(target_arch = "loongarch64"))] #[inline] pub(crate) fn stat(path: &CStr) -> io::Result { // See the comments in `fstat` about using `crate::fs::statx` here. @@ -596,6 +602,7 @@ fn stat_old(path: &CStr) -> io::Result { } } +#[cfg(not(target_arch = "loongarch64"))] #[inline] pub(crate) fn statat(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::Result { // See the comments in `fstat` about using `crate::fs::statx` here. @@ -645,6 +652,7 @@ fn statat_old(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::Result< } } +#[cfg(not(target_arch = "loongarch64"))] #[inline] pub(crate) fn lstat(path: &CStr) -> io::Result { // See the comments in `fstat` about using `crate::fs::statx` here. @@ -1092,7 +1100,7 @@ pub(crate) fn fcntl_lock(fd: BorrowedFd<'_>, operation: FlockOperation) -> io::R #[inline] pub(crate) fn rename(old_path: &CStr, new_path: &CStr) -> io::Result<()> { - #[cfg(target_arch = "riscv64")] + #[cfg(any(target_arch = "riscv64", target_arch = "loongarch64"))] unsafe { ret(syscall_readonly!( __NR_renameat2, @@ -1103,7 +1111,7 @@ pub(crate) fn rename(old_path: &CStr, new_path: &CStr) -> io::Result<()> { c_uint(0) )) } - #[cfg(not(target_arch = "riscv64"))] + #[cfg(not(any(target_arch = "riscv64", target_arch = "loongarch64")))] unsafe { ret(syscall_readonly!( __NR_renameat, @@ -1122,7 +1130,7 @@ pub(crate) fn renameat( new_dirfd: BorrowedFd<'_>, new_path: &CStr, ) -> io::Result<()> { - #[cfg(target_arch = "riscv64")] + #[cfg(any(target_arch = "loongarch64", target_arch = "riscv64"))] unsafe { ret(syscall_readonly!( __NR_renameat2, @@ -1133,7 +1141,7 @@ pub(crate) fn renameat( c_uint(0) )) } - #[cfg(not(target_arch = "riscv64"))] + #[cfg(not(any(target_arch = "loongarch64", target_arch = "riscv64")))] unsafe { ret(syscall_readonly!( __NR_renameat, diff --git a/src/backend/linux_raw/fs/types.rs b/src/backend/linux_raw/fs/types.rs index 201ed9169..4a468d115 100644 --- a/src/backend/linux_raw/fs/types.rs +++ b/src/backend/linux_raw/fs/types.rs @@ -684,7 +684,8 @@ pub struct Stat { #[cfg(all( target_pointer_width = "64", not(target_arch = "mips64"), - not(target_arch = "mips64r6") + not(target_arch = "mips64r6"), + not(target_arch = "loongarch64") ))] pub type Stat = linux_raw_sys::general::stat; diff --git a/src/backend/linux_raw/io/syscalls.rs b/src/backend/linux_raw/io/syscalls.rs index c38f28fce..894eed5d5 100644 --- a/src/backend/linux_raw/io/syscalls.rs +++ b/src/backend/linux_raw/io/syscalls.rs @@ -310,7 +310,11 @@ pub(crate) fn dup(fd: BorrowedFd<'_>) -> io::Result { #[allow(clippy::needless_pass_by_ref_mut)] #[inline] pub(crate) fn dup2(fd: BorrowedFd<'_>, new: &mut OwnedFd) -> io::Result<()> { - #[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))] + #[cfg(any( + target_arch = "aarch64", + target_arch = "loongarch64", + target_arch = "riscv64" + ))] { // We don't need to worry about the difference between `dup2` and // `dup3` when the file descriptors are equal because we have an @@ -318,7 +322,11 @@ pub(crate) fn dup2(fd: BorrowedFd<'_>, new: &mut OwnedFd) -> io::Result<()> { dup3(fd, new, DupFlags::empty()) } - #[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))] + #[cfg(not(any( + target_arch = "aarch64", + target_arch = "loongarch64", + target_arch = "riscv64" + )))] unsafe { ret_discarded_fd(syscall_readonly!(__NR_dup2, fd, new.as_fd())) } diff --git a/src/backend/linux_raw/net/syscalls.rs b/src/backend/linux_raw/net/syscalls.rs index 4d4427a40..20595fe03 100644 --- a/src/backend/linux_raw/net/syscalls.rs +++ b/src/backend/linux_raw/net/syscalls.rs @@ -465,6 +465,7 @@ pub(crate) fn send(fd: BorrowedFd<'_>, buf: &[u8], flags: SendFlags) -> io::Resu #[cfg(not(any( target_arch = "aarch64", + target_arch = "loongarch64", target_arch = "mips64", target_arch = "mips64r6", target_arch = "riscv64", @@ -476,6 +477,7 @@ pub(crate) fn send(fd: BorrowedFd<'_>, buf: &[u8], flags: SendFlags) -> io::Resu } #[cfg(any( target_arch = "aarch64", + target_arch = "loongarch64", target_arch = "mips64", target_arch = "mips64r6", target_arch = "riscv64", @@ -669,6 +671,7 @@ pub(crate) unsafe fn recv( ) -> io::Result { #[cfg(not(any( target_arch = "aarch64", + target_arch = "loongarch64", target_arch = "mips64", target_arch = "mips64r6", target_arch = "riscv64", @@ -680,6 +683,7 @@ pub(crate) unsafe fn recv( } #[cfg(any( target_arch = "aarch64", + target_arch = "loongarch64", target_arch = "mips64", target_arch = "mips64r6", target_arch = "riscv64", diff --git a/src/backend/linux_raw/process/syscalls.rs b/src/backend/linux_raw/process/syscalls.rs index fb900a4d3..69f273006 100644 --- a/src/backend/linux_raw/process/syscalls.rs +++ b/src/backend/linux_raw/process/syscalls.rs @@ -148,7 +148,11 @@ pub(crate) fn setpgid(pid: Option, pgid: Option) -> io::Result<()> { #[inline] pub(crate) fn getpgrp() -> Pid { // Use the `getpgrp` syscall if available. - #[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))] + #[cfg(not(any( + target_arch = "aarch64", + target_arch = "loongarch64", + target_arch = "riscv64" + )))] unsafe { let pgid = ret_c_int_infallible(syscall_readonly!(__NR_getpgrp)); debug_assert!(pgid > 0); @@ -156,7 +160,11 @@ pub(crate) fn getpgrp() -> Pid { } // Otherwise use `getpgrp` and pass it zero. - #[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))] + #[cfg(any( + target_arch = "aarch64", + target_arch = "loongarch64", + target_arch = "riscv64" + ))] unsafe { let pgid = ret_c_int_infallible(syscall_readonly!(__NR_getpgid, c_uint(0))); debug_assert!(pgid > 0); @@ -295,6 +303,7 @@ pub(crate) fn setpriority_process(pid: Option, priority: i32) -> io::Result } } +#[cfg(not(target_arch = "loongarch64"))] #[inline] pub(crate) fn getrlimit(limit: Resource) -> Rlimit { let mut result = MaybeUninit::::uninit(); @@ -310,6 +319,7 @@ pub(crate) fn getrlimit(limit: Resource) -> Rlimit { } } +#[cfg(not(target_arch = "loongarch64"))] #[inline] pub(crate) fn setrlimit(limit: Resource, new: Rlimit) -> io::Result<()> { unsafe { diff --git a/src/backend/linux_raw/vdso_wrappers.rs b/src/backend/linux_raw/vdso_wrappers.rs index 441738f8d..4b9235a8e 100644 --- a/src/backend/linux_raw/vdso_wrappers.rs +++ b/src/backend/linux_raw/vdso_wrappers.rs @@ -510,6 +510,8 @@ fn init() { let ptr = vdso.sym(cstr!("LINUX_2.6"), cstr!("__vdso_clock_gettime64")); #[cfg(any(target_arch = "mips64", target_arch = "mips64r6"))] let ptr = vdso.sym(cstr!("LINUX_2.6"), cstr!("__vdso_clock_gettime")); + #[cfg(target_arch = "loongarch64")] + let ptr = vdso.sym(cstr!("LINUX_5.10"), cstr!("__vdso_clock_gettime")); // On all 64-bit platforms, the 64-bit `clock_gettime` symbols are // always available. diff --git a/src/fs/at.rs b/src/fs/at.rs index f1c49a93b..4ea74d951 100644 --- a/src/fs/at.rs +++ b/src/fs/at.rs @@ -15,7 +15,7 @@ use crate::fs::AtFlags; use crate::fs::CloneFlags; #[cfg(linux_kernel)] use crate::fs::RenameFlags; -#[cfg(not(target_os = "espidf"))] +#[cfg(not(any(target_os = "espidf", target_arch = "loongarch64")))] use crate::fs::Stat; #[cfg(not(any(apple, target_os = "espidf", target_os = "vita", target_os = "wasi")))] use crate::fs::{Dev, FileType}; diff --git a/src/fs/fd.rs b/src/fs/fd.rs index 1aa0e6352..4c9f22146 100644 --- a/src/fs/fd.rs +++ b/src/fs/fd.rs @@ -26,6 +26,7 @@ use backend::fs::types::FallocateFlags; use backend::fs::types::FlockOperation; #[cfg(linux_kernel)] use backend::fs::types::FsWord; +#[cfg(not(target_arch = "loongarch64"))] use backend::fs::types::Stat; #[cfg(not(any( solarish, @@ -161,6 +162,7 @@ pub fn fchown(fd: Fd, owner: Option, group: Option) -> io::R /// [Linux]: https://man7.org/linux/man-pages/man2/fstat.2.html /// [`Mode::from_raw_mode`]: Mode::from_raw_mode /// [`FileType::from_raw_mode`]: crate::fs::FileType::from_raw_mode +#[cfg(not(target_arch = "loongarch64"))] #[inline] pub fn fstat(fd: Fd) -> io::Result { backend::fs::syscalls::fstat(fd.as_fd()) diff --git a/src/process/rlimit.rs b/src/process/rlimit.rs index ea760c22f..1bdd62047 100644 --- a/src/process/rlimit.rs +++ b/src/process/rlimit.rs @@ -22,6 +22,7 @@ pub struct Rlimit { /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getrlimit.html /// [Linux]: https://man7.org/linux/man-pages/man2/getrlimit.2.html +#[cfg(not(target_arch = "loongarch64"))] #[inline] pub fn getrlimit(resource: Resource) -> Rlimit { backend::process::syscalls::getrlimit(resource) @@ -35,6 +36,7 @@ pub fn getrlimit(resource: Resource) -> Rlimit { /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setrlimit.html /// [Linux]: https://man7.org/linux/man-pages/man2/setrlimit.2.html +#[cfg(not(target_arch = "loongarch64"))] #[inline] pub fn setrlimit(resource: Resource, new: Rlimit) -> io::Result<()> { backend::process::syscalls::setrlimit(resource, new) diff --git a/tests/process/rlimit.rs b/tests/process/rlimit.rs index da191b677..c9e377af4 100644 --- a/tests/process/rlimit.rs +++ b/tests/process/rlimit.rs @@ -2,6 +2,7 @@ use rustix::process::Resource; #[cfg(not(target_os = "haiku"))] // No `Core` on Haiku. use rustix::process::Rlimit; +#[cfg(not(target_arch = "loongarch64"))] // No `getrlimit` on LoongArch64. #[test] fn test_getrlimit() { let lim = rustix::process::getrlimit(Resource::Stack); @@ -9,7 +10,8 @@ fn test_getrlimit() { assert_ne!(lim.maximum, Some(0)); } -#[cfg(not(target_os = "haiku"))] // No `Core` on Haiku. +/// No 'Core' on HaiKu. No setrlimit on LoongArch64 +#[cfg(not(any(target_os = "haiku", target_arch = "loongarch64")))] #[test] fn test_setrlimit() { let old = rustix::process::getrlimit(Resource::Core);