[libc-commits] [libc] [llvm] [libc] Use a syscall wrapper for getsid (PR #241202)

via libc-commits libc-commits at lists.llvm.org
Wed Nov 11 02:45:03 PST 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Connector Switch (c8ef)

<details>
<summary>Changes</summary>

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


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


5 Files Affected:

- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt (+13) 
- (added) libc/src/__support/OSUtil/linux/syscall_wrappers/getsid.h (+34) 
- (modified) libc/src/unistd/linux/CMakeLists.txt (+4-2) 
- (modified) libc/src/unistd/linux/getsid.cpp (+11-7) 
- (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 413c4da4b30b6..da7ab174a470b 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
@@ -62,6 +62,19 @@ add_header_library(
     libc.src.__support.macros.config
 )
 
+add_header_library(
+  getsid
+  HDRS
+    getsid.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(
   getuid
   HDRS
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/getsid.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/getsid.h
new file mode 100644
index 0000000000000..9228d173d91ec
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/getsid.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 getsid.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_GETSID_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_GETSID_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> getsid(pid_t pid) {
+  return syscall_checked<pid_t>(SYS_getsid, pid);
+}
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_GETSID_H
diff --git a/libc/src/unistd/linux/CMakeLists.txt b/libc/src/unistd/linux/CMakeLists.txt
index f84ec1efef459..607f7b6230aec 100644
--- a/libc/src/unistd/linux/CMakeLists.txt
+++ b/libc/src/unistd/linux/CMakeLists.txt
@@ -557,8 +557,10 @@ add_entrypoint_object(
     ../getsid.h
   DEPENDS
     libc.hdr.types.pid_t
-    libc.include.sys_syscall
-    libc.src.__support.OSUtil.osutil
+    libc.src.__support.OSUtil.linux.syscall_wrappers.getsid
+    libc.src.__support.common
+    libc.src.__support.libc_errno
+    libc.src.__support.macros.config
     libc.src.errno.errno
 )
 
diff --git a/libc/src/unistd/linux/getsid.cpp b/libc/src/unistd/linux/getsid.cpp
index 025b8d1691ac3..93a0f4af72965 100644
--- a/libc/src/unistd/linux/getsid.cpp
+++ b/libc/src/unistd/linux/getsid.cpp
@@ -1,29 +1,33 @@
-//===-- Linux implementation of getsid-------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // 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 getsid.
+///
+//===----------------------------------------------------------------------===//
 
 #include "src/unistd/getsid.h"
 
 #include "hdr/types/pid_t.h"
-#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/__support/OSUtil/linux/syscall_wrappers/getsid.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, getsid, (pid_t pid)) {
-  pid_t ret = LIBC_NAMESPACE::syscall_impl<pid_t>(SYS_getsid, pid);
-  if (ret < 0) {
-    libc_errno = static_cast<int>(-ret);
+  auto result = linux_syscalls::getsid(pid);
+  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 ed572d03edac2..8197745913ce9 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -3401,6 +3401,22 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_osutil_linux_syscall_wrappers_getsid",
+    hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/getsid.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_getuid",
     hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/getuid.h"],
@@ -18977,6 +18993,24 @@ libc_function(
     ],
 )
 
+libc_function(
+    name = "getsid",
+    srcs = ["src/unistd/linux/getsid.cpp"],
+    hdrs = ["src/unistd/getsid.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_getsid",
+        ":errno",
+        ":types_pid_t",
+    ],
+)
+
 libc_function(
     name = "getuid",
     srcs = ["src/unistd/linux/getuid.cpp"],

``````````

</details>


https://github.com/llvm/llvm-project/pull/241202


More information about the libc-commits mailing list