[libc-commits] [libc] 9180556 - [libc] Use a syscall wrapper for getuid (#240779)

via libc-commits libc-commits at lists.llvm.org
Tue Nov 10 07:49:30 PST 2026


Author: Connector Switch
Date: 2026-11-10T23:49:09+08:00
New Revision: 9180556d09e02ff6f66274d13b7dc6615631ee94

URL: https://github.com/llvm/llvm-project/commit/9180556d09e02ff6f66274d13b7dc6615631ee94
DIFF: https://github.com/llvm/llvm-project/commit/9180556d09e02ff6f66274d13b7dc6615631ee94.diff

LOG: [libc] Use a syscall wrapper for getuid (#240779)

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

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

Modified: 
    libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
    libc/src/unistd/linux/CMakeLists.txt
    libc/src/unistd/linux/getuid.cpp
    utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index 709bbf7d32dfc..ecf91d6087668 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
@@ -38,6 +38,18 @@ add_header_library(
     libc.include.sys_syscall
 )
 
+add_header_library(
+  getuid
+  HDRS
+    getuid.h
+  DEPENDS
+    libc.hdr.types.uid_t
+    libc.include.sys_syscall
+    libc.src.__support.OSUtil.osutil
+    libc.src.__support.common
+    libc.src.__support.macros.config
+)
+
 add_header_library(
   getcpu
   HDRS

diff  --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/getuid.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/getuid.h
new file mode 100644
index 0000000000000..59a1d83d8fbd1
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/getuid.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 getuid.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_GETUID_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_GETUID_H
+
+#include "hdr/types/uid_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 uid_t getuid() { return syscall_impl<uid_t>(SYS_getuid); }
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_GETUID_H

diff  --git a/libc/src/unistd/linux/CMakeLists.txt b/libc/src/unistd/linux/CMakeLists.txt
index 238ffacbd0ac0..f26b33d84a2ea 100644
--- a/libc/src/unistd/linux/CMakeLists.txt
+++ b/libc/src/unistd/linux/CMakeLists.txt
@@ -80,10 +80,10 @@ add_entrypoint_object(
     libc.src.__support.OSUtil.linux.syscall_wrappers.close_range
     libc.src.__support.common
     libc.src.__support.libc_errno
-    libc.src.__support.macros.config
-)
-
-add_entrypoint_object(
+    libc.src.__support.macros.config
+)
+
+add_entrypoint_object(
   copy_file_range
   SRCS
     copy_file_range.cpp
@@ -582,10 +582,10 @@ add_entrypoint_object(
     ../getuid.h
   DEPENDS
     libc.hdr.types.uid_t
-    libc.hdr.fcntl_macros
-    libc.include.unistd
-    libc.include.sys_syscall
-    libc.src.__support.OSUtil.osutil
+    libc.hdr.unistd_macros
+    libc.src.__support.OSUtil.linux.syscall_wrappers.getuid
+    libc.src.__support.common
+    libc.src.__support.macros.config
 )
 
 add_entrypoint_object(

diff  --git a/libc/src/unistd/linux/getuid.cpp b/libc/src/unistd/linux/getuid.cpp
index ce818ec91bd2a..2d48dd60f529c 100644
--- a/libc/src/unistd/linux/getuid.cpp
+++ b/libc/src/unistd/linux/getuid.cpp
@@ -1,23 +1,24 @@
-//===-- Linux implementation of getuid ------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // 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 getuid.
+///
+//===----------------------------------------------------------------------===//
 
 #include "src/unistd/getuid.h"
 
-#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/__support/OSUtil/linux/syscall_wrappers/getuid.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(uid_t, getuid, ()) {
-  return LIBC_NAMESPACE::syscall_impl<uid_t>(SYS_getuid);
-}
+LLVM_LIBC_FUNCTION(uid_t, getuid, ()) { return linux_syscalls::getuid(); }
 
 } // 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 9030f6dbac706..45b3ec8fd1f5a 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -3371,6 +3371,21 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_osutil_linux_syscall_wrappers_getuid",
+    hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/getuid.h"],
+    target_compatible_with = select({
+        "@platforms//os:linux": [],
+        "//conditions:default": ["@platforms//:incompatible"],
+    }),
+    deps = [
+        ":__support_common",
+        ":__support_macros_config",
+        ":__support_osutil_syscall",
+        ":types_uid_t",
+    ],
+)
+
 libc_support_library(
     name = "__support_osutil_linux_syscall_wrappers_unlinkat",
     hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/unlinkat.h"],
@@ -18918,7 +18933,7 @@ libc_function(
     deps = [
         ":__support_common",
         ":__support_macros_config",
-        ":__support_osutil_syscall",
+        ":__support_osutil_linux_syscall_wrappers_getuid",
         ":hdr_unistd_macros",
         ":types_uid_t",
     ],


        


More information about the libc-commits mailing list