[libc-commits] [libc] [llvm] [libc] Use a syscall wrapper for `getcpu` (PR #234157)

via libc-commits libc-commits at lists.llvm.org
Wed Oct 21 04:19:10 PDT 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 `getcpu` behind the centralized syscall wrappers, following `libc/docs/dev/syscall_wrapper_refactor.md`.

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


3 Files Affected:

- (modified) libc/src/sched/linux/CMakeLists.txt (+4-1) 
- (modified) libc/src/sched/linux/getcpu.cpp (+4-6) 
- (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+13) 


``````````diff
diff --git a/libc/src/sched/linux/CMakeLists.txt b/libc/src/sched/linux/CMakeLists.txt
index 0c2fbd5b072fd..1b37756a7dbe8 100644
--- a/libc/src/sched/linux/CMakeLists.txt
+++ b/libc/src/sched/linux/CMakeLists.txt
@@ -23,7 +23,10 @@ add_entrypoint_object(
   HDRS
     ../getcpu.h
   DEPENDS
-    libc.src.__support.OSUtil.osutil
+    libc.src.__support.OSUtil.linux.syscall_wrappers.getcpu
+    libc.src.__support.common
+    libc.src.__support.libc_errno
+    libc.src.__support.macros.config
     libc.src.errno.errno
 )
 
diff --git a/libc/src/sched/linux/getcpu.cpp b/libc/src/sched/linux/getcpu.cpp
index a34b693fc148e..19ec9f3407f32 100644
--- a/libc/src/sched/linux/getcpu.cpp
+++ b/libc/src/sched/linux/getcpu.cpp
@@ -8,19 +8,17 @@
 
 #include "src/sched/getcpu.h"
 
-#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/__support/OSUtil/linux/syscall_wrappers/getcpu.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(int, getcpu, (unsigned int *cpu, unsigned int *node)) {
-  int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_getcpu, cpu, node, nullptr);
-  if (ret < 0) {
-    libc_errno = -ret;
+  auto result = linux_syscalls::getcpu(cpu, node);
+  if (!result) {
+    libc_errno = result.error();
     return -1;
   }
   return 0;
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index cb7738739e62b..61cfb3b6f92de 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -17161,6 +17161,19 @@ libc_function(
     ],
 )
 
+libc_function(
+    name = "getcpu",
+    srcs = ["src/sched/linux/getcpu.cpp"],
+    hdrs = ["src/sched/getcpu.h"],
+    deps = [
+        ":__support_common",
+        ":__support_libc_errno",
+        ":__support_macros_config",
+        ":__support_osutil_linux_syscall_wrappers_getcpu",
+        ":errno",
+    ],
+)
+
 libc_function(
     name = "sched_getcpu",
     srcs = ["src/sched/linux/sched_getcpu.cpp"],

``````````

</details>


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


More information about the libc-commits mailing list