Skip to content

[libc] Enable poll function for riscv #139180

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

Merged
merged 2 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions libc/config/linux/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.fcntl.openat

# poll.h entrypoints
# TODO: https://github.com/llvm/llvm-project/issues/125940
# libc.src.poll.poll
libc.src.poll.poll

# sched.h entrypoints
libc.src.sched.sched_get_priority_max
Expand Down
4 changes: 4 additions & 0 deletions libc/include/sys/syscall.h.def
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,10 @@
#define SYS_ppoll __NR_ppoll
#endif

#ifdef __NR_ppoll_time64
#define SYS_ppoll_time64 __NR_ppoll_time64
#endif

#ifdef __NR_prctl
#define SYS_prctl __NR_prctl
#endif
Expand Down
21 changes: 14 additions & 7 deletions libc/src/poll/linux/poll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,24 @@

#include <sys/syscall.h> // SYS_poll, SYS_ppoll

#ifdef SYS_poll
constexpr auto POLL_SYSCALL_ID = SYS_poll;
#elif defined(SYS_ppoll)
constexpr auto POLL_SYSCALL_ID = SYS_ppoll;
#elif defined(SYS_ppoll_time64)
constexpr auto POLL_SYSCALL_ID = SYS_ppoll_time64;
#else
#error "poll, ppoll, ppoll_time64 syscalls not available."
#endif

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(int, poll, (pollfd * fds, nfds_t nfds, int timeout)) {
int ret = 0;

#ifdef SYS_poll
ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_poll, fds, nfds, timeout);
#elif defined(SYS_ppoll)
ret = LIBC_NAMESPACE::syscall_impl<int>(POLL_SYSCALL_ID, fds, nfds, timeout);
#elif defined(SYS_ppoll) || defined(SYS_ppoll_time64)
timespec ts, *tsp;
if (timeout >= 0) {
ts.tv_sec = timeout / 1000;
Expand All @@ -34,11 +44,8 @@ LLVM_LIBC_FUNCTION(int, poll, (pollfd * fds, nfds_t nfds, int timeout)) {
} else {
tsp = nullptr;
}
ret =
LIBC_NAMESPACE::syscall_impl<int>(SYS_ppoll, fds, nfds, tsp, nullptr, 0);
#else
// TODO: https://github.com/llvm/llvm-project/issues/125940
#error "SYS_ppoll_time64?"
ret = LIBC_NAMESPACE::syscall_impl<int>(POLL_SYSCALL_ID, fds, nfds, tsp,
nullptr, 0);
#endif

if (ret < 0) {
Expand Down
Loading