Skip to content

Commit 04b4f62

Browse files
[libc] Fix epoll_create behavior when only epoll_create1 is available (#149713)
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.
1 parent c045caa commit 04b4f62

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

libc/src/sys/epoll/linux/epoll_create.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ LLVM_LIBC_FUNCTION(int, epoll_create, ([[maybe_unused]] int size)) {
2020
#ifdef SYS_epoll_create
2121
int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_epoll_create, size);
2222
#elif defined(SYS_epoll_create1)
23+
if (size == 0) {
24+
libc_errno = EINVAL;
25+
return -1;
26+
}
27+
2328
int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_epoll_create1, 0);
2429
#else
2530
#error \

libc/test/src/sys/epoll/linux/epoll_create_test.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "test/UnitTest/ErrnoCheckingTest.h"
1111
#include "test/UnitTest/ErrnoSetterMatcher.h"
1212
#include "test/UnitTest/Test.h"
13-
#include <sys/syscall.h> // For syscall numbers.
1413

1514
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
1615
using LlvmLibcEpollCreateTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
@@ -23,8 +22,6 @@ TEST_F(LlvmLibcEpollCreateTest, Basic) {
2322
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds());
2423
}
2524

26-
#ifdef SYS_epoll_create
2725
TEST_F(LlvmLibcEpollCreateTest, Fails) {
2826
ASSERT_THAT(LIBC_NAMESPACE::epoll_create(0), Fails(EINVAL));
2927
}
30-
#endif

0 commit comments

Comments
 (0)