diff options
Diffstat (limited to 'src/select')
-rw-r--r-- | src/select/poll.c | 9 | ||||
-rw-r--r-- | src/select/ppoll.c | 26 | ||||
-rw-r--r-- | src/select/select.c | 1 |
3 files changed, 34 insertions, 2 deletions
diff --git a/src/select/poll.c b/src/select/poll.c index c84c8a99..7883dfab 100644 --- a/src/select/poll.c +++ b/src/select/poll.c @@ -8,8 +8,13 @@ int poll(struct pollfd *fds, nfds_t n, int timeout) #ifdef SYS_poll return syscall_cp(SYS_poll, fds, n, timeout); #else +#if SYS_ppoll_time64 == SYS_ppoll + typedef long long ppoll_ts_t[2]; +#else + typedef long ppoll_ts_t[2]; +#endif return syscall_cp(SYS_ppoll, fds, n, timeout>=0 ? - &((struct timespec){ .tv_sec = timeout/1000, - .tv_nsec = timeout%1000*1000000 }) : 0, 0, _NSIG/8); + ((ppoll_ts_t){ timeout/1000, timeout%1000*1000000 }) : 0, + 0, _NSIG/8); #endif } diff --git a/src/select/ppoll.c b/src/select/ppoll.c new file mode 100644 index 00000000..9a0bf929 --- /dev/null +++ b/src/select/ppoll.c @@ -0,0 +1,26 @@ +#define _BSD_SOURCE +#include <poll.h> +#include <signal.h> +#include <errno.h> +#include "syscall.h" + +#define IS32BIT(x) !((x)+0x80000000ULL>>32) +#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63)) + +int ppoll(struct pollfd *fds, nfds_t n, const struct timespec *to, const sigset_t *mask) +{ + time_t s = to ? to->tv_sec : 0; + long ns = to ? to->tv_nsec : 0; +#ifdef SYS_ppoll_time64 + int r = -ENOSYS; + if (SYS_ppoll == SYS_ppoll_time64 || !IS32BIT(s)) + r = __syscall_cp(SYS_ppoll_time64, fds, n, + to ? ((long long[]){s, ns}) : 0, + mask, _NSIG/8); + if (SYS_ppoll == SYS_ppoll_time64 || r != -ENOSYS) + return __syscall_ret(r); + s = CLAMP(s); +#endif + return syscall_cp(SYS_ppoll, fds, n, + to ? ((long[]){s, ns}) : 0, mask, _NSIG/8); +} diff --git a/src/select/select.c b/src/select/select.c index 8a786884..f1d72863 100644 --- a/src/select/select.c +++ b/src/select/select.c @@ -33,6 +33,7 @@ int select(int n, fd_set *restrict rfds, fd_set *restrict wfds, fd_set *restrict ((syscall_arg_t[]){ 0, _NSIG/8 })); if (SYS_pselect6 == SYS_pselect6_time64 || r!=-ENOSYS) return __syscall_ret(r); + s = CLAMP(s); #endif #ifdef SYS_select return syscall_cp(SYS_select, n, rfds, wfds, efds, |