[libc-commits] [libc] [libc] adding linux SYS_fchmodat2 syscall. (PR #89819)
David CARLIER via libc-commits
libc-commits at lists.llvm.org
Tue Apr 23 14:20:39 PDT 2024
https://github.com/devnexen updated https://github.com/llvm/llvm-project/pull/89819
>From 5a9be672ccf186d512f86a9e01f29b12560399a5 Mon Sep 17 00:00:00 2001
From: David Carlier <devnexen at gmail.com>
Date: Tue, 23 Apr 2024 21:00:28 +0100
Subject: [PATCH] [libc] adding linux SYS_fchmodat2 syscall.
SYS_fchmodat2 syscall had been available since Linux 6.6, being more
flexible than SYS_fchmodat to support AT_SYMLINK_NOFOLLOW.
---
libc/config/linux/syscall_numbers.h.inc | 4 ++++
libc/src/sys/stat/linux/chmod.cpp | 7 +++++--
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/libc/config/linux/syscall_numbers.h.inc b/libc/config/linux/syscall_numbers.h.inc
index 9f910c5f9042a8..4a19d9a08875e8 100644
--- a/libc/config/linux/syscall_numbers.h.inc
+++ b/libc/config/linux/syscall_numbers.h.inc
@@ -338,6 +338,10 @@
#define SYS_fchmodat __NR_fchmodat
#endif
+#ifdef __NR_fchmodat2
+#define SYS_fchmodat2 __NR_fchmodat2
+#endif
+
#ifdef __NR_fchown
#define SYS_fchown __NR_fchown
#endif
diff --git a/libc/src/sys/stat/linux/chmod.cpp b/libc/src/sys/stat/linux/chmod.cpp
index 085b91691d89f4..5689f87cefd6cb 100644
--- a/libc/src/sys/stat/linux/chmod.cpp
+++ b/libc/src/sys/stat/linux/chmod.cpp
@@ -21,11 +21,14 @@ namespace LIBC_NAMESPACE {
LLVM_LIBC_FUNCTION(int, chmod, (const char *path, mode_t mode)) {
#ifdef SYS_chmod
int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_chmod, path, mode);
+#elif defined(SYS_fchmodat2)
+ int ret =
+ LIBC_NAMESPACE::syscall_impl<int>(SYS_fchmodat2, AT_FDCWD, path, mode, 0, AT_SYMLINK_NOFOLLOW);
#elif defined(SYS_fchmodat)
int ret =
- LIBC_NAMESPACE::syscall_impl<int>(SYS_fchmodat, AT_FDCWD, path, mode);
+ LIBC_NAMESPACE::syscall_impl<int>(SYS_fchmodat, AT_FDCWD, path, mode, 0);
#else
-#error "chmod and fchmodat syscalls not available."
+#error "chmod, fchmodat and fchmodat2 syscalls not available."
#endif
if (ret < 0) {
More information about the libc-commits
mailing list