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