llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Connector Switch (c8ef)

<details>
<summary>Changes</summary>

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


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


5 Files Affected:

- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt 
(+13) 
- (added) libc/src/__support/OSUtil/linux/syscall_wrappers/setsid.h (+34) 
- (modified) libc/src/unistd/linux/CMakeLists.txt (+5-2) 
- (modified) libc/src/unistd/linux/setsid.cpp (+11-8) 
- (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+34) 


``````````diff
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt 
b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index f318c5bedb82a..39bf7ad0b5e6e 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
@@ -669,6 +669,19 @@ add_header_library(
     libc.src.__support.macros.config
 )
 
+add_header_library(
+  setsid
+  HDRS
+    setsid.h
+  DEPENDS
+    libc.hdr.types.pid_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(
   setsockopt
   HDRS
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/setsid.h 
b/libc/src/__support/OSUtil/linux/syscall_wrappers/setsid.h
new file mode 100644
index 0000000000000..a1a717fcdbad1
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/setsid.h
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 setsid.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_SETSID_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_SETSID_H
+
+#include "hdr/types/pid_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<pid_t> setsid() {
+  return syscall_checked<pid_t>(SYS_setsid);
+}
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_SETSID_H
diff --git a/libc/src/unistd/linux/CMakeLists.txt 
b/libc/src/unistd/linux/CMakeLists.txt
index 8a028572af79b..48b5f6a796b83 100644
--- a/libc/src/unistd/linux/CMakeLists.txt
+++ b/libc/src/unistd/linux/CMakeLists.txt
@@ -938,8 +938,11 @@ add_entrypoint_object(
     ../setsid.h
   DEPENDS
     libc.hdr.types.pid_t
-    libc.include.sys_syscall
-    libc.src.__support.OSUtil.osutil
+    libc.src.__support.OSUtil.linux.syscall_wrappers.setsid
+    libc.src.__support.common
+    libc.src.__support.libc_errno
+    libc.src.__support.macros.config
+    libc.src.errno.errno
 )
 
 add_entrypoint_object(
diff --git a/libc/src/unistd/linux/setsid.cpp b/libc/src/unistd/linux/setsid.cpp
index b1a265c9a01dd..fbdf6f9ee4a82 100644
--- a/libc/src/unistd/linux/setsid.cpp
+++ b/libc/src/unistd/linux/setsid.cpp
@@ -1,30 +1,33 @@
-//===-- Linux implementation of 
setsid-------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // 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 setsid.
+///
+//===----------------------------------------------------------------------===//
 
 #include "src/unistd/setsid.h"
 
 #include "hdr/types/pid_t.h"
-#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/__support/OSUtil/linux/syscall_wrappers/setsid.h"
 #include "src/__support/common.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(pid_t, setsid, ()) {
-  pid_t ret = LIBC_NAMESPACE::syscall_impl<pid_t>(SYS_setsid);
-  if (ret < 0) {
-    libc_errno = static_cast<int>(-ret);
+  auto result = linux_syscalls::setsid();
+  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 b90c54e791d13..4c001a2909122 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -4830,6 +4830,22 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_osutil_linux_syscall_wrappers_setsid",
+    hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/setsid.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_pid_t",
+    ],
+)
+
 libc_support_library(
     name = "__support_osutil_linux_syscall_wrappers_setsockopt",
     hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/setsockopt.h"],
@@ -19124,6 +19140,24 @@ libc_function(
     ],
 )
 
+libc_function(
+    name = "setsid",
+    srcs = ["src/unistd/linux/setsid.cpp"],
+    hdrs = ["src/unistd/setsid.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_setsid",
+        ":errno",
+        ":types_pid_t",
+    ],
+)
+
 libc_function(
     name = "symlink",
     srcs = ["src/unistd/linux/symlink.cpp"],

``````````

</details>


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

Reply via email to