diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt index 30d9d00dfefc9..df446c3839d68 100644 --- a/libc/config/linux/riscv/entrypoints.txt +++ b/libc/config/linux/riscv/entrypoints.txt @@ -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 diff --git a/libc/include/sys/syscall.h.def b/libc/include/sys/syscall.h.def index 03c19eb0885ed..ca5a6cc706c27 100644 --- a/libc/include/sys/syscall.h.def +++ b/libc/include/sys/syscall.h.def @@ -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 diff --git a/libc/src/poll/linux/poll.cpp b/libc/src/poll/linux/poll.cpp index d7c195878ae12..2579ec04c1200 100644 --- a/libc/src/poll/linux/poll.cpp +++ b/libc/src/poll/linux/poll.cpp @@ -18,14 +18,24 @@ #include // 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(SYS_poll, fds, nfds, timeout); -#elif defined(SYS_ppoll) + ret = LIBC_NAMESPACE::syscall_impl(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; @@ -34,11 +44,8 @@ LLVM_LIBC_FUNCTION(int, poll, (pollfd * fds, nfds_t nfds, int timeout)) { } else { tsp = nullptr; } - ret = - LIBC_NAMESPACE::syscall_impl(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(POLL_SYSCALL_ID, fds, nfds, tsp, + nullptr, 0); #endif if (ret < 0) {