blob: bcc9338282274377d83beb95ac81d3afbbeb6795 [file] [log] [blame]
Dmitry V. Levinaba868c2015-08-01 22:58:17 +00001#include "defs.h"
2#include <fcntl.h>
3#ifdef HAVE_SYS_EPOLL_H
4# include <sys/epoll.h>
5#endif
6
7#include "xlat/epollflags.h"
8
9SYS_FUNC(epoll_create1)
10{
11 printflags(epollflags, tcp->u_arg[0], "EPOLL_???");
12
Dmitry V. Levin7b378e62015-08-01 23:08:39 +000013 return RVAL_DECODED | RVAL_FD;
Dmitry V. Levinaba868c2015-08-01 22:58:17 +000014}
15
16#ifdef HAVE_SYS_EPOLL_H
17# include "xlat/epollevents.h"
18
19static void
20print_epoll_event(struct epoll_event *ev)
21{
22 tprints("{");
23 printflags(epollevents, ev->events, "EPOLL???");
24 /* We cannot know what format the program uses, so print u32 and u64
25 which will cover every value. */
26 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
27 ev->data.u32, ev->data.u64);
28}
29#endif
30
31#include "xlat/epollctls.h"
32
33SYS_FUNC(epoll_ctl)
34{
35 struct epoll_event ev;
36
37 printfd(tcp, tcp->u_arg[0]);
38 tprints(", ");
39 printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
40 tprints(", ");
41 printfd(tcp, tcp->u_arg[2]);
42 tprints(", ");
43#ifdef HAVE_SYS_EPOLL_H
44 if (EPOLL_CTL_DEL == tcp->u_arg[1])
45 printaddr(tcp->u_arg[3]);
46 else if (!umove_or_printaddr(tcp, tcp->u_arg[3], &ev))
47 print_epoll_event(&ev);
48#else
49 printaddr(tcp->u_arg[3]);
50#endif
51
52 return RVAL_DECODED;
53}
54
55static void
56print_epoll_event_array(struct tcb *tcp, const long addr, const long len)
57{
58#ifdef HAVE_SYS_EPOLL_H
59 struct epoll_event ev, *start, *cur, *end;
60
61 if (!len) {
62 tprints("[]");
63 return;
64 }
65
66 if (umove_or_printaddr(tcp, addr, &ev))
67 return;
68
69 tprints("[");
70 print_epoll_event(&ev);
71
72 start = (struct epoll_event *) addr;
73 end = start + len;
74 for (cur = start + 1; cur < end; ++cur) {
75 tprints(", ");
76 if (umove_or_printaddr(tcp, (long) cur, &ev))
77 break;
78 print_epoll_event(&ev);
79 }
80 tprints("]");
81#else
82 printaddr(addr);
83#endif
84}
85
86static void
87epoll_wait_common(struct tcb *tcp)
88{
89 if (entering(tcp)) {
90 printfd(tcp, tcp->u_arg[0]);
91 tprints(", ");
92 } else {
93 print_epoll_event_array(tcp, tcp->u_arg[1], tcp->u_rval);
94 tprintf(", %d, %d", (int) tcp->u_arg[2], (int) tcp->u_arg[3]);
95 }
96}
97
98SYS_FUNC(epoll_wait)
99{
100 epoll_wait_common(tcp);
101 return 0;
102}
103
104SYS_FUNC(epoll_pwait)
105{
106 epoll_wait_common(tcp);
107 if (exiting(tcp)) {
108 tprints(", ");
109 /* NB: kernel requires arg[5] == NSIG / 8 */
110 print_sigset_addr_len(tcp, tcp->u_arg[4], tcp->u_arg[5]);
111 tprintf(", %lu", tcp->u_arg[5]);
112 }
113 return 0;
114}