]> granicus.if.org Git - strace/blob - epoll.c
rtnl_link: print pad field in the struct ifla_port_vsi decoder
[strace] / epoll.c
1 /*
2  * Copyright (c) 2004-2007 Ulrich Drepper <drepper@redhat.com>
3  * Copyright (c) 2004 Roland McGrath <roland@redhat.com>
4  * Copyright (c) 2005-2015 Dmitry V. Levin <ldv@altlinux.org>
5  * Copyright (c) 2015-2018 The strace developers.
6  * All rights reserved.
7  *
8  * SPDX-License-Identifier: LGPL-2.1-or-later
9  */
10
11 #include "defs.h"
12 #include <fcntl.h>
13 #include <sys/epoll.h>
14
15 SYS_FUNC(epoll_create)
16 {
17         tprintf("%d", (int) tcp->u_arg[0]);
18
19         return RVAL_DECODED | RVAL_FD;
20 }
21
22 #include "xlat/epollflags.h"
23
24 SYS_FUNC(epoll_create1)
25 {
26         printflags(epollflags, tcp->u_arg[0], "EPOLL_???");
27
28         return RVAL_DECODED | RVAL_FD;
29 }
30
31 #include "xlat/epollevents.h"
32
33 static bool
34 print_epoll_event(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
35 {
36         const struct epoll_event *ev = elem_buf;
37
38         tprints("{");
39         printflags(epollevents, ev->events, "EPOLL???");
40         /* We cannot know what format the program uses, so print u32 and u64
41            which will cover every value.  */
42         tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
43                 ev->data.u32, ev->data.u64);
44
45         return true;
46 }
47
48 #include "xlat/epollctls.h"
49
50 SYS_FUNC(epoll_ctl)
51 {
52         printfd(tcp, tcp->u_arg[0]);
53         tprints(", ");
54         const unsigned int op = tcp->u_arg[1];
55         printxval(epollctls, op, "EPOLL_CTL_???");
56         tprints(", ");
57         printfd(tcp, tcp->u_arg[2]);
58         tprints(", ");
59         struct epoll_event ev;
60         if (EPOLL_CTL_DEL == op)
61                 printaddr(tcp->u_arg[3]);
62         else if (!umove_or_printaddr(tcp, tcp->u_arg[3], &ev))
63                 print_epoll_event(tcp, &ev, sizeof(ev), 0);
64
65         return RVAL_DECODED;
66 }
67
68 static void
69 epoll_wait_common(struct tcb *tcp)
70 {
71         if (entering(tcp)) {
72                 printfd(tcp, tcp->u_arg[0]);
73                 tprints(", ");
74         } else {
75                 struct epoll_event ev;
76                 print_array(tcp, tcp->u_arg[1], tcp->u_rval, &ev, sizeof(ev),
77                             tfetch_mem, print_epoll_event, 0);
78                 tprintf(", %d, %d", (int) tcp->u_arg[2], (int) tcp->u_arg[3]);
79         }
80 }
81
82 SYS_FUNC(epoll_wait)
83 {
84         epoll_wait_common(tcp);
85         return 0;
86 }
87
88 SYS_FUNC(epoll_pwait)
89 {
90         epoll_wait_common(tcp);
91         if (exiting(tcp)) {
92                 tprints(", ");
93                 /* NB: kernel requires arg[5] == NSIG_BYTES */
94                 print_sigset_addr_len(tcp, tcp->u_arg[4], tcp->u_arg[5]);
95                 tprintf(", %" PRI_klu, tcp->u_arg[5]);
96         }
97         return 0;
98 }