[libc-commits] [libc] 7a5f8a0 - [libc] Add getpid syscall wrapper for Linux (#220595)

via libc-commits libc-commits at lists.llvm.org
Thu Sep 3 01:00:49 PDT 2026


Author: Tapiwa Gonga
Date: 2026-09-03T09:00:43+01:00
New Revision: 7a5f8a04e602ea1d74f4a9f28fdd4d5592611e68

URL: https://github.com/llvm/llvm-project/commit/7a5f8a04e602ea1d74f4a9f28fdd4d5592611e68
DIFF: https://github.com/llvm/llvm-project/commit/7a5f8a04e602ea1d74f4a9f28fdd4d5592611e68.diff

LOG: [libc] Add getpid syscall wrapper for Linux (#220595)

Adds an internal `getpid` Linux system call wrapper
(`LIBC_NAMESPACE::linux_syscalls::getpid`) in
`src/__support/OSUtil/linux/syscall_wrappers/getpid.h` and registers the
corresponding CMake header library target.

This follows the established pattern of existing syscall wrappers in
this directory to allow internal utilities to query the process ID via
`SYS_getpid` in freestanding environments.

Update existing getpid to use it.

Assisted-by: Automated tooling, human reviewed.

Added: 
    libc/src/__support/OSUtil/linux/syscall_wrappers/getpid.h

Modified: 
    libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
    libc/src/unistd/linux/CMakeLists.txt
    libc/src/unistd/linux/getpid.cpp

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index f4a3d1fa7c20e..a01fae7f80583 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
@@ -26,6 +26,18 @@ add_header_library(
     libc.include.sys_syscall
 )
 
+add_header_library(
+  getpid
+  HDRS
+    getpid.h
+  DEPENDS
+    libc.src.__support.OSUtil.osutil
+    libc.src.__support.common
+    libc.src.__support.macros.config
+    libc.hdr.types.pid_t
+    libc.include.sys_syscall
+)
+
 add_header_library(
   sched_getaffinity
   HDRS

diff  --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/getpid.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/getpid.h
new file mode 100644
index 0000000000000..7644b67449fdb
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/getpid.h
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 getpid.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_GETPID_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_GETPID_H
+
+#include "hdr/types/pid_t.h"
+#include "src/__support/OSUtil/linux/syscall.h" // syscall_impl
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include <sys/syscall.h> // For syscall numbers
+
+namespace LIBC_NAMESPACE_DECL {
+namespace linux_syscalls {
+
+LIBC_INLINE pid_t getpid() { return syscall_impl<pid_t>(SYS_getpid); }
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_GETPID_H

diff  --git a/libc/src/unistd/linux/CMakeLists.txt b/libc/src/unistd/linux/CMakeLists.txt
index 3c939ba3e24e0..9c5ac662eef18 100644
--- a/libc/src/unistd/linux/CMakeLists.txt
+++ b/libc/src/unistd/linux/CMakeLists.txt
@@ -320,10 +320,7 @@ add_entrypoint_object(
     ../getpid.h
   DEPENDS
     libc.hdr.types.pid_t
-    libc.hdr.fcntl_macros
-    libc.include.unistd
-    libc.include.sys_syscall
-    libc.src.__support.OSUtil.osutil
+    libc.src.__support.OSUtil.linux.syscall_wrappers.getpid
 )
 
 add_entrypoint_object(

diff  --git a/libc/src/unistd/linux/getpid.cpp b/libc/src/unistd/linux/getpid.cpp
index b24c86a15990f..c1749baa8081f 100644
--- a/libc/src/unistd/linux/getpid.cpp
+++ b/libc/src/unistd/linux/getpid.cpp
@@ -8,16 +8,12 @@
 
 #include "src/unistd/getpid.h"
 
-#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/__support/OSUtil/linux/syscall_wrappers/getpid.h"
 #include "src/__support/common.h"
 #include "src/__support/macros/config.h"
 
-#include <sys/syscall.h> // For syscall numbers.
-
 namespace LIBC_NAMESPACE_DECL {
 
-LLVM_LIBC_FUNCTION(pid_t, getpid, ()) {
-  return LIBC_NAMESPACE::syscall_impl<pid_t>(SYS_getpid);
-}
+LLVM_LIBC_FUNCTION(pid_t, getpid, ()) { return linux_syscalls::getpid(); }
 
 } // namespace LIBC_NAMESPACE_DECL


        


More information about the libc-commits mailing list