[libc-commits] [libc] 0157483 - [libc] Use a syscall wrapper for `epoll_pwait2` (#235701)
via libc-commits
libc-commits at lists.llvm.org
Mon Oct 26 05:52:01 PDT 2026
Author: Connector Switch
Date: 2026-10-26T20:51:57+08:00
New Revision: 015748372360f92ddb85c7e76be2b64c12189950
URL: https://github.com/llvm/llvm-project/commit/015748372360f92ddb85c7e76be2b64c12189950
DIFF: https://github.com/llvm/llvm-project/commit/015748372360f92ddb85c7e76be2b64c12189950.diff
LOG: [libc] Use a syscall wrapper for `epoll_pwait2` (#235701)
This PR move `epoll_pwait2` behind the centralized syscall wrappers,
following `libc/docs/dev/syscall_wrapper_refactor.md`.
And slightly make the cmake and bazel target more sorted.
Added:
libc/src/__support/OSUtil/linux/syscall_wrappers/epoll_pwait2.h
Modified:
libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
libc/src/sys/epoll/linux/CMakeLists.txt
libc/src/sys/epoll/linux/epoll_pwait2.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 6701bb24f081d2..ca476f95b0cc8c 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
@@ -1291,6 +1291,22 @@ add_header_library(
libc.include.sys_syscall
)
+add_header_library(
+ epoll_pwait2
+ HDRS
+ epoll_pwait2.h
+ DEPENDS
+ libc.hdr.signal_macros
+ libc.hdr.types.sigset_t
+ libc.hdr.types.struct_epoll_event
+ libc.hdr.types.struct_timespec
+ 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(
access
HDRS
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/epoll_pwait2.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/epoll_pwait2.h
new file mode 100644
index 00000000000000..c80592907c8272
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/epoll_pwait2.h
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// 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_pwait2.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_EPOLL_PWAIT2_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_EPOLL_PWAIT2_H
+
+#include "hdr/signal_macros.h"
+#include "hdr/types/sigset_t.h"
+#include "hdr/types/struct_epoll_event.h"
+#include "hdr/types/struct_timespec.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_pwait2(int epfd, struct epoll_event *events,
+ int maxevents,
+ const struct timespec *timeout,
+ const sigset_t *sigmask) {
+ return syscall_checked<int>(SYS_epoll_pwait2, epfd, events, maxevents,
+ timeout, sigmask, NSIG / 8);
+}
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_EPOLL_PWAIT2_H
diff --git a/libc/src/sys/epoll/linux/CMakeLists.txt b/libc/src/sys/epoll/linux/CMakeLists.txt
index 2fab33194febf4..83918fd3b49b8f 100644
--- a/libc/src/sys/epoll/linux/CMakeLists.txt
+++ b/libc/src/sys/epoll/linux/CMakeLists.txt
@@ -41,15 +41,17 @@ add_entrypoint_object(
)
add_entrypoint_object(
- epoll_wait
+ epoll_pwait
SRCS
- epoll_wait.cpp
+ epoll_pwait.cpp
HDRS
- ../epoll_wait.h
+ ../epoll_pwait.h
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.macros.sanitizer
@@ -57,35 +59,33 @@ add_entrypoint_object(
)
add_entrypoint_object(
- epoll_pwait
+ epoll_pwait2
SRCS
- epoll_pwait.cpp
+ epoll_pwait2.cpp
HDRS
- ../epoll_pwait.h
+ ../epoll_pwait2.h
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_pwait2
+ libc.src.__support.common
+ libc.src.__support.libc_errno
+ libc.src.__support.macros.config
libc.src.__support.macros.sanitizer
libc.src.errno.errno
)
add_entrypoint_object(
- epoll_pwait2
+ epoll_wait
SRCS
- epoll_pwait2.cpp
+ epoll_wait.cpp
HDRS
- ../epoll_pwait2.h
+ ../epoll_wait.h
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.macros.sanitizer
diff --git a/libc/src/sys/epoll/linux/epoll_pwait2.cpp b/libc/src/sys/epoll/linux/epoll_pwait2.cpp
index ee507344d68d26..4130ae4130fdb0 100644
--- a/libc/src/sys/epoll/linux/epoll_pwait2.cpp
+++ b/libc/src/sys/epoll/linux/epoll_pwait2.cpp
@@ -8,38 +8,30 @@
#include "src/sys/epoll/epoll_pwait2.h"
-#include "hdr/signal_macros.h" // for NSIG
#include "hdr/types/sigset_t.h"
#include "hdr/types/struct_epoll_event.h"
#include "hdr/types/struct_timespec.h"
-#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/__support/OSUtil/linux/syscall_wrappers/epoll_pwait2.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_pwait2,
(int epfd, struct epoll_event *events, int maxevents,
const struct timespec *timeout, const sigset_t *sigmask)) {
- int ret = LIBC_NAMESPACE::syscall_impl<int>(
- SYS_epoll_pwait2, epfd, reinterpret_cast<long>(events), maxevents,
- reinterpret_cast<long>(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_pwait2(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 8f35d6b22fbfd7..0c8dec9ccd2029 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2553,6 +2553,25 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_osutil_linux_syscall_wrappers_epoll_pwait2",
+ hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/epoll_pwait2.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",
+ ":types_struct_timespec",
+ ],
+)
+
libc_support_library(
name = "__support_osutil_linux_syscall_wrappers_ftruncate",
hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/ftruncate.h"],
@@ -19392,9 +19411,9 @@ libc_function(
)
libc_function(
- name = "epoll_wait",
- srcs = ["src/sys/epoll/linux/epoll_wait.cpp"],
- hdrs = ["src/sys/epoll/epoll_wait.h"],
+ name = "epoll_pwait",
+ srcs = ["src/sys/epoll/linux/epoll_pwait.cpp"],
+ hdrs = ["src/sys/epoll/epoll_pwait.h"],
target_compatible_with = select({
"@platforms//os:linux": [],
"//conditions:default": ["@platforms//:incompatible"],
@@ -19414,9 +19433,9 @@ libc_function(
)
libc_function(
- name = "epoll_pwait",
- srcs = ["src/sys/epoll/linux/epoll_pwait.cpp"],
- hdrs = ["src/sys/epoll/epoll_pwait.h"],
+ name = "epoll_pwait2",
+ srcs = ["src/sys/epoll/linux/epoll_pwait2.cpp"],
+ hdrs = ["src/sys/epoll/epoll_pwait2.h"],
target_compatible_with = select({
"@platforms//os:linux": [],
"//conditions:default": ["@platforms//:incompatible"],
@@ -19426,19 +19445,18 @@ libc_function(
":__support_libc_errno",
":__support_macros_config",
":__support_macros_sanitizer",
- ":__support_osutil_syscall",
+ ":__support_osutil_linux_syscall_wrappers_epoll_pwait2",
":errno",
- ":hdr_signal_macros",
- ":hdr_sys_epoll_macros",
":types_sigset_t",
":types_struct_epoll_event",
+ ":types_struct_timespec",
],
)
libc_function(
- name = "epoll_pwait2",
- srcs = ["src/sys/epoll/linux/epoll_pwait2.cpp"],
- hdrs = ["src/sys/epoll/epoll_pwait2.h"],
+ name = "epoll_wait",
+ srcs = ["src/sys/epoll/linux/epoll_wait.cpp"],
+ hdrs = ["src/sys/epoll/epoll_wait.h"],
target_compatible_with = select({
"@platforms//os:linux": [],
"//conditions:default": ["@platforms//:incompatible"],
@@ -19454,7 +19472,6 @@ libc_function(
":hdr_sys_epoll_macros",
":types_sigset_t",
":types_struct_epoll_event",
- ":types_struct_timespec",
],
)
More information about the libc-commits
mailing list