Skip to content

Conversation

mikhailramalho
Copy link
Member

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.

In PR llvm#99785 I disabled a epoll_create test that should fail for systems
where only epoll_create1 was available, because epoll_create1 couldn't
fail the same way epoll_create did.

Calling epoll_create(0) should fail with an EINVAL error, so when only
epoll_create1 is available, we should just check if the arg is zero and
return the error accordingly.
@llvmbot
Copy link
Member

llvmbot commented Jul 20, 2025

@llvm/pr-subscribers-libc

Author: Mikhail R. Gadelha (mikhailramalho)

Changes

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 --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

@mikhailramalho mikhailramalho merged commit 04b4f62 into llvm:main Jul 20, 2025
25 of 26 checks passed
@mikhailramalho mikhailramalho deleted the libc-fix-epoll branch July 20, 2025 18:40
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Jul 28, 2025
…llvm#149713)

In PR llvm#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.
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