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.
36 #ifdef HAVE_SYS_POLL_H
42 #ifdef HAVE_SYS_CONF_H
46 #ifndef HAVE_STROPTS_H
49 int maxlen; /* no. of bytes in buffer */
50 int len; /* no. of bytes returned */
51 const char *buf; /* pointer to data */
55 #endif /* !HAVE_STROPTS_H */
57 static const struct xlat msgflags[] = {
58 { RS_HIPRI, "RS_HIPRI" },
63 printstrbuf(struct tcb *tcp, struct strbuf *sbp, int getting)
65 if (sbp->maxlen == -1 && getting)
66 tprints("{maxlen=-1}");
70 tprintf("maxlen=%d, ", sbp->maxlen);
71 tprintf("len=%d, buf=", sbp->len);
72 printstr(tcp, (unsigned long) sbp->buf, sbp->len);
78 printstrbufarg(struct tcb *tcp, int arg, int getting)
84 else if (umove(tcp, arg, &buf) < 0)
87 printstrbuf(tcp, &buf, getting);
92 sys_putmsg(struct tcb *tcp)
98 tprintf("%ld, ", tcp->u_arg[0]);
99 /* control and data */
100 for (i = 1; i < 3; i++)
101 printstrbufarg(tcp, tcp->u_arg[i], 0);
103 printflags(msgflags, tcp->u_arg[3], "RS_???");
108 #if defined(SPARC) || defined(SPARC64)
110 sys_getmsg(struct tcb *tcp)
116 tprintf("%lu, ", tcp->u_arg[0]);
119 tprintf("%#lx, %#lx, %#lx",
120 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
123 /* control and data */
124 for (i = 1; i < 3; i++)
125 printstrbufarg(tcp, tcp->u_arg[i], 1);
126 /* pointer to flags */
127 if (tcp->u_arg[3] == 0)
129 else if (umove(tcp, tcp->u_arg[3], &flags) < 0)
133 printflags(msgflags, flags, "RS_???");
136 /* decode return value */
137 switch (tcp->u_rval) {
139 tcp->auxstr = "MORECTL";
141 case MORECTL|MOREDATA:
142 tcp->auxstr = "MORECTL|MOREDATA";
145 tcp->auxstr = "MORECTL";
152 return RVAL_HEX | RVAL_STR;
156 #if defined SYS_putpmsg || defined SYS_getpmsg
157 static const struct xlat pmsgflags[] = {
159 { MSG_HIPRI, "MSG_HIPRI" },
162 { MSG_ANY, "MSG_ANY" },
165 { MSG_BAND, "MSG_BAND" },
173 sys_putpmsg(struct tcb *tcp)
179 tprintf("%ld, ", tcp->u_arg[0]);
180 /* control and data */
181 for (i = 1; i < 3; i++)
182 printstrbufarg(tcp, tcp->u_arg[i], 0);
184 tprintf("%ld, ", tcp->u_arg[3]);
186 printflags(pmsgflags, tcp->u_arg[4], "MSG_???");
190 #endif /* SYS_putpmsg */
194 sys_getpmsg(struct tcb *tcp)
200 tprintf("%lu, ", tcp->u_arg[0]);
203 tprintf("%#lx, %#lx, %#lx, %#lx", tcp->u_arg[1],
204 tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[4]);
207 /* control and data */
208 for (i = 1; i < 3; i++)
209 printstrbufarg(tcp, tcp->u_arg[i], 1);
210 /* pointer to band */
211 printnum(tcp, tcp->u_arg[3], "%d");
213 /* pointer to flags */
214 if (tcp->u_arg[4] == 0)
216 else if (umove(tcp, tcp->u_arg[4], &flags) < 0)
220 printflags(pmsgflags, flags, "MSG_???");
223 /* decode return value */
224 switch (tcp->u_rval) {
226 tcp->auxstr = "MORECTL";
228 case MORECTL|MOREDATA:
229 tcp->auxstr = "MORECTL|MOREDATA";
232 tcp->auxstr = "MORECTL";
239 return RVAL_HEX | RVAL_STR;
241 #endif /* SYS_getpmsg */
243 #ifdef HAVE_SYS_POLL_H
245 static const struct xlat pollflags[] = {
247 { POLLIN, "POLLIN" },
248 { POLLPRI, "POLLPRI" },
249 { POLLOUT, "POLLOUT" },
251 { POLLRDNORM, "POLLRDNORM" },
254 { POLLWRNORM, "POLLWRNORM" },
257 { POLLRDBAND, "POLLRDBAND" },
260 { POLLWRBAND, "POLLWRBAND" },
262 { POLLERR, "POLLERR" },
263 { POLLHUP, "POLLHUP" },
264 { POLLNVAL, "POLLNVAL" },
270 decode_poll(struct tcb *tcp, long pts)
274 unsigned long size, start, cur, end, abbrev_end;
278 nfds = tcp->u_arg[1];
279 size = sizeof(fds) * nfds;
280 start = tcp->u_arg[0];
282 if (nfds == 0 || size / sizeof(fds) != nfds || end < start) {
283 tprintf("%#lx, %d, ",
284 tcp->u_arg[0], nfds);
288 abbrev_end = start + max_strlen * sizeof(fds);
289 if (abbrev_end < start)
295 for (cur = start; cur < end; cur += sizeof(fds)) {
298 if (cur >= abbrev_end) {
302 if (umoven(tcp, cur, sizeof fds, (char *) &fds) < 0) {
308 tprintf("{fd=%d}", fds.fd);
312 printfd(tcp, fds.fd);
313 tprints(", events=");
314 printflags(pollflags, fds.events, "POLL???");
319 tprintf(" %#lx", start);
320 tprintf(", %d, ", nfds);
323 static char outstr[1024];
325 #define end_outstr (outstr + sizeof(outstr))
330 if (tcp->u_rval == 0) {
331 tcp->auxstr = "Timeout";
335 nfds = tcp->u_arg[1];
336 size = sizeof(fds) * nfds;
337 start = tcp->u_arg[0];
339 if (nfds == 0 || size / sizeof(fds) != nfds || end < start)
342 abbrev_end = start + max_strlen * sizeof(fds);
343 if (abbrev_end < start)
351 for (cur = start; cur < end; cur += sizeof(fds)) {
352 if (umoven(tcp, cur, sizeof fds, (char *) &fds) < 0) {
353 if (outptr < end_outstr - 2)
360 if (outptr == outstr) {
363 if (outptr < end_outstr - 3)
364 outptr = stpcpy(outptr, ", ");
366 if (cur >= abbrev_end) {
367 if (outptr < end_outstr - 4)
368 outptr = stpcpy(outptr, "...");
371 if (outptr < end_outstr - (sizeof("{fd=%d, revents=") + sizeof(int)*3) + 1)
372 outptr += sprintf(outptr, "{fd=%d, revents=", fds.fd);
373 flagstr = sprintflags("", pollflags, fds.revents);
374 if (outptr < end_outstr - (strlen(flagstr) + 2)) {
375 outptr = stpcpy(outptr, flagstr);
382 if (outptr != outstr /* && outptr < end_outstr - 1 (always true)*/)
387 if (outptr < end_outstr - (10 + TIMESPEC_TEXT_BUFSIZE)) {
388 outptr = stpcpy(outptr, outptr == outstr ? "left " : ", left ");
389 sprint_timespec(outptr, tcp, pts);
393 if (outptr == outstr)
396 tcp->auxstr = outstr;
403 sys_poll(struct tcb *tcp)
405 int rc = decode_poll(tcp, 0);
408 if (tcp->u_arg[2] == INFTIM)
412 tprintf("%ld", tcp->u_arg[2]);
418 sys_ppoll(struct tcb *tcp)
420 int rc = decode_poll(tcp, tcp->u_arg[2]);
422 print_timespec(tcp, tcp->u_arg[2]);
424 print_sigset(tcp, tcp->u_arg[3], 0);
425 tprintf(", %lu", tcp->u_arg[4]);
430 #else /* !HAVE_SYS_POLL_H */
432 sys_poll(struct tcb *tcp)