Skip to content

Commit 66bb445

Browse files
[libc] Enable poll function for riscv (llvm#139180)
RV32 uses SYS_ppoll_time64 instead of SYS_ppoll, but the call is the same.
1 parent 79e8e27 commit 66bb445

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

libc/config/linux/riscv/entrypoints.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ set(TARGET_LIBC_ENTRYPOINTS
3333
libc.src.fcntl.openat
3434

3535
# poll.h entrypoints
36-
# TODO: https://github.com/llvm/llvm-project/issues/125940
37-
# libc.src.poll.poll
36+
libc.src.poll.poll
3837

3938
# sched.h entrypoints
4039
libc.src.sched.sched_get_priority_max

libc/include/sys/syscall.h.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,10 @@
15171517
#define SYS_ppoll __NR_ppoll
15181518
#endif
15191519

1520+
#ifdef __NR_ppoll_time64
1521+
#define SYS_ppoll_time64 __NR_ppoll_time64
1522+
#endif
1523+
15201524
#ifdef __NR_prctl
15211525
#define SYS_prctl __NR_prctl
15221526
#endif

libc/src/poll/linux/poll.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,24 @@
1818

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

21+
#ifdef SYS_poll
22+
constexpr auto POLL_SYSCALL_ID = SYS_poll;
23+
#elif defined(SYS_ppoll)
24+
constexpr auto POLL_SYSCALL_ID = SYS_ppoll;
25+
#elif defined(SYS_ppoll_time64)
26+
constexpr auto POLL_SYSCALL_ID = SYS_ppoll_time64;
27+
#else
28+
#error "poll, ppoll, ppoll_time64 syscalls not available."
29+
#endif
30+
2131
namespace LIBC_NAMESPACE_DECL {
2232

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

2636
#ifdef SYS_poll
27-
ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_poll, fds, nfds, timeout);
28-
#elif defined(SYS_ppoll)
37+
ret = LIBC_NAMESPACE::syscall_impl<int>(POLL_SYSCALL_ID, fds, nfds, timeout);
38+
#elif defined(SYS_ppoll) || defined(SYS_ppoll_time64)
2939
timespec ts, *tsp;
3040
if (timeout >= 0) {
3141
ts.tv_sec = timeout / 1000;
@@ -34,11 +44,8 @@ LLVM_LIBC_FUNCTION(int, poll, (pollfd * fds, nfds_t nfds, int timeout)) {
3444
} else {
3545
tsp = nullptr;
3646
}
37-
ret =
38-
LIBC_NAMESPACE::syscall_impl<int>(SYS_ppoll, fds, nfds, tsp, nullptr, 0);
39-
#else
40-
// TODO: https://github.com/llvm/llvm-project/issues/125940
41-
#error "SYS_ppoll_time64?"
47+
ret = LIBC_NAMESPACE::syscall_impl<int>(POLL_SYSCALL_ID, fds, nfds, tsp,
48+
nullptr, 0);
4249
#endif
4350

4451
if (ret < 0) {

0 commit comments

Comments
 (0)