| 1 | #include <sys/select.h> |
| 2 | #include <signal.h> |
| 3 | #include <stdint.h> |
| 4 | #include <errno.h> |
| 5 | #include "syscall.h" |
| 6 | |
| 7 | #define IS32BIT(x) !((x)+0x80000000ULL>>32) |
| 8 | #define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63)) |
| 9 | |
| 10 | int pselect(int n, fd_set *restrict rfds, fd_set *restrict wfds, fd_set *restrict efds, const struct timespec *restrict ts, const sigset_t *restrict mask) |
| 11 | { |
| 12 | 	syscall_arg_t data[2] = { (uintptr_t)mask, _NSIG/8 }; |
| 13 | 	time_t s = ts ? ts->tv_sec : 0; |
| 14 | 	long ns = ts ? ts->tv_nsec : 0; |
| 15 | #ifdef SYS_pselect6_time64 |
| 16 | 	int r = -ENOSYS; |
| 17 | 	if (SYS_pselect6 == SYS_pselect6_time64 || !IS32BIT(s)) |
| 18 | 		r = __syscall_cp(SYS_pselect6_time64, n, rfds, wfds, efds, |
| 19 | 			ts ? ((long long[]){s, ns}) : 0, data); |
| 20 | 	if (SYS_pselect6 == SYS_pselect6_time64 || r!=-ENOSYS) |
| 21 | 		return __syscall_ret(r); |
| 22 | 	s = CLAMP(s); |
| 23 | #endif |
| 24 | 	return syscall_cp(SYS_pselect6, n, rfds, wfds, efds, |
| 25 | 		ts ? ((long[]){s, ns}) : 0, data); |
| 26 | } |