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.
33 #ifdef HAVE_SYS_POLL_H
34 # include <sys/poll.h>
39 #ifdef HAVE_SYS_CONF_H
40 # include <sys/conf.h>
43 #ifndef HAVE_STROPTS_H
46 int maxlen; /* no. of bytes in buffer */
47 int len; /* no. of bytes returned */
48 const char *buf; /* pointer to data */
52 #endif /* !HAVE_STROPTS_H */
54 static const struct xlat msgflags[] = {
55 { RS_HIPRI, "RS_HIPRI" },
60 printstrbuf(struct tcb *tcp, struct strbuf *sbp, int getting)
62 if (sbp->maxlen == -1 && getting)
63 tprints("{maxlen=-1}");
67 tprintf("maxlen=%d, ", sbp->maxlen);
68 tprintf("len=%d, buf=", sbp->len);
69 printstr(tcp, (unsigned long) sbp->buf, sbp->len);
75 printstrbufarg(struct tcb *tcp, int arg, int getting)
81 else if (umove(tcp, arg, &buf) < 0)
84 printstrbuf(tcp, &buf, getting);
89 sys_putmsg(struct tcb *tcp)
95 tprintf("%ld, ", tcp->u_arg[0]);
96 /* control and data */
97 for (i = 1; i < 3; i++)
98 printstrbufarg(tcp, tcp->u_arg[i], 0);
100 printflags(msgflags, tcp->u_arg[3], "RS_???");
105 #if defined(SPARC) || defined(SPARC64)
107 sys_getmsg(struct tcb *tcp)
113 tprintf("%lu, ", tcp->u_arg[0]);
116 tprintf("%#lx, %#lx, %#lx",
117 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
120 /* control and data */
121 for (i = 1; i < 3; i++)
122 printstrbufarg(tcp, tcp->u_arg[i], 1);
123 /* pointer to flags */
124 if (tcp->u_arg[3] == 0)
126 else if (umove(tcp, tcp->u_arg[3], &flags) < 0)
130 printflags(msgflags, flags, "RS_???");
133 /* decode return value */
134 switch (tcp->u_rval) {
136 tcp->auxstr = "MORECTL";
138 case MORECTL|MOREDATA:
139 tcp->auxstr = "MORECTL|MOREDATA";
142 tcp->auxstr = "MORECTL";
149 return RVAL_HEX | RVAL_STR;
153 #if defined SYS_putpmsg || defined SYS_getpmsg
154 static const struct xlat pmsgflags[] = {
156 { MSG_HIPRI, "MSG_HIPRI" },
159 { MSG_ANY, "MSG_ANY" },
162 { MSG_BAND, "MSG_BAND" },
170 sys_putpmsg(struct tcb *tcp)
176 tprintf("%ld, ", tcp->u_arg[0]);
177 /* control and data */
178 for (i = 1; i < 3; i++)
179 printstrbufarg(tcp, tcp->u_arg[i], 0);
181 tprintf("%ld, ", tcp->u_arg[3]);
183 printflags(pmsgflags, tcp->u_arg[4], "MSG_???");
187 #endif /* SYS_putpmsg */
191 sys_getpmsg(struct tcb *tcp)
197 tprintf("%lu, ", tcp->u_arg[0]);
200 tprintf("%#lx, %#lx, %#lx, %#lx", tcp->u_arg[1],
201 tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[4]);
204 /* control and data */
205 for (i = 1; i < 3; i++)
206 printstrbufarg(tcp, tcp->u_arg[i], 1);
207 /* pointer to band */
208 printnum(tcp, tcp->u_arg[3], "%d");
210 /* pointer to flags */
211 if (tcp->u_arg[4] == 0)
213 else if (umove(tcp, tcp->u_arg[4], &flags) < 0)
217 printflags(pmsgflags, flags, "MSG_???");
220 /* decode return value */
221 switch (tcp->u_rval) {
223 tcp->auxstr = "MORECTL";
225 case MORECTL|MOREDATA:
226 tcp->auxstr = "MORECTL|MOREDATA";
229 tcp->auxstr = "MORECTL";
236 return RVAL_HEX | RVAL_STR;
238 #endif /* SYS_getpmsg */
240 #ifdef HAVE_SYS_POLL_H
242 static const struct xlat pollflags[] = {
244 { POLLIN, "POLLIN" },
245 { POLLPRI, "POLLPRI" },
246 { POLLOUT, "POLLOUT" },
248 { POLLRDNORM, "POLLRDNORM" },
251 { POLLWRNORM, "POLLWRNORM" },
254 { POLLRDBAND, "POLLRDBAND" },
257 { POLLWRBAND, "POLLWRBAND" },
259 { POLLERR, "POLLERR" },
260 { POLLHUP, "POLLHUP" },
261 { POLLNVAL, "POLLNVAL" },
267 decode_poll(struct tcb *tcp, long pts)
271 unsigned long size, start, cur, end, abbrev_end;
275 nfds = tcp->u_arg[1];
276 size = sizeof(fds) * nfds;
277 start = tcp->u_arg[0];
279 if (nfds == 0 || size / sizeof(fds) != nfds || end < start) {
280 tprintf("%#lx, %d, ",
281 tcp->u_arg[0], nfds);
285 abbrev_end = start + max_strlen * sizeof(fds);
286 if (abbrev_end < start)
292 for (cur = start; cur < end; cur += sizeof(fds)) {
295 if (cur >= abbrev_end) {
299 if (umoven(tcp, cur, sizeof fds, (char *) &fds) < 0) {
305 tprintf("{fd=%d}", fds.fd);
309 printfd(tcp, fds.fd);
310 tprints(", events=");
311 printflags(pollflags, fds.events, "POLL???");
316 tprintf(" %#lx", start);
317 tprintf(", %d, ", nfds);
320 static char outstr[1024];
322 #define end_outstr (outstr + sizeof(outstr))
327 if (tcp->u_rval == 0) {
328 tcp->auxstr = "Timeout";
332 nfds = tcp->u_arg[1];
333 size = sizeof(fds) * nfds;
334 start = tcp->u_arg[0];
336 if (nfds == 0 || size / sizeof(fds) != nfds || end < start)
339 abbrev_end = start + max_strlen * sizeof(fds);
340 if (abbrev_end < start)
348 for (cur = start; cur < end; cur += sizeof(fds)) {
349 if (umoven(tcp, cur, sizeof fds, (char *) &fds) < 0) {
350 if (outptr < end_outstr - 2)
357 if (outptr == outstr) {
360 if (outptr < end_outstr - 3)
361 outptr = stpcpy(outptr, ", ");
363 if (cur >= abbrev_end) {
364 if (outptr < end_outstr - 4)
365 outptr = stpcpy(outptr, "...");
368 if (outptr < end_outstr - (sizeof("{fd=%d, revents=") + sizeof(int)*3) + 1)
369 outptr += sprintf(outptr, "{fd=%d, revents=", fds.fd);
370 flagstr = sprintflags("", pollflags, fds.revents);
371 if (outptr < end_outstr - (strlen(flagstr) + 2)) {
372 outptr = stpcpy(outptr, flagstr);
379 if (outptr != outstr /* && outptr < end_outstr - 1 (always true)*/)
384 if (outptr < end_outstr - (10 + TIMESPEC_TEXT_BUFSIZE)) {
385 outptr = stpcpy(outptr, outptr == outstr ? "left " : ", left ");
386 sprint_timespec(outptr, tcp, pts);
390 if (outptr == outstr)
393 tcp->auxstr = outstr;
400 sys_poll(struct tcb *tcp)
402 int rc = decode_poll(tcp, 0);
405 if (tcp->u_arg[2] == INFTIM)
409 tprintf("%ld", tcp->u_arg[2]);
415 sys_ppoll(struct tcb *tcp)
417 int rc = decode_poll(tcp, tcp->u_arg[2]);
419 print_timespec(tcp, tcp->u_arg[2]);
421 print_sigset(tcp, tcp->u_arg[3], 0);
422 tprintf(", %lu", tcp->u_arg[4]);
427 #else /* !HAVE_SYS_POLL_H */
429 sys_poll(struct tcb *tcp)