1 /*
2 * Check decoding of epoll_pwait2 syscall.
3 *
4 * Copyright (c) 2015-2021 Dmitry V. Levin <ldv@strace.io>
5 * All rights reserved.
6 *
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
9
10 #include "tests.h"
11 #include "scno.h"
12 #include "xmalloc.h"
13 #include <fcntl.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <unistd.h>
17 #include <sys/epoll.h>
18 #include "kernel_timespec.h"
19
20 #ifndef DECODE_FDS
21 # define DECODE_FDS 0
22 #endif
23 #ifndef SKIP_IF_PROC_IS_UNAVAILABLE
24 # define SKIP_IF_PROC_IS_UNAVAILABLE
25 #endif
26
27 static const char *errstr;
28
29 static long
30 k_epoll_pwait2(const unsigned int epfd,
31 const void *const events,
32 const unsigned int maxevents,
33 const void *const timeout,
34 const void *const sigmask,
35 const kernel_ulong_t sigsetsize)
36 {
37 const kernel_ulong_t fill = (kernel_ulong_t) 0xdefaced00000000ULL;
38 const kernel_ulong_t arg1 = fill | epfd;
39 const kernel_ulong_t arg2 = (unsigned long) events;
40 const kernel_ulong_t arg3 = fill | maxevents;
41 const kernel_ulong_t arg4 = (unsigned long) timeout;
42 const kernel_ulong_t arg5 = (unsigned long) sigmask;
43 const kernel_ulong_t arg6 = sigsetsize;
44 const long rc = syscall(__NR_epoll_pwait2,
45 arg1, arg2, arg3, arg4, arg5, arg6);
46 errstr = sprintrc(rc);
47 return rc;
48 }
49
50 int
51 main(void)
52 {
53 SKIP_IF_PROC_IS_UNAVAILABLE;
54
55 static const char fd_path[] = "/dev/full";
56 int fd = open(fd_path, O_WRONLY);
57 if (fd < 0)
58 perror_msg_and_fail("open: %s", fd_path);
59 char *fd_str = xasprintf("%d%s%s%s", fd,
60 DECODE_FDS ? "<" : "",
61 DECODE_FDS ? fd_path : "",
62 DECODE_FDS ? ">" : "");
63
64 TAIL_ALLOC_OBJECT_CONST_PTR(struct epoll_event, events);
65 TAIL_ALLOC_OBJECT_CONST_PTR(kernel_timespec64_t, timeout);
66 TAIL_ALLOC_OBJECT_CONST_PTR(kernel_ulong_t, sigmask);
67 const unsigned int sigsetsize = sizeof(*sigmask);
68
69 k_epoll_pwait2(-1, events, fd, timeout, sigmask, fd);
70 #ifndef PATH_TRACING
71 printf("epoll_pwait2(-1, %p, %d, %p, %p, %u) = %s\n",
72 events, fd, timeout, sigmask, fd, errstr);
73 #endif
74
75 k_epoll_pwait2(fd, events, -1, timeout, sigmask, sigsetsize);
76 printf("epoll_pwait2(%s, %p, -1, %p, %p, %u) = %s\n",
77 fd_str, events, timeout, sigmask, sigsetsize, errstr);
78
79 /*
80 * Some positive tests should be added here
81 * when epoll_pwait2 becomes widely available.
82 */
83
84 puts("+++ exited with 0 +++");
85 return 0;
86 }