https://github.com/c8ef created https://github.com/llvm/llvm-project/pull/240782
This PR move getgid behind the centralized syscall wrappers, following libc/docs/dev/syscall_wrapper_refactor.md. >From 8c1671dbab031e12cdcdc4651dab409de053015a Mon Sep 17 00:00:00 2001 From: c8ef <[email protected]> Date: Tue, 10 Nov 2026 18:45:36 +0800 Subject: [PATCH] [libc] Use a syscall wrapper for getgid This PR move getgid behind the centralized syscall wrappers, following libc/docs/dev/syscall_wrapper_refactor.md. --- .../linux/syscall_wrappers/CMakeLists.txt | 12 +++++++ .../OSUtil/linux/syscall_wrappers/getgid.h | 31 +++++++++++++++++++ libc/src/unistd/linux/CMakeLists.txt | 8 ++--- libc/src/unistd/linux/getgid.cpp | 15 ++++----- .../llvm-project-overlay/libc/BUILD.bazel | 17 +++++++++- 5 files changed, 71 insertions(+), 12 deletions(-) create mode 100644 libc/src/__support/OSUtil/linux/syscall_wrappers/getgid.h diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt index 8685253f2081b3..71929438e70092 100644 --- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt +++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt @@ -26,6 +26,18 @@ add_header_library( libc.include.sys_syscall ) +add_header_library( + getgid + HDRS + getgid.h + DEPENDS + libc.hdr.types.gid_t + libc.include.sys_syscall + libc.src.__support.OSUtil.osutil + libc.src.__support.common + libc.src.__support.macros.config +) + add_header_library( getpid HDRS diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/getgid.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/getgid.h new file mode 100644 index 00000000000000..1f89678df384d1 --- /dev/null +++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/getgid.h @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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 getgid. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_GETGID_H +#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_GETGID_H + +#include "hdr/types/gid_t.h" +#include "src/__support/OSUtil/linux/syscall.h" // syscall_impl +#include "src/__support/common.h" +#include "src/__support/macros/config.h" +#include <sys/syscall.h> // For syscall numbers + +namespace LIBC_NAMESPACE_DECL { +namespace linux_syscalls { + +LIBC_INLINE gid_t getgid() { return syscall_impl<gid_t>(SYS_getgid); } + +} // namespace linux_syscalls +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_GETGID_H diff --git a/libc/src/unistd/linux/CMakeLists.txt b/libc/src/unistd/linux/CMakeLists.txt index 530b0b1aae68e9..b106f182954b77 100644 --- a/libc/src/unistd/linux/CMakeLists.txt +++ b/libc/src/unistd/linux/CMakeLists.txt @@ -570,10 +570,10 @@ add_entrypoint_object( ../getgid.h DEPENDS libc.hdr.types.gid_t - libc.hdr.fcntl_macros - libc.include.unistd - libc.include.sys_syscall - libc.src.__support.OSUtil.osutil + libc.hdr.unistd_macros + libc.src.__support.OSUtil.linux.syscall_wrappers.getgid + libc.src.__support.common + libc.src.__support.macros.config ) add_entrypoint_object( diff --git a/libc/src/unistd/linux/getgid.cpp b/libc/src/unistd/linux/getgid.cpp index 1656fd601d8432..e9c8978d26683e 100644 --- a/libc/src/unistd/linux/getgid.cpp +++ b/libc/src/unistd/linux/getgid.cpp @@ -1,23 +1,24 @@ -//===-- Linux implementation of getgid ------------------------------------===// +//===----------------------------------------------------------------------===// // // 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 of getgid. +/// +//===----------------------------------------------------------------------===// #include "src/unistd/getgid.h" -#include "src/__support/OSUtil/syscall.h" // For internal syscall function. +#include "src/__support/OSUtil/linux/syscall_wrappers/getgid.h" #include "src/__support/common.h" #include "src/__support/macros/config.h" -#include <sys/syscall.h> // For syscall numbers. - namespace LIBC_NAMESPACE_DECL { -LLVM_LIBC_FUNCTION(gid_t, getgid, ()) { - return LIBC_NAMESPACE::syscall_impl<gid_t>(SYS_getgid); -} +LLVM_LIBC_FUNCTION(gid_t, getgid, ()) { return linux_syscalls::getgid(); } } // namespace LIBC_NAMESPACE_DECL diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel index 06b51a9af9acc5..3deef74286e4a8 100644 --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -3356,6 +3356,21 @@ libc_support_library( ], ) +libc_support_library( + name = "__support_osutil_linux_syscall_wrappers_getgid", + hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/getgid.h"], + target_compatible_with = select({ + "@platforms//os:linux": [], + "//conditions:default": ["@platforms//:incompatible"], + }), + deps = [ + ":__support_common", + ":__support_macros_config", + ":__support_osutil_syscall", + ":types_gid_t", + ], +) + libc_support_library( name = "__support_osutil_linux_syscall_wrappers_getpid", hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/getpid.h"], @@ -18993,7 +19008,7 @@ libc_function( deps = [ ":__support_common", ":__support_macros_config", - ":__support_osutil_syscall", + ":__support_osutil_linux_syscall_wrappers_getgid", ":hdr_unistd_macros", ":types_gid_t", ], _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
