| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| //===-- Implementation header for epoll_wait function -----------*- C++ -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_WAIT_H | ||
| #define LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_WAIT_H | ||
|
|
||
| // TODO: Use this include once the include headers are also using quotes. | ||
| // #include "include/llvm-libc-types/struct_epoll_event.h" | ||
|
|
||
| #include <sys/epoll.h> | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| int epoll_wait(int epfd, epoll_event *events, int maxevents, int timeout); | ||
|
|
||
| } // namespace LIBC_NAMESPACE | ||
|
|
||
| #endif // LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_WAIT_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| add_entrypoint_object( | ||
| epoll_wait | ||
| SRCS | ||
| epoll_wait.cpp | ||
| HDRS | ||
| ../epoll_wait.h | ||
| DEPENDS | ||
| libc.include.sys_epoll | ||
| libc.include.sys_syscall | ||
| libc.src.__support.OSUtil.osutil | ||
| libc.src.errno.errno | ||
| ) | ||
|
|
||
| add_entrypoint_object( | ||
| epoll_pwait | ||
| SRCS | ||
| epoll_pwait.cpp | ||
| HDRS | ||
| ../epoll_pwait.h | ||
| DEPENDS | ||
| libc.include.sys_epoll | ||
| libc.include.signal | ||
| libc.include.sys_syscall | ||
| libc.src.__support.OSUtil.osutil | ||
| libc.src.errno.errno | ||
| ) | ||
|
|
||
| add_entrypoint_object( | ||
| epoll_pwait2 | ||
| SRCS | ||
| epoll_pwait2.cpp | ||
| HDRS | ||
| ../epoll_pwait2.h | ||
| DEPENDS | ||
| libc.include.sys_epoll | ||
| libc.include.signal | ||
| libc.include.time | ||
| libc.include.sys_syscall | ||
| libc.src.__support.OSUtil.osutil | ||
| libc.src.errno.errno | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| //===---------- Linux implementation of the epoll_pwait function ----------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "src/sys/epoll/epoll_pwait.h" | ||
|
|
||
| #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> | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| LLVM_LIBC_FUNCTION(int, epoll_pwait, | ||
| (int epfd, struct epoll_event *events, int maxevents, | ||
| int timeout, const sigset_t *sigmask)) { | ||
| int ret = LIBC_NAMESPACE::syscall_impl<int>( | ||
| SYS_epoll_pwait, epfd, reinterpret_cast<long>(events), maxevents, timeout, | ||
| reinterpret_cast<long>(sigmask), sizeof(sigset_t)); | ||
|
|
||
| // A negative return value indicates an error with the magnitude of the | ||
| // value being the error code. | ||
| if (ret < 0) { | ||
| libc_errno = -ret; | ||
| return -1; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| //===---------- Linux implementation of the epoll_pwait2 function ---------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "src/sys/epoll/epoll_pwait2.h" | ||
|
|
||
| #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 "include/llvm-libc-types/struct_timespec.h" | ||
|
|
||
| #include <sys/epoll.h> | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| LLVM_LIBC_FUNCTION(int, epoll_pwait2, | ||
| (int epfd, struct epoll_event *events, int maxevents, | ||
| const struct timespec *timeout, const sigset_t *sigmask)) { | ||
| int ret = LIBC_NAMESPACE::syscall_impl<int>( | ||
| SYS_epoll_pwait2, epfd, reinterpret_cast<long>(events), maxevents, | ||
| reinterpret_cast<long>(timeout), reinterpret_cast<long>(sigmask), | ||
| sizeof(sigset_t)); | ||
|
|
||
| // A negative return value indicates an error with the magnitude of the | ||
| // value being the error code. | ||
| if (ret < 0) { | ||
| libc_errno = -ret; | ||
| return -1; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| //===---------- Linux implementation of the epoll_wait function -----------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "src/sys/epoll/epoll_wait.h" | ||
|
|
||
| #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/struct_epoll_event.h" | ||
|
|
||
| #include <sys/epoll.h> | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| LLVM_LIBC_FUNCTION(int, epoll_wait, | ||
| (int epfd, struct epoll_event *events, int maxevents, | ||
| int timeout)) { | ||
| int ret = LIBC_NAMESPACE::syscall_impl<int>( | ||
| SYS_epoll_wait, epfd, reinterpret_cast<long>(events), maxevents, timeout); | ||
|
|
||
| // A negative return value indicates an error with the magnitude of the | ||
| // value being the error code. | ||
| if (ret < 0) { | ||
| libc_errno = -ret; | ||
| return -1; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS}) | ||
| add_subdirectory(${LIBC_TARGET_OS}) | ||
| endif() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| add_custom_target(libc_sys_epoll_unittests) | ||
| add_libc_unittest( | ||
| epoll_wait_test | ||
| SUITE | ||
| libc_sys_epoll_unittests | ||
| SRCS | ||
| epoll_wait_test.cpp | ||
| DEPENDS | ||
| libc.include.sys_epoll | ||
| libc.src.errno.errno | ||
| libc.src.sys.epoll.epoll_wait | ||
| libc.test.UnitTest.ErrnoSetterMatcher | ||
| ) | ||
|
|
||
| add_libc_unittest( | ||
| epoll_pwait_test | ||
| SUITE | ||
| libc_sys_epoll_unittests | ||
| SRCS | ||
| epoll_pwait_test.cpp | ||
| DEPENDS | ||
| libc.include.sys_epoll | ||
| libc.src.errno.errno | ||
| libc.src.sys.epoll.epoll_pwait | ||
| libc.test.UnitTest.ErrnoSetterMatcher | ||
| ) | ||
|
|
||
| add_libc_unittest( | ||
| epoll_pwait2_test | ||
| SUITE | ||
| libc_sys_epoll_unittests | ||
| SRCS | ||
| epoll_pwait2_test.cpp | ||
| DEPENDS | ||
| libc.include.sys_epoll | ||
| libc.src.errno.errno | ||
| libc.src.sys.epoll.epoll_pwait2 | ||
| libc.test.UnitTest.ErrnoSetterMatcher | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //===-- Unittests for epoll_pwait2 ----------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| #include "src/errno/libc_errno.h" | ||
| #include "src/sys/epoll/epoll_pwait2.h" | ||
| #include "test/UnitTest/ErrnoSetterMatcher.h" | ||
| #include "test/UnitTest/Test.h" | ||
|
|
||
| using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher; | ||
|
|
||
| TEST(LlvmLibcEpollWaitTest, Basic) { | ||
| EXPECT_THAT(LIBC_NAMESPACE::epoll_pwait2(-1, nullptr, 0, nullptr, nullptr), | ||
| returns(EQ(-1ul)).with_errno(EQ(EINVAL))); | ||
| } | ||
|
|
||
| // TODO: Complete these tests when epoll_create is implemented. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //===-- Unittests for epoll_pwait -----------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| #include "src/errno/libc_errno.h" | ||
| #include "src/sys/epoll/epoll_pwait.h" | ||
| #include "test/UnitTest/ErrnoSetterMatcher.h" | ||
| #include "test/UnitTest/Test.h" | ||
|
|
||
| using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher; | ||
|
|
||
| TEST(LlvmLibcEpollWaitTest, Basic) { | ||
| EXPECT_THAT(LIBC_NAMESPACE::epoll_pwait(-1, nullptr, 0, 0, nullptr), | ||
| returns(EQ(-1ul)).with_errno(EQ(EINVAL))); | ||
| } | ||
|
|
||
| // TODO: Complete these tests when epoll_create is implemented. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //===-- Unittests for epoll_wait ------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| #include "src/errno/libc_errno.h" | ||
| #include "src/sys/epoll/epoll_wait.h" | ||
| #include "test/UnitTest/ErrnoSetterMatcher.h" | ||
| #include "test/UnitTest/Test.h" | ||
|
|
||
| using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher; | ||
|
|
||
| TEST(LlvmLibcEpollWaitTest, Basic) { | ||
| EXPECT_THAT(LIBC_NAMESPACE::epoll_wait(-1, nullptr, 0, 0), | ||
| returns(EQ(-1ul)).with_errno(EQ(EINVAL))); | ||
| } | ||
|
|
||
| // TODO: Complete these tests when epoll_create is implemented. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # This file is licensed under the Apache License v2.0 with LLVM Exceptions. | ||
| # See https://llvm.org/LICENSE.txt for license information. | ||
| # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| # Tests for LLVM libc string.h functions. | ||
|
|
||
| load("//libc/test:libc_test_rules.bzl", "libc_test") | ||
|
|
||
| package(default_visibility = ["//visibility:public"]) | ||
|
|
||
| licenses(["notice"]) | ||
|
|
||
| libc_test( | ||
| name = "epoll_wait_test", | ||
| srcs = ["linux/epoll_wait_test.cpp"], | ||
| libc_function_deps = [ | ||
| "//libc:epoll_wait", | ||
| ], | ||
| ) | ||
|
|
||
| libc_test( | ||
| name = "epoll_pwait_test", | ||
| srcs = ["linux/epoll_pwait_test.cpp"], | ||
| libc_function_deps = [ | ||
| "//libc:epoll_pwait", | ||
| ], | ||
| ) | ||
|
|
||
| libc_test( | ||
| name = "epoll_pwait2_test", | ||
| srcs = ["linux/epoll_pwait2_test.cpp"], | ||
| libc_function_deps = [ | ||
| "//libc:epoll_pwait2", | ||
| ], | ||
| ) |