llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Connector Switch (c8ef)

<details>
<summary>Changes</summary>

This PR move semop behind the centralized syscall wrappers, following 
libc/docs/dev/syscall_wrapper_refactor.md.

---

&lt;sub&gt;Stack created with &lt;a 
href="https://github.com/github/gh-stack"&gt;GitHub Stacks CLI&lt;/a&gt; • 
&lt;a href="https://gh.io/stacks-feedback"&gt;Give Feedback 
💬&lt;/a&gt;&lt;/sub&gt;

---
Full diff: https://github.com/llvm/llvm-project/pull/236723.diff


5 Files Affected:

- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt 
(+14) 
- (added) libc/src/__support/OSUtil/linux/syscall_wrappers/semop.h (+36) 
- (modified) libc/src/sys/sem/linux/CMakeLists.txt (+3-2) 
- (modified) libc/src/sys/sem/linux/semop.cpp (+6-6) 
- (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+50) 


``````````diff
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt 
b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index d931c83c3a66a..8f3515b972cc7 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 0000000000000..7ee88fbd62017
--- /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 8fa3f8db77ec6..827fcaef3ab3b 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 97d7d12daf898..8a672c5d9df61 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 85a4947cc3ce7..315240dc5d6b2 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -604,6 +604,11 @@ libc_support_library(
     hdrs = ["include/llvm-libc-types/struct_seminfo.h"],
 )
 
+libc_support_library(
+    name = "llvm_libc_types_struct_sembuf",
+    hdrs = ["include/llvm-libc-types/struct_sembuf.h"],
+)
+
 libc_support_library(
     name = "llvm_libc_types_pid_t",
     hdrs = ["include/llvm-libc-types/pid_t.h"],
@@ -1497,6 +1502,15 @@ libc_support_library(
     }),
 )
 
+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_pid_t",
     hdrs = ["hdr/types/pid_t.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(

``````````

</details>


https://github.com/llvm/llvm-project/pull/236723
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to