2 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
3 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
4 * Copyright (c) 1999-2017 The strace developers.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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.
33 #include "xlat/pollflags.h"
36 print_pollfd(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
38 const struct pollfd *fds = elem_buf;
41 printfd(tcp, fds->fd);
44 printflags(pollflags, (unsigned short) fds->events, "POLL???");
52 decode_poll_entering(struct tcb *tcp)
54 const kernel_ulong_t addr = tcp->u_arg[0];
55 const unsigned int nfds = tcp->u_arg[1];
58 print_array(tcp, addr, nfds, &fds, sizeof(fds),
59 umoven_or_printaddr, print_pollfd, 0);
60 tprintf(", %u, ", nfds);
64 decode_poll_exiting(struct tcb *const tcp, const kernel_ulong_t pts)
67 const unsigned int nfds = tcp->u_arg[1];
68 const unsigned long size = sizeof(fds) * nfds;
69 const kernel_ulong_t start = tcp->u_arg[0];
70 const kernel_ulong_t end = start + size;
72 const unsigned int max_printed =
73 abbrev(tcp) ? max_strlen : -1U;
76 static char outstr[1024];
78 #define end_outstr (outstr + sizeof(outstr))
82 if (tcp->u_rval == 0) {
83 tcp->auxstr = "Timeout";
87 if (!verbose(tcp) || !start || !nfds ||
88 size / sizeof(fds) != nfds || end < start)
93 for (printed = 0, cur = start; cur < end; cur += sizeof(fds)) {
94 if (umove(tcp, cur, &fds) < 0) {
98 outptr = stpcpy(outptr, ", ");
99 outptr += sprintf(outptr, "%#" PRI_klx, cur);
104 if (outptr == outstr)
107 outptr = stpcpy(outptr, ", ");
108 if (printed >= max_printed) {
109 outptr = stpcpy(outptr, "...");
113 static const char fmt[] = "{fd=%d, revents=";
114 char fdstr[sizeof(fmt) + sizeof(int) * 3];
115 sprintf(fdstr, fmt, fds.fd);
117 const char *flagstr = sprintflags("", pollflags,
118 (unsigned short) fds.revents);
120 if (outptr + strlen(fdstr) + strlen(flagstr) + 1 >=
121 end_outstr - (2 + 2 * sizeof(long) + sizeof(", ], ..."))) {
122 outptr = stpcpy(outptr, "...");
125 outptr = stpcpy(outptr, fdstr);
126 outptr = stpcpy(outptr, flagstr);
131 if (outptr != outstr)
136 const char *str = sprint_timespec(tcp, pts);
138 if (outptr + sizeof(", left ") + strlen(str) < end_outstr) {
139 outptr = stpcpy(outptr, outptr == outstr ? "left " : ", left ");
140 outptr = stpcpy(outptr, str);
142 outptr = stpcpy(outptr, ", ...");
146 if (outptr == outstr)
149 tcp->auxstr = outstr;
157 decode_poll_entering(tcp);
158 int timeout = tcp->u_arg[2];
161 if (INFTIM == timeout)
165 tprintf("%d", timeout);
169 return decode_poll_exiting(tcp, 0);
176 decode_poll_entering(tcp);
178 print_timespec(tcp, tcp->u_arg[2]);
180 /* NB: kernel requires arg[4] == NSIG_BYTES */
181 print_sigset_addr_len(tcp, tcp->u_arg[3], tcp->u_arg[4]);
182 tprintf(", %" PRI_klu, tcp->u_arg[4]);
186 return decode_poll_exiting(tcp, tcp->u_arg[2]);