1 /*
2 * Check decoding of epoll_ctl syscall.
3 *
4 * Copyright (c) 2016-2021 The strace developers.
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
13 #include <inttypes.h>
14 #include <stdio.h>
15 #include <sys/epoll.h>
16 #include <unistd.h>
17
18 static long
19 invoke_syscall(unsigned long epfd, unsigned long op, unsigned long fd, void *ev)
20 {
21 return syscall(__NR_epoll_ctl, epfd, F8ILL_KULONG_MASK | op,
22 fd, (unsigned long) ev);
23 }
24
25 int
26 main(void)
27 {
28 TAIL_ALLOC_OBJECT_CONST_PTR(struct epoll_event, ev);
29 ev->events = EPOLLIN;
30
31 long rc = invoke_syscall(-1U, EPOLL_CTL_ADD, -2U, ev);
32 printf("epoll_ctl(-1, EPOLL_CTL_ADD, -2"
33 ", {events=EPOLLIN, data={u32=%u, u64=%" PRIu64 "}}) = %s\n",
34 ev->data.u32, ev->data.u64, sprintrc(rc));
35
36 rc = invoke_syscall(-3U, EPOLL_CTL_DEL, -4U, ev);
37 printf("epoll_ctl(-3, EPOLL_CTL_DEL, -4, %p) = %s\n",
38 ev, sprintrc(rc));
39
40 rc = invoke_syscall(-1UL, EPOLL_CTL_MOD, -16UL, 0);
41 printf("epoll_ctl(-1, EPOLL_CTL_MOD, -16, NULL) = %s\n",
42 sprintrc(rc));
43
44 puts("+++ exited with 0 +++");
45 return 0;
46 }