[libc-commits] [libc] [libc] Support epoll_wait using epoll_pwait (PR #80224)

via libc-commits libc-commits at lists.llvm.org
Thu Feb 1 10:36:29 PST 2024


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

>From a6271b5d7f985a373d12acf2eafc4846d19c857b Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Wed, 31 Jan 2024 16:48:26 -0800
Subject: [PATCH 1/2] [libc] Support epoll_wait using epoll_pwait

The epoll_wait syscall is equivalent to calling epoll_pwait with a null
sigset. This is useful to support systems that have epoll_pwait but not
epoll_wait.
---
 libc/src/sys/epoll/linux/epoll_wait.cpp | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/libc/src/sys/epoll/linux/epoll_wait.cpp b/libc/src/sys/epoll/linux/epoll_wait.cpp
index 54927faaf8629..6adae0c272971 100644
--- a/libc/src/sys/epoll/linux/epoll_wait.cpp
+++ b/libc/src/sys/epoll/linux/epoll_wait.cpp
@@ -10,11 +10,11 @@
 
 #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.
 
 // 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 <sys/epoll.h>
@@ -24,9 +24,16 @@ namespace LIBC_NAMESPACE {
 LLVM_LIBC_FUNCTION(int, epoll_wait,
                    (int epfd, struct epoll_event *events, int maxevents,
                     int timeout)) {
+#ifdef SYS_epoll_wait
   int ret = LIBC_NAMESPACE::syscall_impl<int>(
       SYS_epoll_wait, epfd, reinterpret_cast<long>(events), maxevents, timeout);
-
+#elif defined(SYS_epoll_pwait)
+  int ret = LIBC_NAMESPACE::syscall_impl<int>(
+      SYS_epoll_pwait, epfd, reinterpret_cast<long>(events), maxevents, timeout,
+      reinterpret_cast<long>(nullptr), sizeof(sigset_t));
+#else
+#error epoll_wait and epoll_pwait are unavailable. Unable to build epoll_wait.
+#endif
   // A negative return value indicates an error with the magnitude of the
   // value being the error code.
   if (ret < 0) {

>From 33966a45747d9ae0040192fd51983888c3fc3d4d Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Thu, 1 Feb 2024 10:36:14 -0800
Subject: [PATCH 2/2] add quotes to error

---
 libc/src/sys/epoll/linux/epoll_wait.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/src/sys/epoll/linux/epoll_wait.cpp b/libc/src/sys/epoll/linux/epoll_wait.cpp
index 6adae0c272971..0c43edf764545 100644
--- a/libc/src/sys/epoll/linux/epoll_wait.cpp
+++ b/libc/src/sys/epoll/linux/epoll_wait.cpp
@@ -32,7 +32,7 @@ LLVM_LIBC_FUNCTION(int, epoll_wait,
       SYS_epoll_pwait, epfd, reinterpret_cast<long>(events), maxevents, timeout,
       reinterpret_cast<long>(nullptr), sizeof(sigset_t));
 #else
-#error epoll_wait and epoll_pwait are unavailable. Unable to build epoll_wait.
+#error "epoll_wait and epoll_pwait are unavailable. Unable to build epoll_wait."
 #endif
   // A negative return value indicates an error with the magnitude of the
   // value being the error code.



More information about the libc-commits mailing list