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