https://github.com/c8ef updated https://github.com/llvm/llvm-project/pull/236723
>From 60693374689a6e9bf6707fe454c7692d4f4bcae2 Mon Sep 17 00:00:00 2001 From: c8ef <[email protected]> Date: Thu, 29 Oct 2026 18:48:16 +0800 Subject: [PATCH] [libc] Use a syscall wrapper for semop This PR move semop behind the centralized syscall wrappers, following libc/docs/dev/syscall_wrapper_refactor.md. --- .../linux/syscall_wrappers/CMakeLists.txt | 14 ++++++ .../OSUtil/linux/syscall_wrappers/semop.h | 36 +++++++++++++ libc/src/sys/sem/linux/CMakeLists.txt | 5 +- libc/src/sys/sem/linux/semop.cpp | 12 ++--- .../llvm-project-overlay/libc/BUILD.bazel | 50 +++++++++++++++++++ 5 files changed, 109 insertions(+), 8 deletions(-) create mode 100644 libc/src/__support/OSUtil/linux/syscall_wrappers/semop.h diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt index d931c83c3a66a1..8f3515b972cc7a 100644 --- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt +++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt @@ -208,6 +208,20 @@ add_header_library( libc.src.__support.macros.config ) +add_header_library( + semop + HDRS + semop.h + DEPENDS + libc.hdr.types.size_t + libc.hdr.types.struct_sembuf + 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( close HDRS diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/semop.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/semop.h new file mode 100644 index 00000000000000..7ee88fbd620176 --- /dev/null +++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/semop.h @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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 semop. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_SEMOP_H +#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_SEMOP_H + +#include "hdr/types/size_t.h" +#include "hdr/types/struct_sembuf.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> semop(int semid, struct sembuf *sops, size_t nsops) { + return syscall_checked<int>(SYS_semop, semid, sops, nsops); +} + +} // namespace linux_syscalls +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_SEMOP_H diff --git a/libc/src/sys/sem/linux/CMakeLists.txt b/libc/src/sys/sem/linux/CMakeLists.txt index 8fa3f8db77ec65..827fcaef3ab3b1 100644 --- a/libc/src/sys/sem/linux/CMakeLists.txt +++ b/libc/src/sys/sem/linux/CMakeLists.txt @@ -41,8 +41,9 @@ add_entrypoint_object( DEPENDS libc.hdr.types.size_t libc.hdr.types.struct_sembuf - libc.include.sys_syscall - libc.src.__support.OSUtil.osutil + libc.src.__support.OSUtil.linux.syscall_wrappers.semop libc.src.__support.common + libc.src.__support.libc_errno + libc.src.__support.macros.config libc.src.errno.errno ) diff --git a/libc/src/sys/sem/linux/semop.cpp b/libc/src/sys/sem/linux/semop.cpp index 97d7d12daf8984..8a672c5d9df616 100644 --- a/libc/src/sys/sem/linux/semop.cpp +++ b/libc/src/sys/sem/linux/semop.cpp @@ -8,20 +8,20 @@ #include "src/sys/sem/semop.h" -#include "src/__support/OSUtil/syscall.h" +#include "src/__support/OSUtil/linux/syscall_wrappers/semop.h" #include "src/__support/common.h" #include "src/__support/libc_errno.h" -#include <sys/syscall.h> +#include "src/__support/macros/config.h" namespace LIBC_NAMESPACE_DECL { LLVM_LIBC_FUNCTION(int, semop, (int semid, struct sembuf *sops, size_t nsops)) { - int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_semop, semid, sops, nsops); - if (ret < 0) { - libc_errno = -ret; + auto result = linux_syscalls::semop(semid, sops, nsops); + if (!result) { + libc_errno = result.error(); return -1; } - return ret; + return result.value(); } } // 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 df577eb35c6780..df50b6cc3189a5 100644 --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -775,6 +775,11 @@ libc_support_library( ], ) +libc_support_library( + name = "llvm_libc_types_struct_sembuf", + hdrs = ["include/llvm-libc-types/struct_sembuf.h"], +) + libc_support_library( name = "llvm_libc_types_struct_semid_ds", hdrs = ["include/llvm-libc-types/struct_semid_ds.h"], @@ -1465,6 +1470,15 @@ libc_support_library( hdrs = ["hdr/types/struct_rlimit.h"], ) +libc_support_library( + name = "types_struct_sembuf", + hdrs = ["hdr/types/struct_sembuf.h"], + deps = select({ + ":full_build": [":llvm_libc_types_struct_sembuf"], + "//conditions:default": [], + }), +) + libc_support_library( name = "types_struct_semid_ds", hdrs = ["hdr/types/struct_semid_ds.h"], @@ -3139,6 +3153,23 @@ libc_support_library( ], ) +libc_support_library( + name = "__support_osutil_linux_syscall_wrappers_semop", + hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/semop.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", + ":types_struct_sembuf", + ], +) + libc_support_library( name = "__support_osutil_linux_syscall_wrappers_sendmsg", hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/sendmsg.h"], @@ -19493,6 +19524,25 @@ libc_function( ], ) +libc_function( + name = "semop", + srcs = ["src/sys/sem/linux/semop.cpp"], + hdrs = ["src/sys/sem/semop.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_semop", + ":errno", + ":types_size_t", + ":types_struct_sembuf", + ], +) + ############################### sys/stat targets ############################### libc_function( _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
