[llvm-branch-commits] [libc] [llvm] [libc] Use a syscall wrapper for `epoll_pwait` (PR #236382)
Connector Switch via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Oct 28 04:33:57 PDT 2026
https://github.com/c8ef created https://github.com/llvm/llvm-project/pull/236382
This PR move `epoll_pwait` behind the centralized syscall wrappers, following `libc/docs/dev/syscall_wrapper_refactor.md`.
---
<sub>Stack created with <a href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub>
>From 2fbd46ed807b7745aeedf51991d86e5727fb1509 Mon Sep 17 00:00:00 2001
From: c8ef <c8ef at outlook.com>
Date: Wed, 28 Oct 2026 19:31:28 +0800
Subject: [PATCH] [libc] Use a syscall wrapper for epoll_pwait
---
.../linux/syscall_wrappers/CMakeLists.txt | 15 +++++++
.../linux/syscall_wrappers/epoll_pwait.h | 40 +++++++++++++++++++
libc/src/sys/epoll/linux/CMakeLists.txt | 9 ++---
libc/src/sys/epoll/linux/epoll_pwait.cpp | 21 ++++------
.../llvm-project-overlay/libc/BUILD.bazel | 22 ++++++++--
5 files changed, 85 insertions(+), 22 deletions(-)
create mode 100644 libc/src/__support/OSUtil/linux/syscall_wrappers/epoll_pwait.h
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index 4a2eae9e942eb0..e682daff23fb5e 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
@@ -1330,6 +1330,21 @@ add_header_library(
libc.include.sys_syscall
)
+add_header_library(
+ epoll_pwait
+ HDRS
+ epoll_pwait.h
+ DEPENDS
+ libc.hdr.signal_macros
+ libc.hdr.types.sigset_t
+ libc.hdr.types.struct_epoll_event
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.__support.common
+ libc.src.__support.error_or
+ libc.src.__support.macros.config
+)
+
add_header_library(
epoll_pwait2
HDRS
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/epoll_pwait.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/epoll_pwait.h
new file mode 100644
index 00000000000000..f32cb92f098ff1
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/epoll_pwait.h
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 epoll_pwait.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_EPOLL_PWAIT_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_EPOLL_PWAIT_H
+
+#include "hdr/signal_macros.h"
+#include "hdr/types/sigset_t.h"
+#include "hdr/types/struct_epoll_event.h"
+#include "src/__support/OSUtil/linux/syscall.h" // syscall_checked
+#include "src/__support/common.h"
+#include "src/__support/error_or.h"
+#include "src/__support/macros/config.h"
+
+#include <sys/syscall.h> // For syscall numbers
+
+namespace LIBC_NAMESPACE_DECL {
+namespace linux_syscalls {
+
+LIBC_INLINE ErrorOr<int> epoll_pwait(int epfd, struct epoll_event *events,
+ int maxevents, int timeout,
+ const sigset_t *sigmask) {
+ return syscall_checked<int>(SYS_epoll_pwait, epfd, events, maxevents, timeout,
+ sigmask, NSIG / 8);
+}
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_EPOLL_PWAIT_H
diff --git a/libc/src/sys/epoll/linux/CMakeLists.txt b/libc/src/sys/epoll/linux/CMakeLists.txt
index 6def58ada31eae..8d52e534afa521 100644
--- a/libc/src/sys/epoll/linux/CMakeLists.txt
+++ b/libc/src/sys/epoll/linux/CMakeLists.txt
@@ -51,11 +51,10 @@ add_entrypoint_object(
DEPENDS
libc.hdr.types.sigset_t
libc.hdr.types.struct_epoll_event
- libc.hdr.types.struct_timespec
- libc.hdr.sys_epoll_macros
- libc.hdr.signal_macros
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
+ libc.src.__support.OSUtil.linux.syscall_wrappers.epoll_pwait
+ libc.src.__support.common
+ libc.src.__support.libc_errno
+ libc.src.__support.macros.config
libc.src.__support.macros.sanitizer
libc.src.errno.errno
)
diff --git a/libc/src/sys/epoll/linux/epoll_pwait.cpp b/libc/src/sys/epoll/linux/epoll_pwait.cpp
index d0b4cc1bed5cea..02e6ddc589c26b 100644
--- a/libc/src/sys/epoll/linux/epoll_pwait.cpp
+++ b/libc/src/sys/epoll/linux/epoll_pwait.cpp
@@ -8,36 +8,29 @@
#include "src/sys/epoll/epoll_pwait.h"
-#include "hdr/signal_macros.h" // for NSIG
#include "hdr/types/sigset_t.h"
#include "hdr/types/struct_epoll_event.h"
-#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/__support/OSUtil/linux/syscall_wrappers/epoll_pwait.h"
#include "src/__support/common.h"
#include "src/__support/libc_errno.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/sanitizer.h"
-#include <sys/syscall.h> // For syscall numbers.
-
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, epoll_pwait,
(int epfd, struct epoll_event *events, int maxevents,
int timeout, const sigset_t *sigmask)) {
- int ret = LIBC_NAMESPACE::syscall_impl<int>(
- SYS_epoll_pwait, epfd, reinterpret_cast<long>(events), maxevents, timeout,
- reinterpret_cast<long>(sigmask), NSIG / 8);
-
- // A negative return value indicates an error with the magnitude of the
- // value being the error code.
- if (ret < 0) {
- libc_errno = -ret;
+ auto result =
+ linux_syscalls::epoll_pwait(epfd, events, maxevents, timeout, sigmask);
+ if (!result) {
+ libc_errno = result.error();
return -1;
}
- LIBC_MSAN_UNPOISON(events, ret * sizeof(struct epoll_event));
+ LIBC_MSAN_UNPOISON(events, result.value() * sizeof(struct epoll_event));
- return ret;
+ return result.value();
}
} // 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 43806ef615f29d..c7c585d757a41d 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2583,6 +2583,24 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_osutil_linux_syscall_wrappers_epoll_pwait",
+ hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/epoll_pwait.h"],
+ target_compatible_with = select({
+ "@platforms//os:linux": [],
+ "//conditions:default": ["@platforms//:incompatible"],
+ }),
+ deps = [
+ ":__support_common",
+ ":__support_error_or",
+ ":__support_macros_config",
+ ":__support_osutil_syscall",
+ ":hdr_signal_macros",
+ ":types_sigset_t",
+ ":types_struct_epoll_event",
+ ],
+)
+
libc_support_library(
name = "__support_osutil_linux_syscall_wrappers_epoll_pwait2",
hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/epoll_pwait2.h"],
@@ -19671,10 +19689,8 @@ libc_function(
":__support_libc_errno",
":__support_macros_config",
":__support_macros_sanitizer",
- ":__support_osutil_syscall",
+ ":__support_osutil_linux_syscall_wrappers_epoll_pwait",
":errno",
- ":hdr_signal_macros",
- ":hdr_sys_epoll_macros",
":types_sigset_t",
":types_struct_epoll_event",
],
More information about the llvm-branch-commits
mailing list