2 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
3 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "xlat/pollflags.h"
35 print_pollfd(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
37 const struct pollfd *fds = elem_buf;
40 printfd(tcp, fds->fd);
43 printflags(pollflags, (unsigned short) fds->events, "POLL???");
51 decode_poll_entering(struct tcb *tcp)
53 const unsigned long addr = tcp->u_arg[0];
54 const unsigned int nfds = tcp->u_arg[1];
57 print_array(tcp, addr, nfds, &fds, sizeof(fds),
58 umoven_or_printaddr, print_pollfd, 0);
59 tprintf(", %u, ", nfds);
63 decode_poll_exiting(struct tcb *tcp, const long pts)
66 const unsigned int nfds = tcp->u_arg[1];
67 const unsigned long size = sizeof(fds) * nfds;
68 const unsigned long start = tcp->u_arg[0];
69 const unsigned long end = start + size;
70 const unsigned long max_printed =
71 abbrev(tcp) ? max_strlen : (unsigned int) -1;
72 unsigned long printed, cur;
74 static char outstr[1024];
76 #define end_outstr (outstr + sizeof(outstr))
80 if (tcp->u_rval == 0) {
81 tcp->auxstr = "Timeout";
85 if (!verbose(tcp) || !start || !nfds ||
86 size / sizeof(fds) != nfds || end < start)
91 for (printed = 0, cur = start; cur < end; cur += sizeof(fds)) {
92 if (umove(tcp, cur, &fds) < 0) {
96 outptr = stpcpy(outptr, ", ");
97 outptr += sprintf(outptr, "%#lx", cur);
102 if (outptr == outstr)
105 outptr = stpcpy(outptr, ", ");
106 if (printed >= max_printed) {
107 outptr = stpcpy(outptr, "...");
111 static const char fmt[] = "{fd=%d, revents=";
112 char fdstr[sizeof(fmt) + sizeof(int) * 3];
113 sprintf(fdstr, fmt, fds.fd);
115 const char *flagstr = sprintflags("", pollflags,
116 (unsigned short) fds.revents);
118 if (outptr + strlen(fdstr) + strlen(flagstr) + 1 >=
119 end_outstr - (2 + 2 * sizeof(long) + sizeof(", ], ..."))) {
120 outptr = stpcpy(outptr, "...");
123 outptr = stpcpy(outptr, fdstr);
124 outptr = stpcpy(outptr, flagstr);
129 if (outptr != outstr)
134 const char *str = sprint_timespec(tcp, pts);
136 if (outptr + sizeof(", left ") + strlen(str) < end_outstr) {
137 outptr = stpcpy(outptr, outptr == outstr ? "left " : ", left ");
138 outptr = stpcpy(outptr, str);
140 outptr = stpcpy(outptr, ", ...");
144 if (outptr == outstr)
147 tcp->auxstr = outstr;
155 decode_poll_entering(tcp);
156 int timeout = tcp->u_arg[2];
159 if (INFTIM == timeout)
163 tprintf("%d", timeout);
167 return decode_poll_exiting(tcp, 0);
174 decode_poll_entering(tcp);
176 print_timespec(tcp, tcp->u_arg[2]);
178 /* NB: kernel requires arg[4] == NSIG / 8 */
179 print_sigset_addr_len(tcp, tcp->u_arg[3], tcp->u_arg[4]);
180 tprintf(", %lu", tcp->u_arg[4]);
184 return decode_poll_exiting(tcp, tcp->u_arg[2]);