[libc-commits] [libc] 66bb445 - [libc] Enable poll function for riscv (#139180)

via libc-commits libc-commits at lists.llvm.org
Tue May 13 14:59:31 PDT 2025


Author: Mikhail R. Gadelha
Date: 2025-05-13T18:59:28-03:00
New Revision: 66bb445d5ccc275ffea674287a7ac55d030801b2

URL: https://github.com/llvm/llvm-project/commit/66bb445d5ccc275ffea674287a7ac55d030801b2
DIFF: https://github.com/llvm/llvm-project/commit/66bb445d5ccc275ffea674287a7ac55d030801b2.diff

LOG: [libc] Enable poll function for riscv (#139180)

RV32 uses SYS_ppoll_time64 instead of SYS_ppoll, but the call is the
same.

Added: 
    

Modified: 
    libc/config/linux/riscv/entrypoints.txt
    libc/include/sys/syscall.h.def
    libc/src/poll/linux/poll.cpp

Removed: 
    


################################################################################
diff  --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index c2a31b9f5c964..4bc27b832fdaa 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/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;
@@ -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) {


        


More information about the libc-commits mailing list