llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-libc Author: Connector Switch (c8ef) <details> <summary>Changes</summary> This PR move the Linux Dir helpers behind the centralized syscall wrappers, following libc/docs/dev/syscall_wrapper_refactor.md. --- Full diff: https://github.com/llvm/llvm-project/pull/242254.diff 5 Files Affected: - (modified) libc/src/__support/File/linux/CMakeLists.txt (+2-2) - (modified) libc/src/__support/File/linux/dir.cpp (+2-11) - (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt (+13) - (added) libc/src/__support/OSUtil/linux/syscall_wrappers/getdents64.h (+38) - (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+16) ``````````diff diff --git a/libc/src/__support/File/linux/CMakeLists.txt b/libc/src/__support/File/linux/CMakeLists.txt index be5f0c4d2a154..8ae1757f69d87 100644 --- a/libc/src/__support/File/linux/CMakeLists.txt +++ b/libc/src/__support/File/linux/CMakeLists.txt @@ -53,10 +53,10 @@ add_object_library( libc.hdr.fcntl_macros libc.hdr.sys_stat_macros libc.src.__support.OSUtil.linux.stat.kernel_statx_types - libc.src.__support.OSUtil.osutil libc.src.__support.OSUtil.linux.syscall_wrappers.close - libc.src.__support.OSUtil.linux.syscall_wrappers.open libc.src.__support.OSUtil.linux.syscall_wrappers.fcntl + libc.src.__support.OSUtil.linux.syscall_wrappers.getdents64 + libc.src.__support.OSUtil.linux.syscall_wrappers.open libc.src.__support.OSUtil.linux.syscall_wrappers.statx libc.src.__support.error_or libc.src.__support.File.dir diff --git a/libc/src/__support/File/linux/dir.cpp b/libc/src/__support/File/linux/dir.cpp index 2b6bb4b0b6c5b..e5064cde6cc36 100644 --- a/libc/src/__support/File/linux/dir.cpp +++ b/libc/src/__support/File/linux/dir.cpp @@ -17,9 +17,9 @@ #include "src/__support/OSUtil/linux/stat/kernel_statx_types.h" #include "src/__support/OSUtil/linux/syscall_wrappers/close.h" #include "src/__support/OSUtil/linux/syscall_wrappers/fcntl.h" +#include "src/__support/OSUtil/linux/syscall_wrappers/getdents64.h" #include "src/__support/OSUtil/linux/syscall_wrappers/open.h" #include "src/__support/OSUtil/linux/syscall_wrappers/statx.h" -#include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/error_or.h" #include "src/__support/macros/config.h" @@ -30,16 +30,7 @@ ErrorOr<int> platform_opendir(const char *name) { } ErrorOr<size_t> platform_fetch_dirents(int fd, cpp::span<uint8_t> buffer) { -#ifdef SYS_getdents64 - long size = LIBC_NAMESPACE::syscall_impl<long>(SYS_getdents64, fd, - buffer.data(), buffer.size()); -#else -#error "getdents64 syscalls not available to perform a fetch dirents operation." -#endif - - if (size < 0) - return LIBC_NAMESPACE::Error(static_cast<int>(-size)); - return size; + return linux_syscalls::getdents64(fd, buffer.data(), buffer.size()); } int platform_closedir(int fd) { diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt index cfd4d1e25aba1..a59095fa8d802 100644 --- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt +++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt @@ -13,6 +13,19 @@ add_header_library( libc.src.__support.macros.config ) +add_header_library( + getdents64 + HDRS + getdents64.h + DEPENDS + libc.hdr.types.size_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( getrandom HDRS diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/getdents64.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/getdents64.h new file mode 100644 index 0000000000000..b14483881f14c --- /dev/null +++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/getdents64.h @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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 getdents64. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_GETDENTS64_H +#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_GETDENTS64_H + +#include "hdr/types/size_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<size_t> getdents64(int fd, void *buffer, size_t count) { +#ifdef SYS_getdents64 + return syscall_checked<size_t>(SYS_getdents64, fd, buffer, count); +#else +#error "getdents64 syscalls not available to perform a fetch dirents operation." +#endif +} + +} // namespace linux_syscalls +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_GETDENTS64_H diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel index 3be110a1c7da4..42b28b1c01fb2 100644 --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -3533,6 +3533,22 @@ libc_support_library( ], ) +libc_support_library( + name = "__support_osutil_linux_syscall_wrappers_getdents64", + hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/getdents64.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_size_t", + ], +) + libc_support_library( name = "__support_osutil_linux_syscall_wrappers_geteuid", hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/geteuid.h"], `````````` </details> https://github.com/llvm/llvm-project/pull/242254 _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
