[llvm-branch-commits] [libc] [llvm] [libc] Use a syscall wrapper for geteuid (PR #241769)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Nov 12 02:27:26 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 geteuid behind the centralized syscall wrappers, following libc/docs/dev/syscall_wrapper_refactor.md.


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


5 Files Affected:

- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt (+12) 
- (added) libc/src/__support/OSUtil/linux/syscall_wrappers/geteuid.h (+31) 
- (modified) libc/src/unistd/linux/CMakeLists.txt (+4-4) 
- (modified) libc/src/unistd/linux/geteuid.cpp (+8-7) 
- (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+16-2) 


``````````diff
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index a8250b57599e7..6058f7716b8e7 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(
+  geteuid
+  HDRS
+    geteuid.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(
   getgid
   HDRS
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/geteuid.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/geteuid.h
new file mode 100644
index 0000000000000..fce4487f84fbf
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/geteuid.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 geteuid.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_GETEUID_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_GETEUID_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 geteuid() { return syscall_impl<uid_t>(SYS_geteuid); }
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_GETEUID_H
diff --git a/libc/src/unistd/linux/CMakeLists.txt b/libc/src/unistd/linux/CMakeLists.txt
index 747ef41278eb8..c95357e505b8c 100644
--- a/libc/src/unistd/linux/CMakeLists.txt
+++ b/libc/src/unistd/linux/CMakeLists.txt
@@ -462,10 +462,10 @@ add_entrypoint_object(
     ../geteuid.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.geteuid
+    libc.src.__support.common
+    libc.src.__support.macros.config
 )
 
 add_entrypoint_object(
diff --git a/libc/src/unistd/linux/geteuid.cpp b/libc/src/unistd/linux/geteuid.cpp
index a4bbcc0cb312a..1be11457e6780 100644
--- a/libc/src/unistd/linux/geteuid.cpp
+++ b/libc/src/unistd/linux/geteuid.cpp
@@ -1,23 +1,24 @@
-//===-- Linux implementation of geteuid -----------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // 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 for geteuid.
+///
+//===----------------------------------------------------------------------===//
 
 #include "src/unistd/geteuid.h"
 
-#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/__support/OSUtil/linux/syscall_wrappers/geteuid.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, geteuid, ()) {
-  return LIBC_NAMESPACE::syscall_impl<uid_t>(SYS_geteuid);
-}
+LLVM_LIBC_FUNCTION(uid_t, geteuid, ()) { return linux_syscalls::geteuid(); }
 
 } // 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 e58ab7294982e..4e6b21a39f533 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -3468,6 +3468,21 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_osutil_linux_syscall_wrappers_geteuid",
+    hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/geteuid.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_getgid",
     hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/getgid.h"],
@@ -18936,9 +18951,8 @@ libc_function(
     deps = [
         ":__support_common",
         ":__support_macros_config",
-        ":__support_osutil_syscall",
+        ":__support_osutil_linux_syscall_wrappers_geteuid",
         ":hdr_unistd_macros",
-        ":types_size_t",
         ":types_uid_t",
     ],
 )

``````````

</details>


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


More information about the llvm-branch-commits mailing list