https://github.com/c8ef created https://github.com/llvm/llvm-project/pull/241768
This PR move fchown behind the centralized syscall wrappers, following libc/docs/dev/syscall_wrapper_refactor.md. >From eccb24ddf1a9e4d752654bb25aabf81e13859b22 Mon Sep 17 00:00:00 2001 From: c8ef <[email protected]> Date: Thu, 12 Nov 2026 18:25:37 +0800 Subject: [PATCH] [libc] Use a syscall wrapper for fchown --- .../linux/syscall_wrappers/CMakeLists.txt | 14 ++++++++ .../OSUtil/linux/syscall_wrappers/fchown.h | 35 ++++++++++++++++++ libc/src/unistd/linux/CMakeLists.txt | 8 +++-- libc/src/unistd/linux/fchown.cpp | 19 +++++----- .../llvm-project-overlay/libc/BUILD.bazel | 36 +++++++++++++++++++ 5 files changed, 100 insertions(+), 12 deletions(-) create mode 100644 libc/src/__support/OSUtil/linux/syscall_wrappers/fchown.h diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt index 7fd9991be0e16f..a8250b57599e7d 100644 --- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt +++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt @@ -1221,6 +1221,20 @@ add_header_library( libc.src.__support.macros.config ) +add_header_library( + fchown + HDRS + fchown.h + DEPENDS + libc.hdr.types.gid_t + libc.hdr.types.uid_t + libc.include.sys_syscall + libc.src.__support.OSUtil.osutil + libc.src.__support.common + libc.src.__support.error_or + libc.src.__support.macros.config +) + add_header_library( fchownat HDRS diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/fchown.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/fchown.h new file mode 100644 index 00000000000000..a7d8f396a9850c --- /dev/null +++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/fchown.h @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// Syscall wrapper for fchown. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_FCHOWN_H +#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_FCHOWN_H + +#include "hdr/types/gid_t.h" +#include "hdr/types/uid_t.h" +#include "src/__support/OSUtil/linux/syscall.h" // syscall_checked +#include "src/__support/common.h" +#include "src/__support/error_or.h" +#include "src/__support/macros/config.h" +#include <sys/syscall.h> // For syscall numbers. + +namespace LIBC_NAMESPACE_DECL { +namespace linux_syscalls { + +LIBC_INLINE ErrorOr<int> fchown(int fildes, uid_t owner, gid_t group) { + return syscall_checked<int>(SYS_fchown, fildes, owner, group); +} + +} // namespace linux_syscalls +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_FCHOWN_H diff --git a/libc/src/unistd/linux/CMakeLists.txt b/libc/src/unistd/linux/CMakeLists.txt index 5a44bbd3d9caac..747ef41278eb88 100644 --- a/libc/src/unistd/linux/CMakeLists.txt +++ b/libc/src/unistd/linux/CMakeLists.txt @@ -164,10 +164,12 @@ add_entrypoint_object( HDRS ../fchown.h DEPENDS - libc.hdr.types.uid_t libc.hdr.types.gid_t - libc.include.sys_syscall - libc.src.__support.OSUtil.osutil + libc.hdr.types.uid_t + libc.src.__support.OSUtil.linux.syscall_wrappers.fchown + libc.src.__support.common + libc.src.__support.libc_errno + libc.src.__support.macros.config libc.src.errno.errno ) diff --git a/libc/src/unistd/linux/fchown.cpp b/libc/src/unistd/linux/fchown.cpp index 9cf3d139050c13..b7e1b62902df39 100644 --- a/libc/src/unistd/linux/fchown.cpp +++ b/libc/src/unistd/linux/fchown.cpp @@ -1,28 +1,29 @@ -//===-- Linux implementation of fchown ------------------------------------===// +//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// +/// +/// \file +/// Linux implementation for fchown. +/// +//===----------------------------------------------------------------------===// #include "src/unistd/fchown.h" -#include "src/__support/OSUtil/syscall.h" // For internal syscall function. +#include "src/__support/OSUtil/linux/syscall_wrappers/fchown.h" #include "src/__support/common.h" - -#include "hdr/types/gid_t.h" -#include "hdr/types/uid_t.h" #include "src/__support/libc_errno.h" #include "src/__support/macros/config.h" -#include <sys/syscall.h> // For syscall numbers. namespace LIBC_NAMESPACE_DECL { LLVM_LIBC_FUNCTION(int, fchown, (int fildes, uid_t owner, gid_t group)) { - int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_fchown, fildes, owner, group); - if (ret < 0) { - libc_errno = -ret; + auto result = linux_syscalls::fchown(fildes, owner, group); + if (!result) { + libc_errno = result.error(); return -1; } return 0; diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel index a1cc803e9b35e8..e58ab7294982eb 100644 --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -2833,6 +2833,23 @@ libc_support_library( ], ) +libc_support_library( + name = "__support_osutil_linux_syscall_wrappers_fchown", + hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/fchown.h"], + target_compatible_with = select({ + "@platforms//os:linux": [], + "//conditions:default": ["@platforms//:incompatible"], + }), + deps = [ + ":__support_common", + ":__support_error_or", + ":__support_macros_config", + ":__support_osutil_syscall", + ":types_gid_t", + ":types_uid_t", + ], +) + libc_support_library( name = "__support_osutil_linux_syscall_wrappers_ftruncate", hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/ftruncate.h"], @@ -18845,6 +18862,25 @@ libc_function( ], ) +libc_function( + name = "fchown", + srcs = ["src/unistd/linux/fchown.cpp"], + hdrs = ["src/unistd/fchown.h"], + target_compatible_with = select({ + "@platforms//os:linux": [], + "//conditions:default": ["@platforms//:incompatible"], + }), + deps = [ + ":__support_common", + ":__support_libc_errno", + ":__support_macros_config", + ":__support_osutil_linux_syscall_wrappers_fchown", + ":errno", + ":types_gid_t", + ":types_uid_t", + ], +) + libc_function( name = "fsync", srcs = ["src/unistd/linux/fsync.cpp"], _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
