[libc-commits] [libc] [libc] Fix epoll_create behavior when only epoll_create1 is available (PR #149713)

via libc-commits libc-commits at lists.llvm.org
Sun Jul 20 08:40:47 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Mikhail R. Gadelha (mikhailramalho)

<details>
<summary>Changes</summary>

In PR #<!-- -->99785, I disabled a test for `epoll_create` that was intended to fail on systems where only `epoll_create1` is available. This is because `epoll_create1` cannot fail in the same way that `epoll_create` does.

Specifically, calling `epoll_create(0)` should result in an EINVAL error. So, when only `epoll_create1` is available, we should simply check if the argument is zero and return the error accordingly.

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


2 Files Affected:

- (modified) libc/src/sys/epoll/linux/epoll_create.cpp (+5) 
- (modified) libc/test/src/sys/epoll/linux/epoll_create_test.cpp (-3) 


``````````diff
diff --git a/libc/src/sys/epoll/linux/epoll_create.cpp b/libc/src/sys/epoll/linux/epoll_create.cpp
index 2e44e883ddf0a..dcd082b56f9ad 100644
--- a/libc/src/sys/epoll/linux/epoll_create.cpp
+++ b/libc/src/sys/epoll/linux/epoll_create.cpp
@@ -20,6 +20,11 @@ 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;
+    return -1;
+  }
+
   int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_epoll_create1, 0);
 #else
 #error                                                                         \
diff --git a/libc/test/src/sys/epoll/linux/epoll_create_test.cpp b/libc/test/src/sys/epoll/linux/epoll_create_test.cpp
index 06c17c6cf29e6..2bbfe4fbe81ff 100644
--- a/libc/test/src/sys/epoll/linux/epoll_create_test.cpp
+++ b/libc/test/src/sys/epoll/linux/epoll_create_test.cpp
@@ -10,7 +10,6 @@
 #include "test/UnitTest/ErrnoCheckingTest.h"
 #include "test/UnitTest/ErrnoSetterMatcher.h"
 #include "test/UnitTest/Test.h"
-#include <sys/syscall.h> // For syscall numbers.
 
 using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
 using LlvmLibcEpollCreateTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
@@ -23,8 +22,6 @@ TEST_F(LlvmLibcEpollCreateTest, Basic) {
   ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds());
 }
 
-#ifdef SYS_epoll_create
 TEST_F(LlvmLibcEpollCreateTest, Fails) {
   ASSERT_THAT(LIBC_NAMESPACE::epoll_create(0), Fails(EINVAL));
 }
-#endif

``````````

</details>


https://github.com/llvm/llvm-project/pull/149713


More information about the libc-commits mailing list