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-2017 The strace developers.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "defs.h"
32 #include <fcntl.h>
33 #include <sys/epoll.h>
34
SYS_FUNC(epoll_create)35 SYS_FUNC(epoll_create)
36 {
37 tprintf("%d", (int) tcp->u_arg[0]);
38
39 return RVAL_DECODED | RVAL_FD;
40 }
41
42 #include "xlat/epollflags.h"
43
SYS_FUNC(epoll_create1)44 SYS_FUNC(epoll_create1)
45 {
46 printflags(epollflags, tcp->u_arg[0], "EPOLL_???");
47
48 return RVAL_DECODED | RVAL_FD;
49 }
50
51 #include "xlat/epollevents.h"
52
53 static bool
print_epoll_event(struct tcb * tcp,void * elem_buf,size_t elem_size,void * data)54 print_epoll_event(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
55 {
56 const struct epoll_event *ev = elem_buf;
57
58 tprints("{");
59 printflags(epollevents, ev->events, "EPOLL???");
60 /* We cannot know what format the program uses, so print u32 and u64
61 which will cover every value. */
62 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
63 ev->data.u32, ev->data.u64);
64
65 return true;
66 }
67
68 #include "xlat/epollctls.h"
69
SYS_FUNC(epoll_ctl)70 SYS_FUNC(epoll_ctl)
71 {
72 printfd(tcp, tcp->u_arg[0]);
73 tprints(", ");
74 const unsigned int op = tcp->u_arg[1];
75 printxval(epollctls, op, "EPOLL_CTL_???");
76 tprints(", ");
77 printfd(tcp, tcp->u_arg[2]);
78 tprints(", ");
79 struct epoll_event ev;
80 if (EPOLL_CTL_DEL == op)
81 printaddr(tcp->u_arg[3]);
82 else if (!umove_or_printaddr(tcp, tcp->u_arg[3], &ev))
83 print_epoll_event(tcp, &ev, sizeof(ev), 0);
84
85 return RVAL_DECODED;
86 }
87
88 static void
epoll_wait_common(struct tcb * tcp)89 epoll_wait_common(struct tcb *tcp)
90 {
91 if (entering(tcp)) {
92 printfd(tcp, tcp->u_arg[0]);
93 tprints(", ");
94 } else {
95 struct epoll_event ev;
96 print_array(tcp, tcp->u_arg[1], tcp->u_rval, &ev, sizeof(ev),
97 umoven_or_printaddr, print_epoll_event, 0);
98 tprintf(", %d, %d", (int) tcp->u_arg[2], (int) tcp->u_arg[3]);
99 }
100 }
101
SYS_FUNC(epoll_wait)102 SYS_FUNC(epoll_wait)
103 {
104 epoll_wait_common(tcp);
105 return 0;
106 }
107
SYS_FUNC(epoll_pwait)108 SYS_FUNC(epoll_pwait)
109 {
110 epoll_wait_common(tcp);
111 if (exiting(tcp)) {
112 tprints(", ");
113 /* NB: kernel requires arg[5] == NSIG_BYTES */
114 print_sigset_addr_len(tcp, tcp->u_arg[4], tcp->u_arg[5]);
115 tprintf(", %" PRI_klu, tcp->u_arg[5]);
116 }
117 return 0;
118 }
119