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.
30 #if defined HAVE_POLL_H
32 #elif defined HAVE_SYS_POLL_H
33 # include <sys/poll.h>
35 #ifdef HAVE_SYS_CONF_H
36 # include <sys/conf.h>
39 /* Who has STREAMS syscalls?
40 * Linux hasn't. Solaris has (had?).
41 * Just in case I miss something, retain in for Sparc...
43 #if defined(SPARC) || defined(SPARC64)
45 # ifdef 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 */
58 static const struct xlat msgflags[] = {
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, long 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_???");
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;
155 # if defined SYS_putpmsg || defined SYS_getpmsg
156 static const struct xlat pmsgflags[] = {
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_???");
190 sys_getpmsg(struct tcb *tcp)
196 tprintf("%lu, ", tcp->u_arg[0]);
199 tprintf("%#lx, %#lx, %#lx, %#lx", tcp->u_arg[1],
200 tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[4]);
203 /* control and data */
204 for (i = 1; i < 3; i++)
205 printstrbufarg(tcp, tcp->u_arg[i], 1);
206 /* pointer to band */
207 printnum(tcp, tcp->u_arg[3], "%d");
209 /* pointer to flags */
210 if (tcp->u_arg[4] == 0)
212 else if (umove(tcp, tcp->u_arg[4], &flags) < 0)
216 printflags(pmsgflags, flags, "MSG_???");
219 /* decode return value */
220 switch (tcp->u_rval) {
222 tcp->auxstr = "MORECTL";
224 case MORECTL|MOREDATA:
225 tcp->auxstr = "MORECTL|MOREDATA";
228 tcp->auxstr = "MORECTL";
235 return RVAL_HEX | RVAL_STR;
238 # endif /* getpmsg/putpmsg */
240 #endif /* STREAMS syscalls support */
243 #ifdef HAVE_SYS_POLL_H
245 static const struct xlat pollflags[] = {
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 /* NB: kernel requires arg[4] == NSIG / 8 */
425 print_sigset_addr_len(tcp, tcp->u_arg[3], tcp->u_arg[4]);
426 tprintf(", %lu", tcp->u_arg[4]);
431 #else /* !HAVE_SYS_POLL_H */
433 sys_poll(struct tcb *tcp)