[libc-commits] [libc] [llvm] [libc] Use a syscall wrapper for `epoll_create` (PR #236381)
Connector Switch via libc-commits
libc-commits at lists.llvm.org
Wed Oct 28 04:33:53 PDT 2026
https://github.com/c8ef created https://github.com/llvm/llvm-project/pull/236381
This PR move `epoll_create` 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 560952bf41e2a15328fedd5a3dc3fdf11598f5a9 Mon Sep 17 00:00:00 2001
From: c8ef <c8ef at outlook.com>
Date: Wed, 28 Oct 2026 19:29:01 +0800
Subject: [PATCH] [libc] Use a syscall wrapper for epoll_create
---
.../linux/syscall_wrappers/CMakeLists.txt | 13 ++++++
.../linux/syscall_wrappers/epoll_create.h | 44 +++++++++++++++++++
libc/src/sys/epoll/linux/CMakeLists.txt | 6 ++-
libc/src/sys/epoll/linux/epoll_create.cpp | 28 +++---------
.../llvm-project-overlay/libc/BUILD.bazel | 18 +++++++-
5 files changed, 84 insertions(+), 25 deletions(-)
create mode 100644 libc/src/__support/OSUtil/linux/syscall_wrappers/epoll_create.h
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index 8cff89c818baaa..4a2eae9e942eb0 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
@@ -1292,6 +1292,19 @@ add_header_library(
libc.include.sys_syscall
)
+add_header_library(
+ epoll_create
+ HDRS
+ epoll_create.h
+ DEPENDS
+ libc.hdr.errno_macros
+ libc.src.__support.OSUtil.osutil
+ libc.src.__support.common
+ libc.src.__support.error_or
+ libc.src.__support.macros.config
+ libc.include.sys_syscall
+)
+
add_header_library(
epoll_create1
HDRS
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/epoll_create.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/epoll_create.h
new file mode 100644
index 00000000000000..e7693576989c5a
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/epoll_create.h
@@ -0,0 +1,44 @@
+//===----------------------------------------------------------------------===//
+//
+// 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_create.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_EPOLL_CREATE_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_EPOLL_CREATE_H
+
+#include "hdr/errno_macros.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_create(int size) {
+#ifdef SYS_epoll_create
+ return syscall_checked<int>(SYS_epoll_create, size);
+#elif defined(SYS_epoll_create1)
+ if (size == 0)
+ return Error(EINVAL);
+ return syscall_checked<int>(SYS_epoll_create1, 0);
+#else
+#error \
+ "epoll_create and epoll_create1 are unavailable. Unable to build epoll_create."
+#endif
+}
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_EPOLL_CREATE_H
diff --git a/libc/src/sys/epoll/linux/CMakeLists.txt b/libc/src/sys/epoll/linux/CMakeLists.txt
index fc7617e11ed5c0..6def58ada31eae 100644
--- a/libc/src/sys/epoll/linux/CMakeLists.txt
+++ b/libc/src/sys/epoll/linux/CMakeLists.txt
@@ -5,8 +5,10 @@ add_entrypoint_object(
HDRS
../epoll_create.h
DEPENDS
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
+ libc.src.__support.OSUtil.linux.syscall_wrappers.epoll_create
+ libc.src.__support.common
+ libc.src.__support.libc_errno
+ libc.src.__support.macros.config
libc.src.errno.errno
)
diff --git a/libc/src/sys/epoll/linux/epoll_create.cpp b/libc/src/sys/epoll/linux/epoll_create.cpp
index dcd082b56f9adb..236233b24aefd7 100644
--- a/libc/src/sys/epoll/linux/epoll_create.cpp
+++ b/libc/src/sys/epoll/linux/epoll_create.cpp
@@ -8,37 +8,21 @@
#include "src/sys/epoll/epoll_create.h"
-#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/__support/OSUtil/linux/syscall_wrappers/epoll_create.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, epoll_create, ([[maybe_unused]] int size)) {
-#ifdef SYS_epoll_create
- int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_epoll_create, size);
-#elif defined(SYS_epoll_create1)
- if (size == 0) {
- libc_errno = EINVAL;
+LLVM_LIBC_FUNCTION(int, epoll_create, (int size)) {
+ auto result = linux_syscalls::epoll_create(size);
+ if (!result) {
+ libc_errno = result.error();
return -1;
}
- int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_epoll_create1, 0);
-#else
-#error \
- "epoll_create and epoll_create1 are unavailable. Unable to build epoll_create."
-#endif
-
- // A negative return value indicates an error with the magnitude of the
- // value being the error code.
- if (ret < 0) {
- libc_errno = -ret;
- return -1;
- }
-
- 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 adab1a680a5c19..43806ef615f29d 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2536,6 +2536,22 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_osutil_linux_syscall_wrappers_epoll_create",
+ hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/epoll_create.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_errno_macros",
+ ],
+)
+
libc_support_library(
name = "__support_osutil_linux_syscall_wrappers_epoll_create1",
hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/epoll_create1.h"],
@@ -19601,7 +19617,7 @@ libc_function(
":__support_common",
":__support_libc_errno",
":__support_macros_config",
- ":__support_osutil_syscall",
+ ":__support_osutil_linux_syscall_wrappers_epoll_create",
":errno",
],
)
More information about the libc-commits
mailing list