Skip to content

Commit a860748

Browse files
SYS_ppoll fallback
1 parent f5527d9 commit a860748

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ set(TARGET_LIBC_ENTRYPOINTS
3232
libc.src.fcntl.open
3333
libc.src.fcntl.openat
3434

35+
# poll.h entrypoints
36+
libc.src.poll.poll
37+
3538
# sched.h entrypoints
3639
libc.src.sched.sched_get_priority_max
3740
libc.src.sched.sched_get_priority_min

libc/config/linux/arm/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ set(TARGET_LIBC_ENTRYPOINTS
2020
# errno.h entrypoints
2121
libc.src.errno.errno
2222

23+
# poll.h entrypoints
24+
libc.src.poll.poll
25+
2326
# string.h entrypoints
2427
libc.src.string.memccpy
2528
libc.src.string.memchr

libc/config/linux/riscv/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ set(TARGET_LIBC_ENTRYPOINTS
3232
libc.src.fcntl.open
3333
libc.src.fcntl.openat
3434

35+
# poll.h entrypoints
36+
libc.src.poll.poll
37+
3538
# sched.h entrypoints
3639
libc.src.sched.sched_get_priority_max
3740
libc.src.sched.sched_get_priority_min

libc/src/poll/linux/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ add_entrypoint_object(
77
DEPENDS
88
libc.hdr.types.nfds_t
99
libc.hdr.types.struct_pollfd
10+
libc.hdr.types.struct_timespec
1011
libc.include.poll
1112
libc.include.sys_syscall
1213
libc.src.__support.OSUtil.osutil

libc/src/poll/linux/poll.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,35 @@
1010

1111
#include "hdr/types/nfds_t.h"
1212
#include "hdr/types/struct_pollfd.h"
13+
#include "hdr/types/struct_timespec.h"
1314
#include "src/__support/OSUtil/syscall.h" // syscall_impl
1415
#include "src/__support/common.h"
1516
#include "src/__support/macros/config.h"
1617
#include "src/errno/libc_errno.h"
1718

18-
#include <sys/syscall.h> // SYS_poll
19+
#include <sys/syscall.h> // SYS_poll, SYS_ppoll
1920

2021
namespace LIBC_NAMESPACE_DECL {
2122

2223
LLVM_LIBC_FUNCTION(int, poll, (struct pollfd * fds, nfds_t nfds, int timeout)) {
24+
25+
#ifdef SYS_poll
2326
int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_poll, fds, nfds, timeout);
27+
#elif defined(SYS_ppoll)
28+
struct timespec ts, *tsp;
29+
if (timeout >= 0) {
30+
ts.tv_sec = timeout / 1000;
31+
ts.tv_nsec = (timeout % 1000) * 1000000;
32+
tsp = &ts;
33+
} else {
34+
tsp = nullptr;
35+
}
36+
int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_ppoll, fds, nfds, tsp,
37+
nullptr, 0);
38+
#else
39+
#error "SYS_ppoll_time64?"
40+
#endif
41+
2442
if (ret < 0) {
2543
libc_errno = -ret;
2644
return -1;

0 commit comments

Comments
 (0)