[libc-commits] [libc] [llvm] [libc] Use a syscall wrapper for `getcpu` (PR #234157)
Connector Switch via libc-commits
libc-commits at lists.llvm.org
Wed Oct 21 04:18:32 PDT 2026
https://github.com/c8ef created https://github.com/llvm/llvm-project/pull/234157
This PR move `getcpu` behind the centralized syscall wrappers, following `libc/docs/dev/syscall_wrapper_refactor.md`.
>From 5156e8b3fbfbdfc4b349266c6ddd7b7e64da69e5 Mon Sep 17 00:00:00 2001
From: c8ef <c8ef at outlook.com>
Date: Wed, 21 Oct 2026 19:17:28 +0800
Subject: [PATCH] [libc] Use a syscall wrapper for getcpu
---
libc/src/sched/linux/CMakeLists.txt | 5 ++++-
libc/src/sched/linux/getcpu.cpp | 10 ++++------
utils/bazel/llvm-project-overlay/libc/BUILD.bazel | 13 +++++++++++++
3 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/libc/src/sched/linux/CMakeLists.txt b/libc/src/sched/linux/CMakeLists.txt
index 0c2fbd5b072fde..1b37756a7dbe85 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 a34b693fc148ef..19ec9f3407f326 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 cb7738739e62b8..61cfb3b6f92de1 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"],
More information about the libc-commits
mailing list