blob: 80883c985a416c6367b3667df5e3008ab5cc0f20 [file] [log] [blame]
Dmitry V. Levin38a34c92015-12-17 17:56:48 +00001/*
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>
Elliott Hughes03a418e2018-06-15 13:11:40 -07005 * Copyright (c) 2015-2018 The strace developers.
Dmitry V. Levin38a34c92015-12-17 17:56:48 +00006 * 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
Dmitry V. Levinaba868c2015-08-01 22:58:17 +000031#include "defs.h"
32#include <fcntl.h>
Dmitry V. Levin6d440122016-05-09 21:46:17 +000033#include <sys/epoll.h>
Dmitry V. Levinaba868c2015-08-01 22:58:17 +000034
Dmitry V. Levinbaaa41c2015-08-01 23:11:43 +000035SYS_FUNC(epoll_create)
36{
37 tprintf("%d", (int) tcp->u_arg[0]);
38
39 return RVAL_DECODED | RVAL_FD;
40}
41
Dmitry V. Levinaba868c2015-08-01 22:58:17 +000042#include "xlat/epollflags.h"
43
44SYS_FUNC(epoll_create1)
45{
46 printflags(epollflags, tcp->u_arg[0], "EPOLL_???");
47
Dmitry V. Levin7b378e62015-08-01 23:08:39 +000048 return RVAL_DECODED | RVAL_FD;
Dmitry V. Levinaba868c2015-08-01 22:58:17 +000049}
50
Dmitry V. Levin6d440122016-05-09 21:46:17 +000051#include "xlat/epollevents.h"
Dmitry V. Levinaba868c2015-08-01 22:58:17 +000052
Dmitry V. Levin02387252016-05-07 22:49:39 +000053static bool
54print_epoll_event(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
Dmitry V. Levinaba868c2015-08-01 22:58:17 +000055{
Dmitry V. Levin02387252016-05-07 22:49:39 +000056 const struct epoll_event *ev = elem_buf;
57
Dmitry V. Levinaba868c2015-08-01 22:58:17 +000058 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);
Dmitry V. Levin02387252016-05-07 22:49:39 +000064
65 return true;
Dmitry V. Levinaba868c2015-08-01 22:58:17 +000066}
Dmitry V. Levinaba868c2015-08-01 22:58:17 +000067
68#include "xlat/epollctls.h"
69
70SYS_FUNC(epoll_ctl)
71{
Dmitry V. Levinaba868c2015-08-01 22:58:17 +000072 printfd(tcp, tcp->u_arg[0]);
73 tprints(", ");
Dmitry V. Levin55044d92016-05-16 21:43:35 +000074 const unsigned int op = tcp->u_arg[1];
75 printxval(epollctls, op, "EPOLL_CTL_???");
Dmitry V. Levinaba868c2015-08-01 22:58:17 +000076 tprints(", ");
77 printfd(tcp, tcp->u_arg[2]);
78 tprints(", ");
Dmitry V. Levin02387252016-05-07 22:49:39 +000079 struct epoll_event ev;
Dmitry V. Levin55044d92016-05-16 21:43:35 +000080 if (EPOLL_CTL_DEL == op)
Dmitry V. Levinaba868c2015-08-01 22:58:17 +000081 printaddr(tcp->u_arg[3]);
82 else if (!umove_or_printaddr(tcp, tcp->u_arg[3], &ev))
Dmitry V. Levin02387252016-05-07 22:49:39 +000083 print_epoll_event(tcp, &ev, sizeof(ev), 0);
Dmitry V. Levinaba868c2015-08-01 22:58:17 +000084
85 return RVAL_DECODED;
86}
87
88static void
Dmitry V. Levinaba868c2015-08-01 22:58:17 +000089epoll_wait_common(struct tcb *tcp)
90{
91 if (entering(tcp)) {
92 printfd(tcp, tcp->u_arg[0]);
93 tprints(", ");
94 } else {
Dmitry V. Levin02387252016-05-07 22:49:39 +000095 struct epoll_event ev;
96 print_array(tcp, tcp->u_arg[1], tcp->u_rval, &ev, sizeof(ev),
Elliott Hughes03a418e2018-06-15 13:11:40 -070097 tfetch_mem, print_epoll_event, 0);
Dmitry V. Levinaba868c2015-08-01 22:58:17 +000098 tprintf(", %d, %d", (int) tcp->u_arg[2], (int) tcp->u_arg[3]);
99 }
100}
101
102SYS_FUNC(epoll_wait)
103{
104 epoll_wait_common(tcp);
105 return 0;
106}
107
108SYS_FUNC(epoll_pwait)
109{
110 epoll_wait_common(tcp);
111 if (exiting(tcp)) {
112 tprints(", ");
Elliott Hughesd35df492017-02-15 15:19:05 -0800113 /* NB: kernel requires arg[5] == NSIG_BYTES */
Dmitry V. Levinaba868c2015-08-01 22:58:17 +0000114 print_sigset_addr_len(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Elliott Hughesd35df492017-02-15 15:19:05 -0800115 tprintf(", %" PRI_klu, tcp->u_arg[5]);
Dmitry V. Levinaba868c2015-08-01 22:58:17 +0000116 }
117 return 0;
118}