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>
36 #ifdef HAVE_SYS_CONF_H
37 # include <sys/conf.h>
40 /* Who has STREAMS syscalls?
41 * Linux hasn't. Solaris has (had?).
42 * Just in case I miss something, retain in for Sparc...
44 #if defined(SPARC) || defined(SPARC64)
46 # ifdef HAVE_STROPTS_H
51 int maxlen; /* no. of bytes in buffer */
52 int len; /* no. of bytes returned */
53 const char *buf; /* pointer to data */
59 static const struct xlat msgflags[] = {
60 { RS_HIPRI, "RS_HIPRI" },
65 printstrbuf(struct tcb *tcp, struct strbuf *sbp, int getting)
67 if (sbp->maxlen == -1 && getting)
68 tprints("{maxlen=-1}");
72 tprintf("maxlen=%d, ", sbp->maxlen);
73 tprintf("len=%d, buf=", sbp->len);
74 printstr(tcp, (unsigned long) sbp->buf, sbp->len);
80 printstrbufarg(struct tcb *tcp, long arg, int getting)
86 else if (umove(tcp, arg, &buf) < 0)
89 printstrbuf(tcp, &buf, getting);
94 sys_putmsg(struct tcb *tcp)
100 tprintf("%ld, ", tcp->u_arg[0]);
101 /* control and data */
102 for (i = 1; i < 3; i++)
103 printstrbufarg(tcp, tcp->u_arg[i], 0);
105 printflags(msgflags, tcp->u_arg[3], "RS_???");
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;
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" },
171 sys_putpmsg(struct tcb *tcp)
177 tprintf("%ld, ", tcp->u_arg[0]);
178 /* control and data */
179 for (i = 1; i < 3; i++)
180 printstrbufarg(tcp, tcp->u_arg[i], 0);
182 tprintf("%ld, ", tcp->u_arg[3]);
184 printflags(pmsgflags, tcp->u_arg[4], "MSG_???");
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;
239 # endif /* getpmsg/putpmsg */
241 #endif /* STREAMS syscalls support */
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 /* NB: kernel requires arg[4] == NSIG / 8 */
426 print_sigset_addr_len(tcp, tcp->u_arg[3], tcp->u_arg[4]);
427 tprintf(", %lu", tcp->u_arg[4]);
432 #else /* !HAVE_SYS_POLL_H */
434 sys_poll(struct tcb *tcp)