1*49cdfc7eSAndroid Build Coastguard Worker /* SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker *
3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) 2016 Cyril Hrubis <[email protected]>
4*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) 2021 Xie Ziyao <[email protected]>
5*49cdfc7eSAndroid Build Coastguard Worker */
6*49cdfc7eSAndroid Build Coastguard Worker
7*49cdfc7eSAndroid Build Coastguard Worker #ifndef LAPI_EPOLL_H__
8*49cdfc7eSAndroid Build Coastguard Worker #define LAPI_EPOLL_H__
9*49cdfc7eSAndroid Build Coastguard Worker
10*49cdfc7eSAndroid Build Coastguard Worker #include "lapi/syscalls.h"
11*49cdfc7eSAndroid Build Coastguard Worker #include "tst_timer.h"
12*49cdfc7eSAndroid Build Coastguard Worker
13*49cdfc7eSAndroid Build Coastguard Worker #ifndef EPOLL_CLOEXEC
14*49cdfc7eSAndroid Build Coastguard Worker #define EPOLL_CLOEXEC 02000000
15*49cdfc7eSAndroid Build Coastguard Worker #endif
16*49cdfc7eSAndroid Build Coastguard Worker
epoll_pwait_supported(void)17*49cdfc7eSAndroid Build Coastguard Worker static inline void epoll_pwait_supported(void)
18*49cdfc7eSAndroid Build Coastguard Worker {
19*49cdfc7eSAndroid Build Coastguard Worker /* allow the tests to fail early */
20*49cdfc7eSAndroid Build Coastguard Worker tst_syscall(__NR_epoll_pwait);
21*49cdfc7eSAndroid Build Coastguard Worker }
22*49cdfc7eSAndroid Build Coastguard Worker
23*49cdfc7eSAndroid Build Coastguard Worker #ifndef HAVE_EPOLL_PWAIT
epoll_pwait(int epfd,struct epoll_event * events,int maxevents,int timeout,const sigset_t * sigmask)24*49cdfc7eSAndroid Build Coastguard Worker static inline int epoll_pwait(int epfd, struct epoll_event *events,
25*49cdfc7eSAndroid Build Coastguard Worker int maxevents, int timeout,
26*49cdfc7eSAndroid Build Coastguard Worker const sigset_t *sigmask)
27*49cdfc7eSAndroid Build Coastguard Worker {
28*49cdfc7eSAndroid Build Coastguard Worker return tst_syscall(__NR_epoll_pwait, epfd, events, maxevents,
29*49cdfc7eSAndroid Build Coastguard Worker timeout, sigmask, _NSIG / 8);
30*49cdfc7eSAndroid Build Coastguard Worker }
31*49cdfc7eSAndroid Build Coastguard Worker #endif
32*49cdfc7eSAndroid Build Coastguard Worker
epoll_pwait2_supported(void)33*49cdfc7eSAndroid Build Coastguard Worker static inline void epoll_pwait2_supported(void)
34*49cdfc7eSAndroid Build Coastguard Worker {
35*49cdfc7eSAndroid Build Coastguard Worker /* allow the tests to fail early */
36*49cdfc7eSAndroid Build Coastguard Worker tst_syscall(__NR_epoll_pwait2);
37*49cdfc7eSAndroid Build Coastguard Worker }
38*49cdfc7eSAndroid Build Coastguard Worker
39*49cdfc7eSAndroid Build Coastguard Worker #ifndef HAVE_EPOLL_PWAIT2
epoll_pwait2(int epfd,struct epoll_event * events,int maxevents,const struct timespec * timeout,const sigset_t * sigmask)40*49cdfc7eSAndroid Build Coastguard Worker static inline int epoll_pwait2(int epfd, struct epoll_event *events,
41*49cdfc7eSAndroid Build Coastguard Worker int maxevents, const struct timespec *timeout,
42*49cdfc7eSAndroid Build Coastguard Worker const sigset_t *sigmask)
43*49cdfc7eSAndroid Build Coastguard Worker {
44*49cdfc7eSAndroid Build Coastguard Worker if (timeout == NULL)
45*49cdfc7eSAndroid Build Coastguard Worker return tst_syscall(__NR_epoll_pwait2, epfd, events, maxevents,
46*49cdfc7eSAndroid Build Coastguard Worker NULL, sigmask, _NSIG / 8);
47*49cdfc7eSAndroid Build Coastguard Worker
48*49cdfc7eSAndroid Build Coastguard Worker struct __kernel_timespec ts;
49*49cdfc7eSAndroid Build Coastguard Worker
50*49cdfc7eSAndroid Build Coastguard Worker ts.tv_sec = timeout->tv_sec;
51*49cdfc7eSAndroid Build Coastguard Worker ts.tv_nsec = timeout->tv_nsec;
52*49cdfc7eSAndroid Build Coastguard Worker
53*49cdfc7eSAndroid Build Coastguard Worker return tst_syscall(__NR_epoll_pwait2, epfd, events, maxevents,
54*49cdfc7eSAndroid Build Coastguard Worker &ts, sigmask, _NSIG / 8);
55*49cdfc7eSAndroid Build Coastguard Worker }
56*49cdfc7eSAndroid Build Coastguard Worker #endif
57*49cdfc7eSAndroid Build Coastguard Worker
58*49cdfc7eSAndroid Build Coastguard Worker #endif /* LAPI_EPOLL_H__ */
59