-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[libc][POSIX][poll.h] implement poll #125118
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
Changes from 6 commits
035836d
f5527d9
a860748
1d8cb3a
19e0439
86c9780
6fc7519
7e24ed0
576e644
9fbba8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| //===-- Definition of nfds_t ----------------------------------------------===// | ||
| // | ||
| // 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_HDR_TYPES_NFDS_T_H | ||
| #define LLVM_LIBC_HDR_TYPES_NFDS_T_H | ||
|
|
||
| #ifdef LIBC_FULL_BUILD | ||
|
|
||
| #include "include/llvm-libc-types/nfds_t.h" | ||
|
|
||
| #else // overlay mode | ||
|
|
||
| #include <poll.h> | ||
|
|
||
| #endif // LLVM_LIBC_FULL_BUILD | ||
|
|
||
| #endif // LLVM_LIBC_HDR_TYPES_NFDS_T_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| //===-- Definition of struct pollfd ---------------------------------------===// | ||
| // | ||
| // 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_HDR_TYPES_STRUCT_POLLFD_H | ||
| #define LLVM_LIBC_HDR_TYPES_STRUCT_POLLFD_H | ||
|
|
||
| #ifdef LIBC_FULL_BUILD | ||
|
|
||
| #include "include/llvm-libc-types/struct_pollfd.h" | ||
|
|
||
| #else // overlay mode | ||
|
|
||
| #include <poll.h> | ||
|
|
||
| #endif // LLVM_LIBC_FULL_BUILD | ||
|
|
||
| #endif // LLVM_LIBC_HDR_TYPES_STRUCT_POLLFD_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -321,3 +321,9 @@ add_macro_header( | |
| HDR | ||
| pthread-macros.h | ||
| ) | ||
|
|
||
| add_macro_header( | ||
| poll-macros | ||
| HDR | ||
| poll-macros.h | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| //===-- Macros defined in poll.h header file ------------------------------===// | ||
| // | ||
| // 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_MACROS_LINUX_POLL_MACROS_H | ||
| #define LLVM_LIBC_MACROS_LINUX_POLL_MACROS_H | ||
|
|
||
| // From asm-generic/poll.h, redefined here to avoid redeclaring struct pollfd. | ||
| #ifndef POLLIN | ||
| #define POLLIN 0x0001 | ||
| #endif | ||
|
|
||
| #ifndef POLLPRI | ||
| #define POLLPRI 0x0002 | ||
| #endif | ||
|
|
||
| #ifndef POLLOUT | ||
| #define POLLOUT 0x0004 | ||
| #endif | ||
|
|
||
| #ifndef POLLERR | ||
| #define POLLERR 0x0008 | ||
| #endif | ||
|
|
||
| #ifndef POLLHUP | ||
| #define POLLHUP 0x0010 | ||
| #endif | ||
|
|
||
| #ifndef POLLNVAL | ||
| #define POLLNVAL 0x0020 | ||
| #endif | ||
|
|
||
| #ifndef POLLRDNORM | ||
| #define POLLRDNORM 0x0040 | ||
| #endif | ||
|
|
||
| #ifndef POLLRDBAND | ||
| #define POLLRDBAND 0x0080 | ||
| #endif | ||
|
|
||
| #ifndef POLLWRNORM | ||
| #define POLLWRNORM 0x0100 | ||
| #endif | ||
|
|
||
| #ifndef POLLWRBAND | ||
| #define POLLWRBAND 0x0200 | ||
| #endif | ||
|
|
||
| #ifndef POLLMSG | ||
| #define POLLMSG 0x0400 | ||
| #endif | ||
|
|
||
| #ifndef POLLREMOVE | ||
| #define POLLREMOVE 0x1000 | ||
| #endif | ||
|
|
||
| #ifndef POLLRDHUP | ||
| #define POLLRDHUP 0x2000 | ||
| #endif | ||
|
|
||
| #endif // LLVM_LIBC_MACROS_LINUX_POLL_MACROS_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| //===-- Macros defined in poll.h header file ------------------------------===// | ||
| // | ||
| // 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_MACROS_POLL_MACROS_H | ||
| #define LLVM_LIBC_MACROS_POLL_MACROS_H | ||
|
|
||
| #ifdef __linux__ | ||
| #include "linux/poll-macros.h" | ||
| #endif | ||
|
|
||
| #endif // LLVM_LIBC_MACROS_POLL_MACROS_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| //===-- Definition of type nfds_t -----------------------------------------===// | ||
| // | ||
| // 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_TYPES_NFDS_T_H | ||
| #define LLVM_LIBC_TYPES_NFDS_T_H | ||
|
|
||
| typedef unsigned int nfds_t; | ||
|
|
||
| #endif // LLVM_LIBC_TYPES_NFDS_T_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| //===-- Definition of type struct pollfd ----------------------------------===// | ||
| // | ||
| // 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_TYPES_STRUCT_POLLFD_H | ||
| #define LLVM_LIBC_TYPES_STRUCT_POLLFD_H | ||
|
|
||
| struct pollfd { | ||
| int fd; | ||
| short events; | ||
| short revents; | ||
| }; | ||
|
|
||
| #endif // LLVM_LIBC_TYPES_STRUCT_POLLFD_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| header: poll.h | ||
| header_template: poll.h.def | ||
| macros: [] | ||
| types: | ||
| - type_name: struct_pollfd | ||
| - type_name: nfds_t | ||
| enums: [] | ||
| functions: | ||
| - name: poll | ||
| standards: | ||
| - posix | ||
| return_type: int | ||
| arguments: | ||
| - type: struct pollfd * | ||
| - type: nfds_t | ||
| - type: int |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS}) | ||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS}) | ||
| endif() | ||
|
|
||
| add_entrypoint_object( | ||
| poll | ||
| ALIAS | ||
| DEPENDS | ||
| .${LIBC_TARGET_OS}.poll | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| add_entrypoint_object( | ||
| poll | ||
| SRCS | ||
| poll.cpp | ||
| HDRS | ||
| ../poll.h | ||
| DEPENDS | ||
| libc.hdr.types.nfds_t | ||
| libc.hdr.types.struct_pollfd | ||
| libc.hdr.types.struct_timespec | ||
| libc.include.poll | ||
| 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,49 @@ | ||
| //===-- Implementation of poll --------------------------------------------===// | ||
| // | ||
| // 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/poll/poll.h" | ||
|
|
||
| #include "hdr/types/nfds_t.h" | ||
| #include "hdr/types/struct_pollfd.h" | ||
| #include "hdr/types/struct_timespec.h" | ||
| #include "src/__support/OSUtil/syscall.h" // syscall_impl | ||
| #include "src/__support/common.h" | ||
| #include "src/__support/macros/config.h" | ||
| #include "src/errno/libc_errno.h" | ||
|
|
||
| #include <sys/syscall.h> // SYS_poll, SYS_ppoll | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| LLVM_LIBC_FUNCTION(int, poll, (struct pollfd * fds, nfds_t nfds, int timeout)) { | ||
|
||
|
|
||
| #ifdef SYS_poll | ||
| int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_poll, fds, nfds, timeout); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like SYS_poll does not exist for all architectures.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, looks like there's a newer ppoll_time64...
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a860748. Will omit ppoll_time64 since that will only help riscv32 at the moment. |
||
| #elif defined(SYS_ppoll) | ||
| struct timespec ts, *tsp; | ||
| if (timeout >= 0) { | ||
| ts.tv_sec = timeout / 1000; | ||
| ts.tv_nsec = (timeout % 1000) * 1000000; | ||
| tsp = &ts; | ||
| } else { | ||
| tsp = nullptr; | ||
| } | ||
| int ret = | ||
| LIBC_NAMESPACE::syscall_impl<int>(SYS_ppoll, fds, nfds, tsp, nullptr, 0); | ||
| #else | ||
| #error "SYS_ppoll_time64?" | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. of course, 32b riscv doesn't have
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| #endif | ||
|
|
||
| if (ret < 0) { | ||
| libc_errno = -ret; | ||
| return -1; | ||
| } | ||
| return ret; | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL | ||
Uh oh!
There was an error while loading. Please reload this page.