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-2018 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.
34 #include "xlat/pollflags.h"
37 print_pollfd(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
39 const struct pollfd *fds = elem_buf;
42 printfd(tcp, fds->fd);
45 printflags(pollflags, (unsigned short) fds->events, "POLL???");
53 decode_poll_entering(struct tcb *tcp)
55 const kernel_ulong_t addr = tcp->u_arg[0];
56 const unsigned int nfds = tcp->u_arg[1];
59 print_array(tcp, addr, nfds, &fds, sizeof(fds),
60 umoven_or_printaddr, print_pollfd, 0);
61 tprintf(", %u, ", nfds);
65 decode_poll_exiting(struct tcb *const tcp, const kernel_ulong_t pts)
68 const unsigned int nfds = tcp->u_arg[1];
69 const unsigned long size = sizeof(fds) * nfds;
70 const kernel_ulong_t start = tcp->u_arg[0];
71 const kernel_ulong_t end = start + size;
73 const unsigned int max_printed =
74 abbrev(tcp) ? max_strlen : -1U;
77 static char outstr[1024];
79 #define end_outstr (outstr + sizeof(outstr))
83 if (tcp->u_rval == 0) {
84 tcp->auxstr = "Timeout";
88 if (!verbose(tcp) || !start || !nfds ||
89 size / sizeof(fds) != nfds || end < start)
94 for (printed = 0, cur = start; cur < end; cur += sizeof(fds)) {
95 if (umove(tcp, cur, &fds) < 0) {
99 outptr = stpcpy(outptr, ", ");
100 outptr = xappendstr(outstr, outptr, "%#" PRI_klx, cur);
105 if (outptr == outstr)
108 outptr = stpcpy(outptr, ", ");
109 if (printed >= max_printed) {
110 outptr = stpcpy(outptr, "...");
114 static const char fmt[] = "{fd=%d, revents=";
115 char fdstr[sizeof(fmt) + sizeof(int) * 3];
116 xsprintf(fdstr, fmt, fds.fd);
118 const char *flagstr = sprintflags("", pollflags,
119 (unsigned short) fds.revents);
121 if (outptr + strlen(fdstr) + strlen(flagstr) + 1 >=
122 end_outstr - (2 + 2 * sizeof(long) + sizeof(", ], ..."))) {
123 outptr = stpcpy(outptr, "...");
126 outptr = stpcpy(outptr, fdstr);
127 outptr = stpcpy(outptr, flagstr);
132 if (outptr != outstr)
137 const char *str = sprint_timespec(tcp, pts);
139 if (outptr + sizeof(", left ") + strlen(str) < end_outstr) {
140 outptr = stpcpy(outptr, outptr == outstr ? "left " : ", left ");
141 outptr = stpcpy(outptr, str);
143 outptr = stpcpy(outptr, ", ...");
147 if (outptr == outstr)
150 tcp->auxstr = outstr;
158 decode_poll_entering(tcp);
159 tprintf("%d", (int) tcp->u_arg[2]);
163 return decode_poll_exiting(tcp, 0);
170 decode_poll_entering(tcp);
172 print_timespec(tcp, tcp->u_arg[2]);
174 /* NB: kernel requires arg[4] == NSIG_BYTES */
175 print_sigset_addr_len(tcp, tcp->u_arg[3], tcp->u_arg[4]);
176 tprintf(", %" PRI_klu, tcp->u_arg[4]);
180 return decode_poll_exiting(tcp, tcp->u_arg[2]);