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
47 #ifndef HAVE_STROPTS_H
50 int maxlen; /* no. of bytes in buffer */
51 int len; /* no. of bytes returned */
52 const char *buf; /* pointer to data */
56 #endif /* !HAVE_STROPTS_H */
58 static const struct xlat msgflags[] = {
59 { RS_HIPRI, "RS_HIPRI" },
64 printstrbuf(struct tcb *tcp, struct strbuf *sbp, int getting)
66 if (sbp->maxlen == -1 && getting)
67 tprints("{maxlen=-1}");
71 tprintf("maxlen=%d, ", sbp->maxlen);
72 tprintf("len=%d, buf=", sbp->len);
73 printstr(tcp, (unsigned long) sbp->buf, sbp->len);
79 printstrbufarg(struct tcb *tcp, int arg, int getting)
85 else if (umove(tcp, arg, &buf) < 0)
88 printstrbuf(tcp, &buf, getting);
93 sys_putmsg(struct tcb *tcp)
99 tprintf("%ld, ", tcp->u_arg[0]);
100 /* control and data */
101 for (i = 1; i < 3; i++)
102 printstrbufarg(tcp, tcp->u_arg[i], 0);
104 printflags(msgflags, tcp->u_arg[3], "RS_???");
109 #if defined(SPARC) || defined(SPARC64)
111 sys_getmsg(struct tcb *tcp)
117 tprintf("%lu, ", tcp->u_arg[0]);
120 tprintf("%#lx, %#lx, %#lx",
121 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
124 /* control and data */
125 for (i = 1; i < 3; i++)
126 printstrbufarg(tcp, tcp->u_arg[i], 1);
127 /* pointer to flags */
128 if (tcp->u_arg[3] == 0)
130 else if (umove(tcp, tcp->u_arg[3], &flags) < 0)
134 printflags(msgflags, flags, "RS_???");
137 /* decode return value */
138 switch (tcp->u_rval) {
140 tcp->auxstr = "MORECTL";
142 case MORECTL|MOREDATA:
143 tcp->auxstr = "MORECTL|MOREDATA";
146 tcp->auxstr = "MORECTL";
153 return RVAL_HEX | RVAL_STR;
157 #if defined SYS_putpmsg || defined SYS_getpmsg
158 static const struct xlat pmsgflags[] = {
160 { MSG_HIPRI, "MSG_HIPRI" },
163 { MSG_ANY, "MSG_ANY" },
166 { MSG_BAND, "MSG_BAND" },
174 sys_putpmsg(struct tcb *tcp)
180 tprintf("%ld, ", tcp->u_arg[0]);
181 /* control and data */
182 for (i = 1; i < 3; i++)
183 printstrbufarg(tcp, tcp->u_arg[i], 0);
185 tprintf("%ld, ", tcp->u_arg[3]);
187 printflags(pmsgflags, tcp->u_arg[4], "MSG_???");
191 #endif /* SYS_putpmsg */
195 sys_getpmsg(struct tcb *tcp)
201 tprintf("%lu, ", tcp->u_arg[0]);
204 tprintf("%#lx, %#lx, %#lx, %#lx", tcp->u_arg[1],
205 tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[4]);
208 /* control and data */
209 for (i = 1; i < 3; i++)
210 printstrbufarg(tcp, tcp->u_arg[i], 1);
211 /* pointer to band */
212 printnum(tcp, tcp->u_arg[3], "%d");
214 /* pointer to flags */
215 if (tcp->u_arg[4] == 0)
217 else if (umove(tcp, tcp->u_arg[4], &flags) < 0)
221 printflags(pmsgflags, flags, "MSG_???");
224 /* decode return value */
225 switch (tcp->u_rval) {
227 tcp->auxstr = "MORECTL";
229 case MORECTL|MOREDATA:
230 tcp->auxstr = "MORECTL|MOREDATA";
233 tcp->auxstr = "MORECTL";
240 return RVAL_HEX | RVAL_STR;
242 #endif /* SYS_getpmsg */
244 #ifdef HAVE_SYS_POLL_H
246 static const struct xlat pollflags[] = {
248 { POLLIN, "POLLIN" },
249 { POLLPRI, "POLLPRI" },
250 { POLLOUT, "POLLOUT" },
252 { POLLRDNORM, "POLLRDNORM" },
255 { POLLWRNORM, "POLLWRNORM" },
258 { POLLRDBAND, "POLLRDBAND" },
261 { POLLWRBAND, "POLLWRBAND" },
263 { POLLERR, "POLLERR" },
264 { POLLHUP, "POLLHUP" },
265 { POLLNVAL, "POLLNVAL" },
271 decode_poll(struct tcb *tcp, long pts)
275 unsigned long size, start, cur, end, abbrev_end;
279 nfds = tcp->u_arg[1];
280 size = sizeof(fds) * nfds;
281 start = tcp->u_arg[0];
283 if (nfds == 0 || size / sizeof(fds) != nfds || end < start) {
284 tprintf("%#lx, %d, ",
285 tcp->u_arg[0], nfds);
289 abbrev_end = start + max_strlen * sizeof(fds);
290 if (abbrev_end < start)
296 for (cur = start; cur < end; cur += sizeof(fds)) {
299 if (cur >= abbrev_end) {
303 if (umoven(tcp, cur, sizeof fds, (char *) &fds) < 0) {
309 tprintf("{fd=%d}", fds.fd);
313 printfd(tcp, fds.fd);
314 tprints(", events=");
315 printflags(pollflags, fds.events, "POLL???");
320 tprintf(" %#lx", start);
321 tprintf(", %d, ", nfds);
324 static char outstr[1024];
326 #define end_outstr (outstr + sizeof(outstr))
331 if (tcp->u_rval == 0) {
332 tcp->auxstr = "Timeout";
336 nfds = tcp->u_arg[1];
337 size = sizeof(fds) * nfds;
338 start = tcp->u_arg[0];
340 if (nfds == 0 || size / sizeof(fds) != nfds || end < start)
343 abbrev_end = start + max_strlen * sizeof(fds);
344 if (abbrev_end < start)
352 for (cur = start; cur < end; cur += sizeof(fds)) {
353 if (umoven(tcp, cur, sizeof fds, (char *) &fds) < 0) {
354 if (outptr < end_outstr - 2)
361 if (outptr == outstr) {
364 if (outptr < end_outstr - 3)
365 outptr = stpcpy(outptr, ", ");
367 if (cur >= abbrev_end) {
368 if (outptr < end_outstr - 4)
369 outptr = stpcpy(outptr, "...");
372 if (outptr < end_outstr - (sizeof("{fd=%d, revents=") + sizeof(int)*3) + 1)
373 outptr += sprintf(outptr, "{fd=%d, revents=", fds.fd);
374 flagstr = sprintflags("", pollflags, fds.revents);
375 if (outptr < end_outstr - (strlen(flagstr) + 2)) {
376 outptr = stpcpy(outptr, flagstr);
383 if (outptr != outstr /* && outptr < end_outstr - 1 (always true)*/)
388 if (outptr < end_outstr - (10 + TIMESPEC_TEXT_BUFSIZE)) {
389 outptr = stpcpy(outptr, outptr == outstr ? "left " : ", left ");
390 sprint_timespec(outptr, tcp, pts);
394 if (outptr == outstr)
397 tcp->auxstr = outstr;
404 sys_poll(struct tcb *tcp)
406 int rc = decode_poll(tcp, 0);
409 if (tcp->u_arg[2] == INFTIM)
413 tprintf("%ld", tcp->u_arg[2]);
419 sys_ppoll(struct tcb *tcp)
421 int rc = decode_poll(tcp, tcp->u_arg[2]);
423 print_timespec(tcp, tcp->u_arg[2]);
425 print_sigset(tcp, tcp->u_arg[3], 0);
426 tprintf(", %lu", tcp->u_arg[4]);
431 #else /* !HAVE_SYS_POLL_H */
433 sys_poll(struct tcb *tcp)