[libc-commits] [libc] [llvm] [reland][libc] add epoll_wait functions (PR #79635)

via libc-commits libc-commits at lists.llvm.org
Mon Jan 29 16:34:11 PST 2024


https://github.com/michaelrj-google updated https://github.com/llvm/llvm-project/pull/79635

>From 74ae5b05e9f661bab9ad0faa369b7cd17781ca3a Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Thu, 25 Jan 2024 13:49:13 -0800
Subject: [PATCH 1/7] [libc] add epoll_wait functions

The epoll_wait functions are syscall wrappers that were requested by
upstream users. This patch adds them, as well as their header and types.

The tests are currently incomplete since they require epoll_create to
properly test epoll_wait. That will be added in a followup patch since
this one is already very large.
---
 libc/config/linux/api.td                      | 12 ++-
 libc/config/linux/syscall_numbers.h.inc       |  4 +
 libc/config/linux/x86_64/entrypoints.txt      |  5 ++
 libc/config/linux/x86_64/headers.txt          |  1 +
 libc/include/CMakeLists.txt                   | 11 +++
 libc/include/llvm-libc-types/CMakeLists.txt   |  2 +
 .../llvm-libc-types/struct_epoll_data.h       | 21 +++++
 .../llvm-libc-types/struct_epoll_event.h      | 19 +++++
 libc/include/sys/epoll.h.def                  | 16 ++++
 libc/spec/gnu_ext.td                          |  4 +-
 libc/spec/linux.td                            | 77 +++++++++++++++++++
 libc/src/sys/CMakeLists.txt                   |  1 +
 libc/src/sys/epoll/CMakeLists.txt             | 24 ++++++
 libc/src/sys/epoll/epoll_pwait.h              | 23 ++++++
 libc/src/sys/epoll/epoll_pwait2.h             | 24 ++++++
 libc/src/sys/epoll/epoll_wait.h               | 21 +++++
 libc/src/sys/epoll/linux/CMakeLists.txt       | 41 ++++++++++
 libc/src/sys/epoll/linux/epoll_pwait.cpp      | 38 +++++++++
 libc/src/sys/epoll/linux/epoll_pwait2.cpp     | 40 ++++++++++
 libc/src/sys/epoll/linux/epoll_wait.cpp       | 35 +++++++++
 libc/test/src/sys/CMakeLists.txt              |  1 +
 libc/test/src/sys/epoll/CMakeLists.txt        |  3 +
 libc/test/src/sys/epoll/linux/CMakeLists.txt  | 39 ++++++++++
 .../src/sys/epoll/linux/epoll_pwait2_test.cpp | 20 +++++
 .../src/sys/epoll/linux/epoll_pwait_test.cpp  | 20 +++++
 .../src/sys/epoll/linux/epoll_wait_test.cpp   | 20 +++++
 .../llvm-project-overlay/libc/BUILD.bazel     | 32 ++++++++
 .../libc/test/src/sys/epoll/BUILD.bazel       | 35 +++++++++
 28 files changed, 584 insertions(+), 5 deletions(-)
 create mode 100644 libc/include/llvm-libc-types/struct_epoll_data.h
 create mode 100644 libc/include/llvm-libc-types/struct_epoll_event.h
 create mode 100644 libc/include/sys/epoll.h.def
 create mode 100644 libc/src/sys/epoll/CMakeLists.txt
 create mode 100644 libc/src/sys/epoll/epoll_pwait.h
 create mode 100644 libc/src/sys/epoll/epoll_pwait2.h
 create mode 100644 libc/src/sys/epoll/epoll_wait.h
 create mode 100644 libc/src/sys/epoll/linux/CMakeLists.txt
 create mode 100644 libc/src/sys/epoll/linux/epoll_pwait.cpp
 create mode 100644 libc/src/sys/epoll/linux/epoll_pwait2.cpp
 create mode 100644 libc/src/sys/epoll/linux/epoll_wait.cpp
 create mode 100644 libc/test/src/sys/epoll/CMakeLists.txt
 create mode 100644 libc/test/src/sys/epoll/linux/CMakeLists.txt
 create mode 100644 libc/test/src/sys/epoll/linux/epoll_pwait2_test.cpp
 create mode 100644 libc/test/src/sys/epoll/linux/epoll_pwait_test.cpp
 create mode 100644 libc/test/src/sys/epoll/linux/epoll_wait_test.cpp
 create mode 100644 utils/bazel/llvm-project-overlay/libc/test/src/sys/epoll/BUILD.bazel

diff --git a/libc/config/linux/api.td b/libc/config/linux/api.td
index 85f6b59264eb0..b8fe16cc0c79e 100644
--- a/libc/config/linux/api.td
+++ b/libc/config/linux/api.td
@@ -1,11 +1,11 @@
 include "config/public_api.td"
 
-include "spec/bsd_ext.td"
-include "spec/gnu_ext.td"
+include "spec/stdc.td"
+include "spec/posix.td"
 include "spec/linux.td"
+include "spec/gnu_ext.td"
+include "spec/bsd_ext.td"
 include "spec/llvm_libc_ext.td"
-include "spec/posix.td"
-include "spec/stdc.td"
 
 def AssertMacro : MacroDef<"assert"> {
   let Defn = [{
@@ -242,6 +242,10 @@ def SysUtsNameAPI : PublicAPI<"sys/utsname.h"> {
   let Types = ["struct utsname"];
 }
 
+def SysEpollAPI : PublicAPI<"sys/epoll.h"> {
+  let Types = ["struct epoll_event", "struct epoll_data", "sigset_t", "struct timespec"];
+}
+
 def SpawnAPI : PublicAPI<"spawn.h"> {
   let Types = ["mode_t", "pid_t", "posix_spawnattr_t", "posix_spawn_file_actions_t"];
 }
diff --git a/libc/config/linux/syscall_numbers.h.inc b/libc/config/linux/syscall_numbers.h.inc
index 5bbb08878ef9d..9f910c5f9042a 100644
--- a/libc/config/linux/syscall_numbers.h.inc
+++ b/libc/config/linux/syscall_numbers.h.inc
@@ -258,6 +258,10 @@
 #define SYS_epoll_pwait __NR_epoll_pwait
 #endif
 
+#ifdef __NR_epoll_pwait2
+#define SYS_epoll_pwait2 __NR_epoll_pwait2
+#endif
+
 #ifdef __NR_epoll_wait
 #define SYS_epoll_wait __NR_epoll_wait
 #endif
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 3812d9586121e..f0e5a0f3bd8f0 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -136,6 +136,11 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.stdio.scanf
     libc.src.stdio.fscanf
 
+    # sys/epoll.h entrypoints
+    libc.src.sys.epoll.epoll_wait
+    libc.src.sys.epoll.epoll_pwait
+    libc.src.sys.epoll.epoll_pwait2
+
     # sys/mman.h entrypoints
     libc.src.sys.mman.madvise
     libc.src.sys.mman.mmap
diff --git a/libc/config/linux/x86_64/headers.txt b/libc/config/linux/x86_64/headers.txt
index d103176897a74..e2bea1fb31f36 100644
--- a/libc/config/linux/x86_64/headers.txt
+++ b/libc/config/linux/x86_64/headers.txt
@@ -29,6 +29,7 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.arpa_inet
 
     libc.include.sys_auxv
+    libc.include.sys_epoll
     libc.include.sys_ioctl
     libc.include.sys_mman
     libc.include.sys_prctl
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 89fffd1022758..24e50fb6a47e0 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -332,6 +332,17 @@ add_gen_header(
     .llvm-libc-macros.sys_auxv_macros
 )
 
+add_gen_header(
+  sys_epoll
+  DEF_FILE sys/epoll.h.def
+  GEN_HDR sys/epoll.h
+  DEPENDS
+    .llvm_libc_common_h
+    .llvm-libc-types.struct_epoll_event
+    .llvm-libc-types.struct_epoll_data
+    .llvm-libc-types.sigset_t
+)
+
 add_gen_header(
   sys_ioctl
   DEF_FILE sys/ioctl.h.def
diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index 500900ffa0bbb..6f004d2d64697 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -96,3 +96,5 @@ add_header(rpc_opcodes_t HDR rpc_opcodes_t.h)
 add_header(ACTION HDR ACTION.h)
 add_header(ENTRY HDR ENTRY.h)
 add_header(struct_hsearch_data HDR struct_hsearch_data.h)
+add_header(struct_epoll_event HDR struct_epoll_event.h)
+add_header(struct_epoll_data HDR struct_epoll_data.h)
diff --git a/libc/include/llvm-libc-types/struct_epoll_data.h b/libc/include/llvm-libc-types/struct_epoll_data.h
new file mode 100644
index 0000000000000..c363171089f11
--- /dev/null
+++ b/libc/include/llvm-libc-types/struct_epoll_data.h
@@ -0,0 +1,21 @@
+//===-- Definition of epoll_data type -------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef __LLVM_LIBC_TYPES_EPOLL_DATA_H__
+#define __LLVM_LIBC_TYPES_EPOLL_DATA_H__
+
+union epoll_data {
+  void *ptr;
+  int fd;
+  __UINT32_TYPE__ u32;
+  __UINT64_TYPE__ u64;
+};
+
+typedef union epoll_data epoll_data_t;
+
+#endif // __LLVM_LIBC_TYPES_EPOLL_DATA_H__
diff --git a/libc/include/llvm-libc-types/struct_epoll_event.h b/libc/include/llvm-libc-types/struct_epoll_event.h
new file mode 100644
index 0000000000000..425dd51e030cc
--- /dev/null
+++ b/libc/include/llvm-libc-types/struct_epoll_event.h
@@ -0,0 +1,19 @@
+//===-- Definition of epoll_event type ------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef __LLVM_LIBC_TYPES_EPOLL_EVENT_H__
+#define __LLVM_LIBC_TYPES_EPOLL_EVENT_H__
+
+#include <llvm-libc-types/epoll_data.h>
+
+typedef struct epoll_event {
+  __UINT32_TYPE__ events;
+  epoll_data_t data;
+};
+
+#endif // __LLVM_LIBC_TYPES_EPOLL_EVENT_H__
diff --git a/libc/include/sys/epoll.h.def b/libc/include/sys/epoll.h.def
new file mode 100644
index 0000000000000..490fad91db3c3
--- /dev/null
+++ b/libc/include/sys/epoll.h.def
@@ -0,0 +1,16 @@
+//===-- Linux header epoll.h ----------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SYS_EPOLL_H
+#define LLVM_LIBC_SYS_EPOLL_H
+
+#include <__llvm-libc-common.h>
+
+%%public_api()
+
+#endif // LLVM_LIBC_SYS_EPOLL_H
diff --git a/libc/spec/gnu_ext.td b/libc/spec/gnu_ext.td
index cb0407c84d4e2..1b1b35b4d028b 100644
--- a/libc/spec/gnu_ext.td
+++ b/libc/spec/gnu_ext.td
@@ -238,7 +238,9 @@ def GnuExtensions : StandardSpec<"GNUExtensions"> {
       [], // Macros
       [], // Types
       [], // Enumerations
-      []  // Functions
+      [
+        //TODO: Add getauxval here
+      ]  // Functions
   >;
 
   HeaderSpec SendFile = HeaderSpec<
diff --git a/libc/spec/linux.td b/libc/spec/linux.td
index eab0a987b920c..9fa8734db7eba 100644
--- a/libc/spec/linux.td
+++ b/libc/spec/linux.td
@@ -1,3 +1,8 @@
+def StructEpollEvent : NamedType<"struct epoll_event">;
+def StructEpollEventPtr : PtrType<StructEpollEvent>;
+
+def StructEpollData : NamedType<"struct epoll_data">;
+
 def Linux : StandardSpec<"Linux"> {
   HeaderSpec Errno = HeaderSpec<
       "errno.h",
@@ -137,6 +142,77 @@ def Linux : StandardSpec<"Linux"> {
       []  // Functions
   >;
 
+
+  HeaderSpec SysEpoll = HeaderSpec<
+      "sys/epoll.h",
+      [], // Macros
+      [
+        StructEpollEvent,
+        StructEpollData,
+        SigSetType,
+        StructTimeSpec,
+      ], // Types
+      [], // Enumerations
+      [
+        FunctionSpec<
+          "epoll_create",
+          RetValSpec<IntType>,
+          [
+            ArgSpec<IntType>
+          ]
+        >,
+        FunctionSpec<
+          "epoll_create1",
+          RetValSpec<IntType>,
+          [
+            ArgSpec<IntType>
+          ]
+        >,
+        FunctionSpec<
+          "epoll_ctl",
+          RetValSpec<IntType>,
+          [
+            ArgSpec<IntType>,
+            ArgSpec<IntType>,
+            ArgSpec<IntType>,
+            ArgSpec<StructEpollEventPtr>
+          ]
+        >,
+        FunctionSpec<
+          "epoll_wait",
+          RetValSpec<IntType>,
+          [
+            ArgSpec<IntType>,
+            ArgSpec<StructEpollEventPtr>,
+            ArgSpec<IntType>,
+            ArgSpec<IntType>
+          ]
+        >,
+        FunctionSpec<
+          "epoll_pwait",
+          RetValSpec<IntType>,
+          [
+            ArgSpec<IntType>,
+            ArgSpec<StructEpollEventPtr>,
+            ArgSpec<IntType>,
+            ArgSpec<IntType>,
+            ArgSpec<SigSetPtrType>
+          ]
+        >,
+        FunctionSpec<
+          "epoll_pwait2",
+          RetValSpec<IntType>,
+          [
+            ArgSpec<IntType>,
+            ArgSpec<StructEpollEventPtr>,
+            ArgSpec<IntType>,
+            ArgSpec<ConstStructTimeSpecPtr>,
+            ArgSpec<SigSetPtrType>
+          ]
+        >,
+      ]  // Functions
+  >;
+
   HeaderSpec Signal = HeaderSpec<
       "signal.h",
       [
@@ -181,6 +257,7 @@ def Linux : StandardSpec<"Linux"> {
 
   let Headers = [
     Errno,
+    SysEpoll,
     SysMMan,
     SysPrctl,
     SysRandom,
diff --git a/libc/src/sys/CMakeLists.txt b/libc/src/sys/CMakeLists.txt
index 81098294176ad..57ea7b4beaca1 100644
--- a/libc/src/sys/CMakeLists.txt
+++ b/libc/src/sys/CMakeLists.txt
@@ -1,4 +1,5 @@
 add_subdirectory(auxv)
+add_subdirectory(epoll)
 add_subdirectory(mman)
 add_subdirectory(random)
 add_subdirectory(resource)
diff --git a/libc/src/sys/epoll/CMakeLists.txt b/libc/src/sys/epoll/CMakeLists.txt
new file mode 100644
index 0000000000000..d4991a238e2a7
--- /dev/null
+++ b/libc/src/sys/epoll/CMakeLists.txt
@@ -0,0 +1,24 @@
+if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
+  add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
+endif()
+
+add_entrypoint_object(
+  epoll_wait
+  ALIAS
+  DEPENDS
+    .${LIBC_TARGET_OS}.epoll_wait
+)
+
+add_entrypoint_object(
+  epoll_pwait
+  ALIAS
+  DEPENDS
+    .${LIBC_TARGET_OS}.epoll_pwait
+)
+
+add_entrypoint_object(
+  epoll_pwait2
+  ALIAS
+  DEPENDS
+    .${LIBC_TARGET_OS}.epoll_pwait2
+)
diff --git a/libc/src/sys/epoll/epoll_pwait.h b/libc/src/sys/epoll/epoll_pwait.h
new file mode 100644
index 0000000000000..f4042cc9888f6
--- /dev/null
+++ b/libc/src/sys/epoll/epoll_pwait.h
@@ -0,0 +1,23 @@
+//===-- Implementation header for epoll_pwait function ----------*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_PWAIT_H
+#define LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_PWAIT_H
+
+#include <signal.h>    // For sigset_t
+#include <sys/epoll.h> // For epoll_event
+
+namespace LIBC_NAMESPACE {
+
+// TODO: sigmask should be nullable
+int epoll_pwait(int epfd, struct epoll_event *events, int maxevents,
+                int timeout, const sigset_t *sigmask);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_PWAIT_H
diff --git a/libc/src/sys/epoll/epoll_pwait2.h b/libc/src/sys/epoll/epoll_pwait2.h
new file mode 100644
index 0000000000000..17ea4b2c226a6
--- /dev/null
+++ b/libc/src/sys/epoll/epoll_pwait2.h
@@ -0,0 +1,24 @@
+//===-- Implementation header for epoll_pwait2 function ---------*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_PWAIT2_H
+#define LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_PWAIT2_H
+
+#include <signal.h>    // For sigset_t
+#include <sys/epoll.h> // For epoll_event
+#include <time.h>      // For timespec
+
+namespace LIBC_NAMESPACE {
+
+// TODO: sigmask and timeout should be nullable
+int epoll_pwait2(int epfd, struct epoll_event *events, int maxevents,
+                 const struct timespec *timeout, const sigset_t *sigmask);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_PWAIT2_H
diff --git a/libc/src/sys/epoll/epoll_wait.h b/libc/src/sys/epoll/epoll_wait.h
new file mode 100644
index 0000000000000..b8f768aabf16d
--- /dev/null
+++ b/libc/src/sys/epoll/epoll_wait.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for epoll_wait function -----------*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_WAIT_H
+#define LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_WAIT_H
+
+#include <sys/epoll.h> // For epoll_event
+
+namespace LIBC_NAMESPACE {
+
+int epoll_wait(int epfd, struct epoll_event *events, int maxevents,
+               int timeout);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_WAIT_H
diff --git a/libc/src/sys/epoll/linux/CMakeLists.txt b/libc/src/sys/epoll/linux/CMakeLists.txt
new file mode 100644
index 0000000000000..a27905d962dc5
--- /dev/null
+++ b/libc/src/sys/epoll/linux/CMakeLists.txt
@@ -0,0 +1,41 @@
+add_entrypoint_object(
+  epoll_wait
+  SRCS
+    epoll_wait.cpp
+  HDRS
+    ../epoll_wait.h
+  DEPENDS
+    libc.include.sys_epoll
+    libc.include.sys_syscall
+    libc.src.__support.OSUtil.osutil
+    libc.src.errno.errno
+)
+
+add_entrypoint_object(
+  epoll_pwait
+  SRCS
+    epoll_pwait.cpp
+  HDRS
+    ../epoll_pwait.h
+  DEPENDS
+    libc.include.sys_epoll
+    libc.include.signal
+    libc.include.sys_syscall
+    libc.src.__support.OSUtil.osutil
+    libc.src.errno.errno
+)
+
+add_entrypoint_object(
+  epoll_pwait2
+  SRCS
+    epoll_pwait2.cpp
+  HDRS
+    ../epoll_pwait2.h
+  DEPENDS
+    libc.include.sys_epoll
+    libc.include.signal
+    libc.include.time
+    libc.include.sys_syscall
+    libc.src.__support.OSUtil.osutil
+    libc.src.errno.errno
+)
diff --git a/libc/src/sys/epoll/linux/epoll_pwait.cpp b/libc/src/sys/epoll/linux/epoll_pwait.cpp
new file mode 100644
index 0000000000000..e3a7b6e0393bd
--- /dev/null
+++ b/libc/src/sys/epoll/linux/epoll_pwait.cpp
@@ -0,0 +1,38 @@
+//===---------- Linux implementation of the epoll_pwait function ----------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/sys/epoll/epoll_pwait.h"
+
+#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/__support/common.h"
+
+#include "src/errno/libc_errno.h"
+#include <sys/syscall.h> // For syscall numbers.
+
+#include <signal.h> // For sigset_t
+
+namespace LIBC_NAMESPACE {
+
+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), sizeof(sigset_t));
+
+  // 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 0;
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/sys/epoll/linux/epoll_pwait2.cpp b/libc/src/sys/epoll/linux/epoll_pwait2.cpp
new file mode 100644
index 0000000000000..25ca0ae06f440
--- /dev/null
+++ b/libc/src/sys/epoll/linux/epoll_pwait2.cpp
@@ -0,0 +1,40 @@
+//===---------- Linux implementation of the epoll_pwait2 function ---------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/sys/epoll/epoll_pwait2.h"
+
+#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/__support/common.h"
+
+#include "src/errno/libc_errno.h"
+#include <sys/syscall.h> // For syscall numbers.
+
+#include <signal.h> // For sigset_t
+#include <time.h>   // For timespec
+
+namespace LIBC_NAMESPACE {
+
+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),
+      sizeof(sigset_t));
+
+  // 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 0;
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/sys/epoll/linux/epoll_wait.cpp b/libc/src/sys/epoll/linux/epoll_wait.cpp
new file mode 100644
index 0000000000000..b305575e099f2
--- /dev/null
+++ b/libc/src/sys/epoll/linux/epoll_wait.cpp
@@ -0,0 +1,35 @@
+//===---------- Linux implementation of the epoll_wait function -----------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/sys/epoll/epoll_wait.h"
+
+#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/__support/common.h"
+
+#include "src/errno/libc_errno.h"
+#include <sys/syscall.h> // For syscall numbers.
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(int, epoll_wait,
+                   (int epfd, struct epoll_event *events, int maxevents,
+                    int timeout)) {
+  int ret = LIBC_NAMESPACE::syscall_impl<int>(
+      SYS_epoll_wait, epfd, reinterpret_cast<long>(events), maxevents, timeout);
+
+  // 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 0;
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/test/src/sys/CMakeLists.txt b/libc/test/src/sys/CMakeLists.txt
index c7095456383b3..7f228e709046d 100644
--- a/libc/test/src/sys/CMakeLists.txt
+++ b/libc/test/src/sys/CMakeLists.txt
@@ -9,3 +9,4 @@ add_subdirectory(utsname)
 add_subdirectory(wait)
 add_subdirectory(prctl)
 add_subdirectory(auxv)
+add_subdirectory(epoll)
diff --git a/libc/test/src/sys/epoll/CMakeLists.txt b/libc/test/src/sys/epoll/CMakeLists.txt
new file mode 100644
index 0000000000000..b4bbe81c92ff2
--- /dev/null
+++ b/libc/test/src/sys/epoll/CMakeLists.txt
@@ -0,0 +1,3 @@
+if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
+  add_subdirectory(${LIBC_TARGET_OS})
+endif()
diff --git a/libc/test/src/sys/epoll/linux/CMakeLists.txt b/libc/test/src/sys/epoll/linux/CMakeLists.txt
new file mode 100644
index 0000000000000..e346af2328db2
--- /dev/null
+++ b/libc/test/src/sys/epoll/linux/CMakeLists.txt
@@ -0,0 +1,39 @@
+add_custom_target(libc_sys_epoll_unittests)
+add_libc_unittest(
+  epoll_wait_test
+  SUITE
+    libc_sys_epoll_unittests
+  SRCS
+    epoll_wait_test.cpp
+  DEPENDS
+    libc.include.sys_epoll
+    libc.src.errno.errno
+    libc.src.sys.epoll.epoll_wait
+    libc.test.UnitTest.ErrnoSetterMatcher
+)
+
+add_libc_unittest(
+  epoll_pwait_test
+  SUITE
+    libc_sys_epoll_unittests
+  SRCS
+    epoll_pwait_test.cpp
+  DEPENDS
+    libc.include.sys_epoll
+    libc.src.errno.errno
+    libc.src.sys.epoll.epoll_pwait
+    libc.test.UnitTest.ErrnoSetterMatcher
+)
+
+add_libc_unittest(
+  epoll_pwait2_test
+  SUITE
+    libc_sys_epoll_unittests
+  SRCS
+    epoll_pwait2_test.cpp
+  DEPENDS
+    libc.include.sys_epoll
+    libc.src.errno.errno
+    libc.src.sys.epoll.epoll_pwait2
+    libc.test.UnitTest.ErrnoSetterMatcher
+)
diff --git a/libc/test/src/sys/epoll/linux/epoll_pwait2_test.cpp b/libc/test/src/sys/epoll/linux/epoll_pwait2_test.cpp
new file mode 100644
index 0000000000000..83fe12bb8eb65
--- /dev/null
+++ b/libc/test/src/sys/epoll/linux/epoll_pwait2_test.cpp
@@ -0,0 +1,20 @@
+//===-- Unittests for epoll_pwait2 ----------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+#include "src/errno/libc_errno.h"
+#include "src/sys/epoll/epoll_pwait2.h"
+#include "test/UnitTest/ErrnoSetterMatcher.h"
+#include "test/UnitTest/Test.h"
+
+using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
+
+TEST(LlvmLibcEpollWaitTest, Basic) {
+  EXPECT_THAT(LIBC_NAMESPACE::epoll_pwait2(-1, nullptr, 0, nullptr, nullptr),
+              returns(EQ(-1ul)).with_errno(EQ(EINVAL)));
+}
+
+// TODO: Complete these tests when epoll_create is implemented.
diff --git a/libc/test/src/sys/epoll/linux/epoll_pwait_test.cpp b/libc/test/src/sys/epoll/linux/epoll_pwait_test.cpp
new file mode 100644
index 0000000000000..217facbfcebb9
--- /dev/null
+++ b/libc/test/src/sys/epoll/linux/epoll_pwait_test.cpp
@@ -0,0 +1,20 @@
+//===-- Unittests for epoll_pwait -----------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+#include "src/errno/libc_errno.h"
+#include "src/sys/epoll/epoll_pwait.h"
+#include "test/UnitTest/ErrnoSetterMatcher.h"
+#include "test/UnitTest/Test.h"
+
+using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
+
+TEST(LlvmLibcEpollWaitTest, Basic) {
+  EXPECT_THAT(LIBC_NAMESPACE::epoll_pwait(-1, nullptr, 0, 0, nullptr),
+              returns(EQ(-1ul)).with_errno(EQ(EINVAL)));
+}
+
+// TODO: Complete these tests when epoll_create is implemented.
diff --git a/libc/test/src/sys/epoll/linux/epoll_wait_test.cpp b/libc/test/src/sys/epoll/linux/epoll_wait_test.cpp
new file mode 100644
index 0000000000000..57fef3f690b62
--- /dev/null
+++ b/libc/test/src/sys/epoll/linux/epoll_wait_test.cpp
@@ -0,0 +1,20 @@
+//===-- Unittests for epoll_wait ------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+#include "src/errno/libc_errno.h"
+#include "src/sys/epoll/epoll_wait.h"
+#include "test/UnitTest/ErrnoSetterMatcher.h"
+#include "test/UnitTest/Test.h"
+
+using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
+
+TEST(LlvmLibcEpollWaitTest, Basic) {
+  EXPECT_THAT(LIBC_NAMESPACE::epoll_wait(-1, nullptr, 0, 0),
+              returns(EQ(-1ul)).with_errno(EQ(EINVAL)));
+}
+
+// TODO: Complete these tests when epoll_create is implemented.
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index e601fa7e4377d..3b8ce044b7fc7 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2942,3 +2942,35 @@ libc_function(
         ":vfprintf_internal",
     ],
 )
+
+############################## sys/epoll targets ###############################
+
+libc_function(
+    name = "epoll_wait",
+    srcs = ["src/sys/epoll/linux/epoll_wait.cpp"],
+    hdrs = ["src/sys/epoll/epoll_wait.h"],
+    deps = [
+        ":__support_osutil_syscall",
+        ":errno",
+    ],
+)
+
+libc_function(
+    name = "epoll_pwait",
+    srcs = ["src/sys/epoll/linux/epoll_pwait.cpp"],
+    hdrs = ["src/sys/epoll/epoll_pwait.h"],
+    deps = [
+        ":__support_osutil_syscall",
+        ":errno",
+    ],
+)
+
+libc_function(
+    name = "epoll_pwait2",
+    srcs = ["src/sys/epoll/linux/epoll_pwait2.cpp"],
+    hdrs = ["src/sys/epoll/epoll_pwait2.h"],
+    deps = [
+        ":__support_osutil_syscall",
+        ":errno",
+    ],
+)
diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/sys/epoll/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/sys/epoll/BUILD.bazel
new file mode 100644
index 0000000000000..e0afce60e6bc2
--- /dev/null
+++ b/utils/bazel/llvm-project-overlay/libc/test/src/sys/epoll/BUILD.bazel
@@ -0,0 +1,35 @@
+# This file is licensed 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
+
+# Tests for LLVM libc string.h functions.
+
+load("//libc/test:libc_test_rules.bzl", "libc_test")
+
+package(default_visibility = ["//visibility:public"])
+
+licenses(["notice"])
+
+libc_test(
+    name = "epoll_wait_test",
+    srcs = ["linux/epoll_wait_test.cpp"],
+    libc_function_deps = [
+        "//libc:epoll_wait",
+    ],
+)
+
+libc_test(
+    name = "epoll_pwait_test",
+    srcs = ["linux/epoll_pwait_test.cpp"],
+    libc_function_deps = [
+        "//libc:epoll_pwait",
+    ],
+)
+
+libc_test(
+    name = "epoll_pwait2_test",
+    srcs = ["linux/epoll_pwait2_test.cpp"],
+    libc_function_deps = [
+        "//libc:epoll_pwait2",
+    ],
+)

>From fe24b104a7a990b87348fdb3794a85a891d08ad0 Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Thu, 25 Jan 2024 14:44:52 -0800
Subject: [PATCH 2/7] enable epoll_wait functions on all linux targets

---
 libc/config/linux/aarch64/entrypoints.txt | 5 +++++
 libc/config/linux/arm/entrypoints.txt     | 6 ++++++
 libc/config/linux/riscv/entrypoints.txt   | 5 +++++
 3 files changed, 16 insertions(+)

diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 52f1d2bce34f4..beec23570ebfc 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -172,6 +172,11 @@ set(TARGET_LIBC_ENTRYPOINTS
     # sys/auxv.h entrypoints
     libc.src.sys.auxv.getauxval
 
+    # sys/epoll.h entrypoints
+    libc.src.sys.epoll.epoll_wait
+    libc.src.sys.epoll.epoll_pwait
+    libc.src.sys.epoll.epoll_pwait2
+
     # termios.h entrypoints
     libc.src.termios.cfgetispeed
     libc.src.termios.cfgetospeed
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index c75ac2302d4ac..f3f42a4cbc1e1 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -95,6 +95,12 @@ set(TARGET_LIBC_ENTRYPOINTS
 
     # sys/prctl.h entrypoints
     libc.src.sys.prctl.prctl
+
+    # sys/epoll.h entrypoints
+    libc.src.sys.epoll.epoll_wait
+    libc.src.sys.epoll.epoll_pwait
+    libc.src.sys.epoll.epoll_pwait2
+
 )
 
 set(TARGET_LIBM_ENTRYPOINTS
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index a257f3f8d64ab..a33fd1b0993f0 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -178,6 +178,11 @@ set(TARGET_LIBC_ENTRYPOINTS
     # sys/auxv.h entrypoints
     libc.src.sys.auxv.getauxval
 
+    # sys/epoll.h entrypoints
+    libc.src.sys.epoll.epoll_wait
+    libc.src.sys.epoll.epoll_pwait
+    libc.src.sys.epoll.epoll_pwait2
+
     # termios.h entrypoints
     libc.src.termios.cfgetispeed
     libc.src.termios.cfgetospeed

>From 1b8798eee567cf9c2958e1c3d039fa333a6a2115 Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Thu, 25 Jan 2024 15:19:11 -0800
Subject: [PATCH 3/7] add epoll to headers for other linux targets

I forgot to do this when I was adding the entrypoints.
---
 libc/config/linux/aarch64/headers.txt | 1 +
 libc/config/linux/arm/headers.txt     | 2 ++
 libc/config/linux/riscv/headers.txt   | 1 +
 3 files changed, 4 insertions(+)

diff --git a/libc/config/linux/aarch64/headers.txt b/libc/config/linux/aarch64/headers.txt
index 60d978bcaa76e..4c8620951ccfe 100644
--- a/libc/config/linux/aarch64/headers.txt
+++ b/libc/config/linux/aarch64/headers.txt
@@ -24,4 +24,5 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.unistd
 
     libc.include.sys_ioctl
+    libc.include.sys_epoll
 )
diff --git a/libc/config/linux/arm/headers.txt b/libc/config/linux/arm/headers.txt
index 9e6ee51675916..e9ded77f19566 100644
--- a/libc/config/linux/arm/headers.txt
+++ b/libc/config/linux/arm/headers.txt
@@ -9,4 +9,6 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.string
     libc.include.strings
     libc.include.search
+
+    libc.include.sys_epoll
 )
diff --git a/libc/config/linux/riscv/headers.txt b/libc/config/linux/riscv/headers.txt
index 0ade63dc5933b..7cd1a9d63314d 100644
--- a/libc/config/linux/riscv/headers.txt
+++ b/libc/config/linux/riscv/headers.txt
@@ -29,6 +29,7 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.arpa_inet
 
     libc.include.sys_auxv
+    libc.include.sys_epoll
     libc.include.sys_ioctl
     libc.include.sys_mman
     libc.include.sys_prctl

>From d0a8b2e5fe10502ff820074a448cbc0b46cc09a5 Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Fri, 26 Jan 2024 11:02:02 -0800
Subject: [PATCH 4/7] disable entrypoints on non-x86 platforms, fix include
 paths

---
 libc/config/linux/aarch64/entrypoints.txt         | 7 ++++---
 libc/config/linux/aarch64/headers.txt             | 3 ++-
 libc/config/linux/arm/entrypoints.txt             | 7 ++++---
 libc/config/linux/arm/headers.txt                 | 3 ++-
 libc/config/linux/riscv/entrypoints.txt           | 7 ++++---
 libc/config/linux/riscv/headers.txt               | 3 ++-
 libc/include/llvm-libc-types/struct_epoll_event.h | 4 ++--
 libc/src/sys/epoll/epoll_pwait.h                  | 4 ++--
 libc/src/sys/epoll/epoll_pwait2.h                 | 6 +++---
 libc/src/sys/epoll/epoll_wait.h                   | 2 +-
 libc/src/sys/epoll/linux/epoll_pwait.cpp          | 3 ++-
 libc/src/sys/epoll/linux/epoll_pwait2.cpp         | 5 +++--
 libc/src/sys/epoll/linux/epoll_wait.cpp           | 2 ++
 13 files changed, 33 insertions(+), 23 deletions(-)

diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index beec23570ebfc..5ad0c12f97b8d 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -173,9 +173,10 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.sys.auxv.getauxval
 
     # sys/epoll.h entrypoints
-    libc.src.sys.epoll.epoll_wait
-    libc.src.sys.epoll.epoll_pwait
-    libc.src.sys.epoll.epoll_pwait2
+    # Disabled due to epoll_wait syscalls not being available on this platform.
+    # libc.src.sys.epoll.epoll_wait
+    # libc.src.sys.epoll.epoll_pwait
+    # libc.src.sys.epoll.epoll_pwait2
 
     # termios.h entrypoints
     libc.src.termios.cfgetispeed
diff --git a/libc/config/linux/aarch64/headers.txt b/libc/config/linux/aarch64/headers.txt
index 4c8620951ccfe..f1f0e2e20245c 100644
--- a/libc/config/linux/aarch64/headers.txt
+++ b/libc/config/linux/aarch64/headers.txt
@@ -24,5 +24,6 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.unistd
 
     libc.include.sys_ioctl
-    libc.include.sys_epoll
+    # Disabled due to epoll_wait syscalls not being available on this platform.
+    # libc.include.sys_epoll
 )
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index f3f42a4cbc1e1..de3411636f7a7 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -97,9 +97,10 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.sys.prctl.prctl
 
     # sys/epoll.h entrypoints
-    libc.src.sys.epoll.epoll_wait
-    libc.src.sys.epoll.epoll_pwait
-    libc.src.sys.epoll.epoll_pwait2
+    # Disabled due to epoll_wait syscalls not being available on this platform.
+    # libc.src.sys.epoll.epoll_wait
+    # libc.src.sys.epoll.epoll_pwait
+    # libc.src.sys.epoll.epoll_pwait2
 
 )
 
diff --git a/libc/config/linux/arm/headers.txt b/libc/config/linux/arm/headers.txt
index e9ded77f19566..57e26914668c0 100644
--- a/libc/config/linux/arm/headers.txt
+++ b/libc/config/linux/arm/headers.txt
@@ -10,5 +10,6 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.strings
     libc.include.search
 
-    libc.include.sys_epoll
+    # Disabled due to epoll_wait syscalls not being available on this platform.
+    # libc.include.sys_epoll
 )
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index a33fd1b0993f0..7c4e8b188c9bc 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -179,9 +179,10 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.sys.auxv.getauxval
 
     # sys/epoll.h entrypoints
-    libc.src.sys.epoll.epoll_wait
-    libc.src.sys.epoll.epoll_pwait
-    libc.src.sys.epoll.epoll_pwait2
+    # Disabled due to epoll_wait syscalls not being available on this platform.
+    # libc.src.sys.epoll.epoll_wait
+    # libc.src.sys.epoll.epoll_pwait
+    # libc.src.sys.epoll.epoll_pwait2
 
     # termios.h entrypoints
     libc.src.termios.cfgetispeed
diff --git a/libc/config/linux/riscv/headers.txt b/libc/config/linux/riscv/headers.txt
index 7cd1a9d63314d..ce00409a6123e 100644
--- a/libc/config/linux/riscv/headers.txt
+++ b/libc/config/linux/riscv/headers.txt
@@ -29,7 +29,8 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.arpa_inet
 
     libc.include.sys_auxv
-    libc.include.sys_epoll
+    # Disabled due to epoll_wait syscalls not being available on this platform.
+    # libc.include.sys_epoll
     libc.include.sys_ioctl
     libc.include.sys_mman
     libc.include.sys_prctl
diff --git a/libc/include/llvm-libc-types/struct_epoll_event.h b/libc/include/llvm-libc-types/struct_epoll_event.h
index 425dd51e030cc..f902a74838146 100644
--- a/libc/include/llvm-libc-types/struct_epoll_event.h
+++ b/libc/include/llvm-libc-types/struct_epoll_event.h
@@ -9,9 +9,9 @@
 #ifndef __LLVM_LIBC_TYPES_EPOLL_EVENT_H__
 #define __LLVM_LIBC_TYPES_EPOLL_EVENT_H__
 
-#include <llvm-libc-types/epoll_data.h>
+#include <llvm-libc-types/struct_epoll_data.h>
 
-typedef struct epoll_event {
+struct epoll_event {
   __UINT32_TYPE__ events;
   epoll_data_t data;
 };
diff --git a/libc/src/sys/epoll/epoll_pwait.h b/libc/src/sys/epoll/epoll_pwait.h
index f4042cc9888f6..b64470a49db04 100644
--- a/libc/src/sys/epoll/epoll_pwait.h
+++ b/libc/src/sys/epoll/epoll_pwait.h
@@ -9,8 +9,8 @@
 #ifndef LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_PWAIT_H
 #define LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_PWAIT_H
 
-#include <signal.h>    // For sigset_t
-#include <sys/epoll.h> // For epoll_event
+#include "include/llvm-libc-types/sigset_t.h"
+#include "include/llvm-libc-types/struct_epoll_event.h"
 
 namespace LIBC_NAMESPACE {
 
diff --git a/libc/src/sys/epoll/epoll_pwait2.h b/libc/src/sys/epoll/epoll_pwait2.h
index 17ea4b2c226a6..e35bfb86829a6 100644
--- a/libc/src/sys/epoll/epoll_pwait2.h
+++ b/libc/src/sys/epoll/epoll_pwait2.h
@@ -9,9 +9,9 @@
 #ifndef LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_PWAIT2_H
 #define LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_PWAIT2_H
 
-#include <signal.h>    // For sigset_t
-#include <sys/epoll.h> // For epoll_event
-#include <time.h>      // For timespec
+#include "include/llvm-libc-types/sigset_t.h"
+#include "include/llvm-libc-types/struct_epoll_event.h"
+#include "include/llvm-libc-types/struct_timespec.h"
 
 namespace LIBC_NAMESPACE {
 
diff --git a/libc/src/sys/epoll/epoll_wait.h b/libc/src/sys/epoll/epoll_wait.h
index b8f768aabf16d..e21b0a72a7a42 100644
--- a/libc/src/sys/epoll/epoll_wait.h
+++ b/libc/src/sys/epoll/epoll_wait.h
@@ -9,7 +9,7 @@
 #ifndef LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_WAIT_H
 #define LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_WAIT_H
 
-#include <sys/epoll.h> // For epoll_event
+#include "include/llvm-libc-types/struct_epoll_event.h"
 
 namespace LIBC_NAMESPACE {
 
diff --git a/libc/src/sys/epoll/linux/epoll_pwait.cpp b/libc/src/sys/epoll/linux/epoll_pwait.cpp
index e3a7b6e0393bd..61389a7b2f5fa 100644
--- a/libc/src/sys/epoll/linux/epoll_pwait.cpp
+++ b/libc/src/sys/epoll/linux/epoll_pwait.cpp
@@ -14,7 +14,8 @@
 #include "src/errno/libc_errno.h"
 #include <sys/syscall.h> // For syscall numbers.
 
-#include <signal.h> // For sigset_t
+#include "include/llvm-libc-types/sigset_t.h"
+#include "include/llvm-libc-types/struct_epoll_event.h"
 
 namespace LIBC_NAMESPACE {
 
diff --git a/libc/src/sys/epoll/linux/epoll_pwait2.cpp b/libc/src/sys/epoll/linux/epoll_pwait2.cpp
index 25ca0ae06f440..ab2d7e6d83091 100644
--- a/libc/src/sys/epoll/linux/epoll_pwait2.cpp
+++ b/libc/src/sys/epoll/linux/epoll_pwait2.cpp
@@ -14,8 +14,9 @@
 #include "src/errno/libc_errno.h"
 #include <sys/syscall.h> // For syscall numbers.
 
-#include <signal.h> // For sigset_t
-#include <time.h>   // For timespec
+#include "include/llvm-libc-types/sigset_t.h"
+#include "include/llvm-libc-types/struct_epoll_event.h"
+#include "include/llvm-libc-types/struct_timespec.h"
 
 namespace LIBC_NAMESPACE {
 
diff --git a/libc/src/sys/epoll/linux/epoll_wait.cpp b/libc/src/sys/epoll/linux/epoll_wait.cpp
index b305575e099f2..a3a2dee1a95b0 100644
--- a/libc/src/sys/epoll/linux/epoll_wait.cpp
+++ b/libc/src/sys/epoll/linux/epoll_wait.cpp
@@ -14,6 +14,8 @@
 #include "src/errno/libc_errno.h"
 #include <sys/syscall.h> // For syscall numbers.
 
+#include "include/llvm-libc-types/struct_epoll_event.h"
+
 namespace LIBC_NAMESPACE {
 
 LLVM_LIBC_FUNCTION(int, epoll_wait,

>From c88c4da95feade9e78f77017458e739d30ed0ea2 Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Fri, 26 Jan 2024 15:59:58 -0800
Subject: [PATCH 5/7] move includes back to angle brackets

Ideally the types would be included directly using
"include/llvm-libc-types/type.h" but that's not the format used within
the type headers themselves so it fails on overlay mode if I do that.
---
 libc/src/sys/epoll/epoll_pwait.h          | 6 ++++--
 libc/src/sys/epoll/epoll_pwait2.h         | 8 +++++---
 libc/src/sys/epoll/epoll_wait.h           | 5 ++++-
 libc/src/sys/epoll/linux/epoll_pwait.cpp  | 6 ++++--
 libc/src/sys/epoll/linux/epoll_pwait2.cpp | 8 +++++---
 libc/src/sys/epoll/linux/epoll_wait.cpp   | 4 +++-
 6 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/libc/src/sys/epoll/epoll_pwait.h b/libc/src/sys/epoll/epoll_pwait.h
index b64470a49db04..9f8417a8b5eea 100644
--- a/libc/src/sys/epoll/epoll_pwait.h
+++ b/libc/src/sys/epoll/epoll_pwait.h
@@ -9,8 +9,10 @@
 #ifndef LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_PWAIT_H
 #define LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_PWAIT_H
 
-#include "include/llvm-libc-types/sigset_t.h"
-#include "include/llvm-libc-types/struct_epoll_event.h"
+// #include "include/llvm-libc-types/sigset_t.h"
+// #include "include/llvm-libc-types/struct_epoll_event.h"
+
+#include <sys/epoll.h>
 
 namespace LIBC_NAMESPACE {
 
diff --git a/libc/src/sys/epoll/epoll_pwait2.h b/libc/src/sys/epoll/epoll_pwait2.h
index e35bfb86829a6..31f62c5954440 100644
--- a/libc/src/sys/epoll/epoll_pwait2.h
+++ b/libc/src/sys/epoll/epoll_pwait2.h
@@ -9,9 +9,11 @@
 #ifndef LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_PWAIT2_H
 #define LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_PWAIT2_H
 
-#include "include/llvm-libc-types/sigset_t.h"
-#include "include/llvm-libc-types/struct_epoll_event.h"
-#include "include/llvm-libc-types/struct_timespec.h"
+// #include "include/llvm-libc-types/sigset_t.h"
+// #include "include/llvm-libc-types/struct_epoll_event.h"
+// #include "include/llvm-libc-types/struct_timespec.h"
+
+#include <sys/epoll.h>
 
 namespace LIBC_NAMESPACE {
 
diff --git a/libc/src/sys/epoll/epoll_wait.h b/libc/src/sys/epoll/epoll_wait.h
index e21b0a72a7a42..a6d0cc4ca9d07 100644
--- a/libc/src/sys/epoll/epoll_wait.h
+++ b/libc/src/sys/epoll/epoll_wait.h
@@ -9,7 +9,10 @@
 #ifndef LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_WAIT_H
 #define LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_WAIT_H
 
-#include "include/llvm-libc-types/struct_epoll_event.h"
+// TODO: Use this include once the include headers are also using quotes.
+// #include "include/llvm-libc-types/struct_epoll_event.h"
+
+#include <sys/epoll.h>
 
 namespace LIBC_NAMESPACE {
 
diff --git a/libc/src/sys/epoll/linux/epoll_pwait.cpp b/libc/src/sys/epoll/linux/epoll_pwait.cpp
index 61389a7b2f5fa..a4a8374d6a181 100644
--- a/libc/src/sys/epoll/linux/epoll_pwait.cpp
+++ b/libc/src/sys/epoll/linux/epoll_pwait.cpp
@@ -14,8 +14,10 @@
 #include "src/errno/libc_errno.h"
 #include <sys/syscall.h> // For syscall numbers.
 
-#include "include/llvm-libc-types/sigset_t.h"
-#include "include/llvm-libc-types/struct_epoll_event.h"
+// #include "include/llvm-libc-types/sigset_t.h"
+// #include "include/llvm-libc-types/struct_epoll_event.h"
+
+#include <sys/epoll.h>
 
 namespace LIBC_NAMESPACE {
 
diff --git a/libc/src/sys/epoll/linux/epoll_pwait2.cpp b/libc/src/sys/epoll/linux/epoll_pwait2.cpp
index ab2d7e6d83091..e8cbd315b96ee 100644
--- a/libc/src/sys/epoll/linux/epoll_pwait2.cpp
+++ b/libc/src/sys/epoll/linux/epoll_pwait2.cpp
@@ -14,9 +14,11 @@
 #include "src/errno/libc_errno.h"
 #include <sys/syscall.h> // For syscall numbers.
 
-#include "include/llvm-libc-types/sigset_t.h"
-#include "include/llvm-libc-types/struct_epoll_event.h"
-#include "include/llvm-libc-types/struct_timespec.h"
+// #include "include/llvm-libc-types/sigset_t.h"
+// #include "include/llvm-libc-types/struct_epoll_event.h"
+// #include "include/llvm-libc-types/struct_timespec.h"
+
+#include <sys/epoll.h>
 
 namespace LIBC_NAMESPACE {
 
diff --git a/libc/src/sys/epoll/linux/epoll_wait.cpp b/libc/src/sys/epoll/linux/epoll_wait.cpp
index a3a2dee1a95b0..ac9052c4ab660 100644
--- a/libc/src/sys/epoll/linux/epoll_wait.cpp
+++ b/libc/src/sys/epoll/linux/epoll_wait.cpp
@@ -14,7 +14,9 @@
 #include "src/errno/libc_errno.h"
 #include <sys/syscall.h> // For syscall numbers.
 
-#include "include/llvm-libc-types/struct_epoll_event.h"
+// #include "include/llvm-libc-types/struct_epoll_event.h"
+
+#include <sys/epoll.h>
 
 namespace LIBC_NAMESPACE {
 

>From 3403bfa012b41c046f238a36668faf5e5ac38dfc Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Mon, 29 Jan 2024 13:12:00 -0800
Subject: [PATCH 6/7] add todos above commmented out includes

---
 libc/src/sys/epoll/epoll_pwait.h          | 1 +
 libc/src/sys/epoll/epoll_pwait2.h         | 1 +
 libc/src/sys/epoll/linux/epoll_pwait.cpp  | 1 +
 libc/src/sys/epoll/linux/epoll_pwait2.cpp | 1 +
 libc/src/sys/epoll/linux/epoll_wait.cpp   | 1 +
 5 files changed, 5 insertions(+)

diff --git a/libc/src/sys/epoll/epoll_pwait.h b/libc/src/sys/epoll/epoll_pwait.h
index 9f8417a8b5eea..6365c2a7191d9 100644
--- a/libc/src/sys/epoll/epoll_pwait.h
+++ b/libc/src/sys/epoll/epoll_pwait.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_PWAIT_H
 #define LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_PWAIT_H
 
+// TODO: Use this include once the include headers are also using quotes.
 // #include "include/llvm-libc-types/sigset_t.h"
 // #include "include/llvm-libc-types/struct_epoll_event.h"
 
diff --git a/libc/src/sys/epoll/epoll_pwait2.h b/libc/src/sys/epoll/epoll_pwait2.h
index 31f62c5954440..079b6e68b5fa2 100644
--- a/libc/src/sys/epoll/epoll_pwait2.h
+++ b/libc/src/sys/epoll/epoll_pwait2.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_PWAIT2_H
 #define LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_PWAIT2_H
 
+// TODO: Use this include once the include headers are also using quotes.
 // #include "include/llvm-libc-types/sigset_t.h"
 // #include "include/llvm-libc-types/struct_epoll_event.h"
 // #include "include/llvm-libc-types/struct_timespec.h"
diff --git a/libc/src/sys/epoll/linux/epoll_pwait.cpp b/libc/src/sys/epoll/linux/epoll_pwait.cpp
index a4a8374d6a181..ee1b4e66e9844 100644
--- a/libc/src/sys/epoll/linux/epoll_pwait.cpp
+++ b/libc/src/sys/epoll/linux/epoll_pwait.cpp
@@ -14,6 +14,7 @@
 #include "src/errno/libc_errno.h"
 #include <sys/syscall.h> // For syscall numbers.
 
+// TODO: Use this include once the include headers are also using quotes.
 // #include "include/llvm-libc-types/sigset_t.h"
 // #include "include/llvm-libc-types/struct_epoll_event.h"
 
diff --git a/libc/src/sys/epoll/linux/epoll_pwait2.cpp b/libc/src/sys/epoll/linux/epoll_pwait2.cpp
index e8cbd315b96ee..671dede2a1058 100644
--- a/libc/src/sys/epoll/linux/epoll_pwait2.cpp
+++ b/libc/src/sys/epoll/linux/epoll_pwait2.cpp
@@ -14,6 +14,7 @@
 #include "src/errno/libc_errno.h"
 #include <sys/syscall.h> // For syscall numbers.
 
+// TODO: Use this include once the include headers are also using quotes.
 // #include "include/llvm-libc-types/sigset_t.h"
 // #include "include/llvm-libc-types/struct_epoll_event.h"
 // #include "include/llvm-libc-types/struct_timespec.h"
diff --git a/libc/src/sys/epoll/linux/epoll_wait.cpp b/libc/src/sys/epoll/linux/epoll_wait.cpp
index ac9052c4ab660..54927faaf8629 100644
--- a/libc/src/sys/epoll/linux/epoll_wait.cpp
+++ b/libc/src/sys/epoll/linux/epoll_wait.cpp
@@ -14,6 +14,7 @@
 #include "src/errno/libc_errno.h"
 #include <sys/syscall.h> // For syscall numbers.
 
+// TODO: Use this include once the include headers are also using quotes.
 // #include "include/llvm-libc-types/struct_epoll_event.h"
 
 #include <sys/epoll.h>

>From 93b0f08b918c9f89cf692b3ec6c24e51a3899baf Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Mon, 29 Jan 2024 16:28:00 -0800
Subject: [PATCH 7/7] final cleanup before land

---
 libc/include/llvm-libc-types/struct_epoll_event.h | 4 ++--
 libc/src/sys/epoll/epoll_pwait.h                  | 4 ++--
 libc/src/sys/epoll/epoll_pwait2.h                 | 4 ++--
 libc/src/sys/epoll/epoll_wait.h                   | 3 +--
 4 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/libc/include/llvm-libc-types/struct_epoll_event.h b/libc/include/llvm-libc-types/struct_epoll_event.h
index f902a74838146..997a94a585044 100644
--- a/libc/include/llvm-libc-types/struct_epoll_event.h
+++ b/libc/include/llvm-libc-types/struct_epoll_event.h
@@ -11,9 +11,9 @@
 
 #include <llvm-libc-types/struct_epoll_data.h>
 
-struct epoll_event {
+typedef struct epoll_event{
   __UINT32_TYPE__ events;
   epoll_data_t data;
-};
+} epoll_event;
 
 #endif // __LLVM_LIBC_TYPES_EPOLL_EVENT_H__
diff --git a/libc/src/sys/epoll/epoll_pwait.h b/libc/src/sys/epoll/epoll_pwait.h
index 6365c2a7191d9..9dcb55533009f 100644
--- a/libc/src/sys/epoll/epoll_pwait.h
+++ b/libc/src/sys/epoll/epoll_pwait.h
@@ -18,8 +18,8 @@
 namespace LIBC_NAMESPACE {
 
 // TODO: sigmask should be nullable
-int epoll_pwait(int epfd, struct epoll_event *events, int maxevents,
-                int timeout, const sigset_t *sigmask);
+int epoll_pwait(int epfd, epoll_event *events, int maxevents, int timeout,
+                const sigset_t *sigmask);
 
 } // namespace LIBC_NAMESPACE
 
diff --git a/libc/src/sys/epoll/epoll_pwait2.h b/libc/src/sys/epoll/epoll_pwait2.h
index 079b6e68b5fa2..622ede6a0f9f9 100644
--- a/libc/src/sys/epoll/epoll_pwait2.h
+++ b/libc/src/sys/epoll/epoll_pwait2.h
@@ -19,8 +19,8 @@
 namespace LIBC_NAMESPACE {
 
 // TODO: sigmask and timeout should be nullable
-int epoll_pwait2(int epfd, struct epoll_event *events, int maxevents,
-                 const struct timespec *timeout, const sigset_t *sigmask);
+int epoll_pwait2(int epfd, epoll_event *events, int maxevents,
+                 const timespec *timeout, const sigset_t *sigmask);
 
 } // namespace LIBC_NAMESPACE
 
diff --git a/libc/src/sys/epoll/epoll_wait.h b/libc/src/sys/epoll/epoll_wait.h
index a6d0cc4ca9d07..d51c9100846ce 100644
--- a/libc/src/sys/epoll/epoll_wait.h
+++ b/libc/src/sys/epoll/epoll_wait.h
@@ -16,8 +16,7 @@
 
 namespace LIBC_NAMESPACE {
 
-int epoll_wait(int epfd, struct epoll_event *events, int maxevents,
-               int timeout);
+int epoll_wait(int epfd, epoll_event *events, int maxevents, int timeout);
 
 } // namespace LIBC_NAMESPACE
 



More information about the libc-commits mailing list