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

Connector Switch via libc-commits libc-commits at lists.llvm.org
Fri Oct 23 03:36:53 PDT 2026


https://github.com/c8ef created https://github.com/llvm/llvm-project/pull/234907

This PR move `epoll_create1` behind the centralized syscall wrappers, following `libc/docs/dev/syscall_wrapper_refactor.md`.

>From 6014c0ddcd3abd60c2cc5d6004b0475826d974b7 Mon Sep 17 00:00:00 2001
From: c8ef <c8ef at outlook.com>
Date: Fri, 23 Oct 2026 18:35:21 +0800
Subject: [PATCH] [libc] Use a syscall wrapper for epoll_create1

---
 .../linux/syscall_wrappers/CMakeLists.txt     | 12 +++++++
 .../linux/syscall_wrappers/epoll_create1.h    | 34 +++++++++++++++++++
 libc/src/sys/epoll/linux/CMakeLists.txt       |  6 ++--
 libc/src/sys/epoll/linux/epoll_create1.cpp    | 15 +++-----
 .../llvm-project-overlay/libc/BUILD.bazel     | 17 +++++++++-
 5 files changed, 71 insertions(+), 13 deletions(-)
 create mode 100644 libc/src/__support/OSUtil/linux/syscall_wrappers/epoll_create1.h

diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index c7c1f4b9d204f1..6701bb24f081d2 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
@@ -1266,6 +1266,18 @@ add_header_library(
     libc.include.sys_syscall
 )
 
+add_header_library(
+  epoll_create1
+  HDRS
+    epoll_create1.h
+  DEPENDS
+    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_ctl
   HDRS
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/epoll_create1.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/epoll_create1.h
new file mode 100644
index 00000000000000..2997bfd620b81c
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/epoll_create1.h
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// 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_create1.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_EPOLL_CREATE1_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_EPOLL_CREATE1_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_create1(int flags) {
+  return syscall_checked<int>(SYS_epoll_create1, flags);
+}
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_EPOLL_CREATE1_H
diff --git a/libc/src/sys/epoll/linux/CMakeLists.txt b/libc/src/sys/epoll/linux/CMakeLists.txt
index 80affd344d93ee..2fab33194febf4 100644
--- a/libc/src/sys/epoll/linux/CMakeLists.txt
+++ b/libc/src/sys/epoll/linux/CMakeLists.txt
@@ -17,8 +17,10 @@ add_entrypoint_object(
   HDRS
     ../epoll_create1.h
   DEPENDS
-    libc.include.sys_syscall
-    libc.src.__support.OSUtil.osutil
+    libc.src.__support.OSUtil.linux.syscall_wrappers.epoll_create1
+    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_create1.cpp b/libc/src/sys/epoll/linux/epoll_create1.cpp
index 3c60090fb7b41d..90a4b35c430ba9 100644
--- a/libc/src/sys/epoll/linux/epoll_create1.cpp
+++ b/libc/src/sys/epoll/linux/epoll_create1.cpp
@@ -8,25 +8,20 @@
 
 #include "src/sys/epoll/epoll_create1.h"
 
-#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/__support/OSUtil/linux/syscall_wrappers/epoll_create1.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_create1, (int flags)) {
-  int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_epoll_create1, flags);
-
-  // 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_create1(flags);
+  if (!result) {
+    libc_errno = result.error();
     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 e4678d68661a5b..193b23e2d1d0f1 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2520,6 +2520,21 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_osutil_linux_syscall_wrappers_epoll_create1",
+    hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/epoll_create1.h"],
+    target_compatible_with = select({
+        "@platforms//os:linux": [],
+        "//conditions:default": ["@platforms//:incompatible"],
+    }),
+    deps = [
+        ":__support_common",
+        ":__support_error_or",
+        ":__support_macros_config",
+        ":__support_osutil_syscall",
+    ],
+)
+
 libc_support_library(
     name = "__support_osutil_linux_syscall_wrappers_epoll_ctl",
     hdrs = ["src/__support/OSUtil/linux/syscall_wrappers/epoll_ctl.h"],
@@ -19340,7 +19355,7 @@ libc_function(
         ":__support_common",
         ":__support_libc_errno",
         ":__support_macros_config",
-        ":__support_osutil_syscall",
+        ":__support_osutil_linux_syscall_wrappers_epoll_create1",
         ":errno",
     ],
 )



More information about the libc-commits mailing list