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 #include "xlat/msgflags.h"
61 printstrbuf(struct tcb *tcp, struct strbuf *sbp, int getting)
63 if (sbp->maxlen == -1 && getting)
64 tprints("{maxlen=-1}");
68 tprintf("maxlen=%d, ", sbp->maxlen);
69 tprintf("len=%d, buf=", sbp->len);
70 printstr(tcp, (unsigned long) sbp->buf, sbp->len);
76 printstrbufarg(struct tcb *tcp, long arg, int getting)
82 else if (umove(tcp, arg, &buf) < 0)
85 printstrbuf(tcp, &buf, getting);
90 sys_putmsg(struct tcb *tcp)
96 tprintf("%ld, ", tcp->u_arg[0]);
97 /* control and data */
98 for (i = 1; i < 3; i++)
99 printstrbufarg(tcp, tcp->u_arg[i], 0);
101 printflags(msgflags, tcp->u_arg[3], "RS_???");
107 sys_getmsg(struct tcb *tcp)
113 tprintf("%lu, ", tcp->u_arg[0]);
116 tprintf("%#lx, %#lx, %#lx",
117 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
120 /* control and data */
121 for (i = 1; i < 3; i++)
122 printstrbufarg(tcp, tcp->u_arg[i], 1);
123 /* pointer to flags */
124 if (tcp->u_arg[3] == 0)
126 else if (umove(tcp, tcp->u_arg[3], &flags) < 0)
130 printflags(msgflags, flags, "RS_???");
133 /* decode return value */
134 switch (tcp->u_rval) {
136 tcp->auxstr = "MORECTL";
138 case MORECTL|MOREDATA:
139 tcp->auxstr = "MORECTL|MOREDATA";
142 tcp->auxstr = "MORECTL";
149 return RVAL_HEX | RVAL_STR;
152 # if defined SYS_putpmsg || defined SYS_getpmsg
153 #include "xlat/pmsgflags.h"
156 sys_putpmsg(struct tcb *tcp)
162 tprintf("%ld, ", tcp->u_arg[0]);
163 /* control and data */
164 for (i = 1; i < 3; i++)
165 printstrbufarg(tcp, tcp->u_arg[i], 0);
167 tprintf("%ld, ", tcp->u_arg[3]);
169 printflags(pmsgflags, tcp->u_arg[4], "MSG_???");
176 sys_getpmsg(struct tcb *tcp)
182 tprintf("%lu, ", tcp->u_arg[0]);
185 tprintf("%#lx, %#lx, %#lx, %#lx", tcp->u_arg[1],
186 tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[4]);
189 /* control and data */
190 for (i = 1; i < 3; i++)
191 printstrbufarg(tcp, tcp->u_arg[i], 1);
192 /* pointer to band */
193 printnum_int(tcp, tcp->u_arg[3], "%d");
195 /* pointer to flags */
196 if (tcp->u_arg[4] == 0)
198 else if (umove(tcp, tcp->u_arg[4], &flags) < 0)
202 printflags(pmsgflags, flags, "MSG_???");
205 /* decode return value */
206 switch (tcp->u_rval) {
208 tcp->auxstr = "MORECTL";
210 case MORECTL|MOREDATA:
211 tcp->auxstr = "MORECTL|MOREDATA";
214 tcp->auxstr = "MORECTL";
221 return RVAL_HEX | RVAL_STR;
224 # endif /* getpmsg/putpmsg */
226 #endif /* STREAMS syscalls support */
229 #ifdef HAVE_SYS_POLL_H
231 #include "xlat/pollflags.h"
234 decode_poll(struct tcb *tcp, long pts)
238 unsigned long size, start, cur, end, abbrev_end;
242 nfds = tcp->u_arg[1];
243 size = sizeof(fds) * nfds;
244 start = tcp->u_arg[0];
246 if (nfds == 0 || size / sizeof(fds) != nfds || end < start) {
247 tprintf("%#lx, %d, ",
248 tcp->u_arg[0], nfds);
252 abbrev_end = start + max_strlen * sizeof(fds);
253 if (abbrev_end < start)
259 for (cur = start; cur < end; cur += sizeof(fds)) {
262 if (cur >= abbrev_end) {
266 if (umoven(tcp, cur, sizeof fds, &fds) < 0) {
272 tprintf("{fd=%d}", fds.fd);
276 printfd(tcp, fds.fd);
277 tprints(", events=");
278 printflags(pollflags, fds.events, "POLL???");
283 tprintf(" %#lx", start);
284 tprintf(", %d, ", nfds);
287 static char outstr[1024];
289 #define end_outstr (outstr + sizeof(outstr))
294 if (tcp->u_rval == 0) {
295 tcp->auxstr = "Timeout";
299 nfds = tcp->u_arg[1];
300 size = sizeof(fds) * nfds;
301 start = tcp->u_arg[0];
303 if (nfds == 0 || size / sizeof(fds) != nfds || end < start)
306 abbrev_end = start + max_strlen * sizeof(fds);
307 if (abbrev_end < start)
315 for (cur = start; cur < end; cur += sizeof(fds)) {
316 if (umoven(tcp, cur, sizeof fds, &fds) < 0) {
317 if (outptr < end_outstr - 2)
324 if (outptr == outstr) {
327 if (outptr < end_outstr - 3)
328 outptr = stpcpy(outptr, ", ");
330 if (cur >= abbrev_end) {
331 if (outptr < end_outstr - 4)
332 outptr = stpcpy(outptr, "...");
335 if (outptr < end_outstr - (sizeof("{fd=%d, revents=") + sizeof(int)*3) + 1)
336 outptr += sprintf(outptr, "{fd=%d, revents=", fds.fd);
337 flagstr = sprintflags("", pollflags, fds.revents);
338 if (outptr < end_outstr - (strlen(flagstr) + 2)) {
339 outptr = stpcpy(outptr, flagstr);
346 if (outptr != outstr /* && outptr < end_outstr - 1 (always true)*/)
351 if (outptr < end_outstr - (10 + TIMESPEC_TEXT_BUFSIZE)) {
352 outptr = stpcpy(outptr, outptr == outstr ? "left " : ", left ");
353 sprint_timespec(outptr, tcp, pts);
357 if (outptr == outstr)
360 tcp->auxstr = outstr;
367 sys_poll(struct tcb *tcp)
369 int rc = decode_poll(tcp, 0);
372 if (tcp->u_arg[2] == INFTIM)
376 tprintf("%ld", tcp->u_arg[2]);
382 sys_ppoll(struct tcb *tcp)
384 int rc = decode_poll(tcp, tcp->u_arg[2]);
386 print_timespec(tcp, tcp->u_arg[2]);
388 /* NB: kernel requires arg[4] == NSIG / 8 */
389 print_sigset_addr_len(tcp, tcp->u_arg[3], tcp->u_arg[4]);
390 tprintf(", %lu", tcp->u_arg[4]);
395 #else /* !HAVE_SYS_POLL_H */
397 sys_poll(struct tcb *tcp)