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 <sys/syscall.h>
37 #ifdef HAVE_SYS_POLL_H
43 #ifdef HAVE_SYS_CONF_H
46 #ifdef HAVE_SYS_STREAM_H
47 #include <sys/stream.h>
49 #ifdef HAVE_SYS_TIHDR_H
50 #include <sys/tihdr.h>
54 #ifndef HAVE_STROPTS_H
57 int maxlen; /* no. of bytes in buffer */
58 int len; /* no. of bytes returned */
59 const char *buf; /* pointer to data */
63 #endif /* !HAVE_STROPTS_H */
65 #ifdef HAVE_SYS_TIUSER_H
66 #include <sys/tiuser.h>
67 #include <sys/sockmod.h>
68 #include <sys/timod.h>
69 #endif /* HAVE_SYS_TIUSER_H */
71 static const struct xlat msgflags[] = {
72 { RS_HIPRI, "RS_HIPRI" },
78 printstrbuf(struct tcb *tcp, struct strbuf *sbp, int getting)
80 if (sbp->maxlen == -1 && getting)
81 tprints("{maxlen=-1}");
85 tprintf("maxlen=%d, ", sbp->maxlen);
86 tprintf("len=%d, buf=", sbp->len);
87 printstr(tcp, (unsigned long) sbp->buf, sbp->len);
93 printstrbufarg(struct tcb *tcp, int arg, int getting)
99 else if (umove(tcp, arg, &buf) < 0)
102 printstrbuf(tcp, &buf, getting);
107 sys_putmsg(struct tcb *tcp)
113 tprintf("%ld, ", tcp->u_arg[0]);
114 /* control and data */
115 for (i = 1; i < 3; i++)
116 printstrbufarg(tcp, tcp->u_arg[i], 0);
118 printflags(msgflags, tcp->u_arg[3], "RS_???");
123 #if defined(SPARC) || defined(SPARC64)
125 sys_getmsg(struct tcb *tcp)
131 tprintf("%lu, ", tcp->u_arg[0]);
134 tprintf("%#lx, %#lx, %#lx",
135 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
138 /* control and data */
139 for (i = 1; i < 3; i++)
140 printstrbufarg(tcp, tcp->u_arg[i], 1);
141 /* pointer to flags */
142 if (tcp->u_arg[3] == 0)
144 else if (umove(tcp, tcp->u_arg[3], &flags) < 0)
148 printflags(msgflags, flags, "RS_???");
151 /* decode return value */
152 switch (tcp->u_rval) {
154 tcp->auxstr = "MORECTL";
156 case MORECTL|MOREDATA:
157 tcp->auxstr = "MORECTL|MOREDATA";
160 tcp->auxstr = "MORECTL";
167 return RVAL_HEX | RVAL_STR;
171 #if defined SYS_putpmsg || defined SYS_getpmsg
172 static const struct xlat pmsgflags[] = {
174 { MSG_HIPRI, "MSG_HIPRI" },
177 { MSG_ANY, "MSG_ANY" },
180 { MSG_BAND, "MSG_BAND" },
188 sys_putpmsg(struct tcb *tcp)
194 tprintf("%ld, ", tcp->u_arg[0]);
195 /* control and data */
196 for (i = 1; i < 3; i++)
197 printstrbufarg(tcp, tcp->u_arg[i], 0);
199 tprintf("%ld, ", tcp->u_arg[3]);
201 printflags(pmsgflags, tcp->u_arg[4], "MSG_???");
205 #endif /* SYS_putpmsg */
209 sys_getpmsg(struct tcb *tcp)
215 tprintf("%lu, ", tcp->u_arg[0]);
218 tprintf("%#lx, %#lx, %#lx, %#lx", tcp->u_arg[1],
219 tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[4]);
222 /* control and data */
223 for (i = 1; i < 3; i++)
224 printstrbufarg(tcp, tcp->u_arg[i], 1);
225 /* pointer to band */
226 printnum(tcp, tcp->u_arg[3], "%d");
228 /* pointer to flags */
229 if (tcp->u_arg[4] == 0)
231 else if (umove(tcp, tcp->u_arg[4], &flags) < 0)
235 printflags(pmsgflags, flags, "MSG_???");
238 /* decode return value */
239 switch (tcp->u_rval) {
241 tcp->auxstr = "MORECTL";
243 case MORECTL|MOREDATA:
244 tcp->auxstr = "MORECTL|MOREDATA";
247 tcp->auxstr = "MORECTL";
254 return RVAL_HEX | RVAL_STR;
256 #endif /* SYS_getpmsg */
260 #ifdef HAVE_SYS_POLL_H
262 static const struct xlat pollflags[] = {
264 { POLLIN, "POLLIN" },
265 { POLLPRI, "POLLPRI" },
266 { POLLOUT, "POLLOUT" },
268 { POLLRDNORM, "POLLRDNORM" },
271 { POLLWRNORM, "POLLWRNORM" },
274 { POLLRDBAND, "POLLRDBAND" },
277 { POLLWRBAND, "POLLWRBAND" },
279 { POLLERR, "POLLERR" },
280 { POLLHUP, "POLLHUP" },
281 { POLLNVAL, "POLLNVAL" },
287 decode_poll(struct tcb *tcp, long pts)
291 unsigned long size, start, cur, end, abbrev_end;
295 nfds = tcp->u_arg[1];
296 size = sizeof(fds) * nfds;
297 start = tcp->u_arg[0];
299 if (nfds == 0 || size / sizeof(fds) != nfds || end < start) {
300 tprintf("%#lx, %d, ",
301 tcp->u_arg[0], nfds);
305 abbrev_end = start + max_strlen * sizeof(fds);
306 if (abbrev_end < start)
312 for (cur = start; cur < end; cur += sizeof(fds)) {
315 if (cur >= abbrev_end) {
319 if (umoven(tcp, cur, sizeof fds, (char *) &fds) < 0) {
325 tprintf("{fd=%d}", fds.fd);
329 printfd(tcp, fds.fd);
330 tprints(", events=");
331 printflags(pollflags, fds.events, "POLL???");
336 tprintf(" %#lx", start);
337 tprintf(", %d, ", nfds);
340 static char outstr[1024];
342 #define end_outstr (outstr + sizeof(outstr))
347 if (tcp->u_rval == 0) {
348 tcp->auxstr = "Timeout";
352 nfds = tcp->u_arg[1];
353 size = sizeof(fds) * nfds;
354 start = tcp->u_arg[0];
356 if (nfds == 0 || size / sizeof(fds) != nfds || end < start)
359 abbrev_end = start + max_strlen * sizeof(fds);
360 if (abbrev_end < start)
368 for (cur = start; cur < end; cur += sizeof(fds)) {
369 if (umoven(tcp, cur, sizeof fds, (char *) &fds) < 0) {
370 if (outptr < end_outstr - 2)
377 if (outptr == outstr) {
380 if (outptr < end_outstr - 3)
381 outptr = stpcpy(outptr, ", ");
383 if (cur >= abbrev_end) {
384 if (outptr < end_outstr - 4)
385 outptr = stpcpy(outptr, "...");
388 if (outptr < end_outstr - (sizeof("{fd=%d, revents=") + sizeof(int)*3) + 1)
389 outptr += sprintf(outptr, "{fd=%d, revents=", fds.fd);
390 flagstr = sprintflags("", pollflags, fds.revents);
391 if (outptr < end_outstr - (strlen(flagstr) + 2)) {
392 outptr = stpcpy(outptr, flagstr);
399 if (outptr != outstr /* && outptr < end_outstr - 1 (always true)*/)
404 if (outptr < end_outstr - (10 + TIMESPEC_TEXT_BUFSIZE)) {
405 outptr = stpcpy(outptr, outptr == outstr ? "left " : ", left ");
406 sprint_timespec(outptr, tcp, pts);
410 if (outptr == outstr)
413 tcp->auxstr = outstr;
420 sys_poll(struct tcb *tcp)
422 int rc = decode_poll(tcp, 0);
425 if (tcp->u_arg[2] == INFTIM)
429 tprintf("%ld", tcp->u_arg[2]);
435 sys_ppoll(struct tcb *tcp)
437 int rc = decode_poll(tcp, tcp->u_arg[2]);
439 print_timespec(tcp, tcp->u_arg[2]);
441 print_sigset(tcp, tcp->u_arg[3], 0);
442 tprintf(", %lu", tcp->u_arg[4]);
447 #else /* !HAVE_SYS_POLL_H */
449 sys_poll(struct tcb *tcp)