-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[libc] Enable utimes function for riscv #139181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
+20
−8
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RV32 uses SYS_utimensat_time64 instead of SYS_utimensat but the call is the same.
@llvm/pr-subscribers-libc Author: Mikhail R. Gadelha (mikhailramalho) ChangesRV32 uses SYS_utimensat_time64 instead of SYS_utimensat but the call is the same. Full diff: https://github.com/llvm/llvm-project/pull/139181.diff 3 Files Affected:
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 30d9d00dfefc9..0ee53e26a9286 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -290,7 +290,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.sys.statvfs.statvfs
# sys/utimes.h entrypoints
- # libc.src.sys.time.utimes
+ libc.src.sys.time.utimes
# sys/utsname.h entrypoints
libc.src.sys.utsname.uname
diff --git a/libc/include/sys/syscall.h.def b/libc/include/sys/syscall.h.def
index 03c19eb0885ed..6f309c8bab331 100644
--- a/libc/include/sys/syscall.h.def
+++ b/libc/include/sys/syscall.h.def
@@ -2301,6 +2301,10 @@
#define SYS_utimes __NR_utimes
#endif
+#ifdef __NR_utimensat_time64
+#define SYS_utimensat_time64 __NR_utimensat_time64
+#endif
+
#ifdef __NR_utrap_install
#define SYS_utrap_install __NR_utrap_install
#endif
diff --git a/libc/src/sys/time/linux/utimes.cpp b/libc/src/sys/time/linux/utimes.cpp
index e6e3d073a81a4..aed04160d5f9d 100644
--- a/libc/src/sys/time/linux/utimes.cpp
+++ b/libc/src/sys/time/linux/utimes.cpp
@@ -10,6 +10,7 @@
#include "hdr/fcntl_macros.h"
#include "hdr/types/struct_timeval.h"
+#include "hdr/types/struct_timespec.h"
#include "src/__support/OSUtil/syscall.h"
#include "src/__support/common.h"
@@ -20,14 +21,24 @@
namespace LIBC_NAMESPACE_DECL {
+#if SYS_utimes
+constexpr auto UTIMES_SYSCALL_ID = SYS_utimes;
+#elif defined(SYS_utimensat)
+constexpr auto UTIMES_SYSCALL_ID = SYS_utimensat;
+#elif defined(SYS_utimensat_time64)
+constexpr auto UTIMES_SYSCALL_ID = SYS_utimensat_time64;
+#else
+#error "utimes, utimensat, utimensat_time64, syscalls not available."
+#endif
+
LLVM_LIBC_FUNCTION(int, utimes,
(const char *path, const struct timeval times[2])) {
int ret;
#ifdef SYS_utimes
// No need to define a timespec struct, use the syscall directly.
- ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_utimes, path, times);
-#elif defined(SYS_utimensat)
+ ret = LIBC_NAMESPACE::syscall_impl<int>(UTIMES_SYSCALL_ID, path, times);
+#elif defined(SYS_utimensat) || defined(SYS_utimensat_time64)
// the utimensat syscall requires a timespec struct, not timeval.
struct timespec ts[2];
struct timespec *ts_ptr = nullptr; // default value if times is nullptr
@@ -59,11 +70,8 @@ LLVM_LIBC_FUNCTION(int, utimes,
// utimensat syscall.
// flags=0 means don't follow symlinks (like utimes)
- ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_utimensat, AT_FDCWD, path, ts_ptr,
- 0);
-
-#else
-#error "utimensat and utimes syscalls not available."
+ ret = LIBC_NAMESPACE::syscall_impl<int>(UTIMES_SYSCALL_ID, AT_FDCWD, path,
+ ts_ptr, 0);
#endif // SYS_utimensat
if (ret < 0) {
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
Signed-off-by: Mikhail R. Gadelha <[email protected]>
lntue
reviewed
May 9, 2025
Signed-off-by: Mikhail R. Gadelha <[email protected]>
lntue
approved these changes
May 13, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
RV32 uses SYS_utimensat_time64 instead of SYS_utimensat but the call is the same.