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

Connector Switch via libc-commits libc-commits at lists.llvm.org
Wed Nov 11 02:44:26 PST 2026


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

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


>From 1ce1f8e4f1886398d3513df5c19e8bac00885f7c Mon Sep 17 00:00:00 2001
From: c8ef <c8ef at outlook.com>
Date: Wed, 11 Nov 2026 18:42:23 +0800
Subject: [PATCH] [libc] Use a syscall wrapper for getsid

This PR move getsid behind the centralized syscall wrappers, following libc/docs/dev/syscall_wrapper_refactor.md.
---
 .../linux/syscall_wrappers/CMakeLists.txt     | 13 +++++++
 .../OSUtil/linux/syscall_wrappers/getsid.h    | 34 +++++++++++++++++++
 libc/src/unistd/linux/CMakeLists.txt          |  6 ++--
 libc/src/unistd/linux/getsid.cpp              | 18 ++++++----
 .../llvm-project-overlay/libc/BUILD.bazel     | 34 +++++++++++++++++++
 5 files changed, 96 insertions(+), 9 deletions(-)
 create mode 100644 libc/src/__support/OSUtil/linux/syscall_wrappers/getsid.h

diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index 413c4da4b30b68..da7ab174a470b5 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 00000000000000..9228d173d91ece
--- /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 f84ec1efef459f..607f7b6230aec7 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 025b8d1691ac37..93a0f4af729651 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 ed572d03edac2f..8197745913ce92 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"],



More information about the libc-commits mailing list