Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc] Support epoll_wait using epoll_pwait #80224

Merged
merged 2 commits into from
Feb 1, 2024

Conversation

michaelrj-google
Copy link
Contributor

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.

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.
@llvmbot llvmbot added the libc label Feb 1, 2024
@llvmbot
Copy link

llvmbot commented Feb 1, 2024

@llvm/pr-subscribers-libc

Author: None (michaelrj-google)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/80224.diff

1 Files Affected:

  • (modified) libc/src/sys/epoll/linux/epoll_wait.cpp (+9-2)
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) {

Copy link
Contributor

@lntue lntue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: We probably should have a consistent style for #error in our style guilde. Currently in our code base, the majority of them are #error "message", and some are #error message.

@michaelrj-google michaelrj-google merged commit ecdbffe into llvm:main Feb 1, 2024
4 checks passed
@michaelrj-google michaelrj-google deleted the libcEpollWaitWithPwait branch February 1, 2024 22:24
agozillon pushed a commit to agozillon/llvm-project that referenced this pull request Feb 5, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants