Thanks to visit codestin.com
Credit goes to github.com

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

Conversation

mikhailramalho
Copy link
Member

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

RV32 uses SYS_ppoll_time64 instead of SYS_ppoll, but the call is the
same.
@llvmbot
Copy link
Member

llvmbot commented May 9, 2025

@llvm/pr-subscribers-libc

Author: Mikhail R. Gadelha (mikhailramalho)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/139180.diff

3 Files Affected:

  • (modified) libc/config/linux/riscv/entrypoints.txt (+1-2)
  • (modified) libc/include/sys/syscall.h.def (+4)
  • (modified) libc/src/poll/linux/poll.cpp (+14-7)
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..bd6fb8b1c0a43 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
 
+#if 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) {

Signed-off-by: Mikhail R. Gadelha <[email protected]>
@mikhailramalho mikhailramalho merged commit 66bb445 into llvm:main May 13, 2025
13 of 15 checks passed
@mikhailramalho mikhailramalho deleted the libc-riscv-poll branch May 13, 2025 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants