blob: ed965019d4c255dc5c38296cd3be6c5f87c03d0b [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00003 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00004 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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.
16 *
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.
27 *
28 * $Id$
29 */
30
31#include "defs.h"
Roland McGrath34e014a2002-12-16 20:40:59 +000032#include <sys/syscall.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000033
Wichert Akkerman42080d82001-04-10 10:32:26 +000034#ifdef HAVE_POLL_H
35#include <poll.h>
36#endif
Pavel Machek245a6ac2000-02-01 16:12:33 +000037#ifdef HAVE_SYS_POLL_H
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000038#include <sys/poll.h>
Pavel Machek245a6ac2000-02-01 16:12:33 +000039#endif
Wichert Akkerman42080d82001-04-10 10:32:26 +000040#ifdef HAVE_STROPTS_H
41#include <stropts.h>
42#endif
43#ifdef HAVE_SYS_CONF_H
44#include <sys/conf.h>
45#endif
46#ifdef HAVE_SYS_STREAM_H
47#include <sys/stream.h>
48#endif
49#ifdef HAVE_SYS_TIHDR_H
50#include <sys/tihdr.h>
51#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000052
Roland McGrath561c7992003-04-02 01:10:44 +000053#if defined(HAVE_SYS_STREAM_H) || defined(LINUX) || defined(FREEBSD)
Wichert Akkerman42080d82001-04-10 10:32:26 +000054
55#ifndef HAVE_STROPTS_H
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000056#define RS_HIPRI 1
57struct strbuf {
Denys Vlasenkoadedb512008-12-30 18:47:55 +000058 int maxlen; /* no. of bytes in buffer */
59 int len; /* no. of bytes returned */
Dmitry V. Levin30145dd2010-09-06 22:08:24 +000060 const char *buf; /* pointer to data */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000061};
62#define MORECTL 1
63#define MOREDATA 2
Wichert Akkerman42080d82001-04-10 10:32:26 +000064#endif /* !HAVE_STROPTS_H */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000065
66#ifdef HAVE_SYS_TIUSER_H
67#include <sys/tiuser.h>
68#include <sys/sockmod.h>
69#include <sys/timod.h>
70#endif /* HAVE_SYS_TIUSER_H */
71
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000072#ifndef FREEBSD
Roland McGrathd9f816f2004-09-04 03:39:20 +000073static const struct xlat msgflags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000074 { RS_HIPRI, "RS_HIPRI" },
75 { 0, NULL },
76};
77
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000078
79static void
Denys Vlasenko12014262011-05-30 14:00:14 +020080printstrbuf(struct tcb *tcp, struct strbuf *sbp, int getting)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000081{
82 if (sbp->maxlen == -1 && getting)
83 tprintf("{maxlen=-1}");
84 else {
85 tprintf("{");
86 if (getting)
87 tprintf("maxlen=%d, ", sbp->maxlen);
88 tprintf("len=%d, buf=", sbp->len);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000089 printstr(tcp, (unsigned long) sbp->buf, sbp->len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000090 tprintf("}");
91 }
92}
93
94static void
Denys Vlasenko12014262011-05-30 14:00:14 +020095printstrbufarg(struct tcb *tcp, int arg, int getting)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000096{
97 struct strbuf buf;
98
99 if (arg == 0)
100 tprintf("NULL");
101 else if (umove(tcp, arg, &buf) < 0)
102 tprintf("{...}");
103 else
104 printstrbuf(tcp, &buf, getting);
105 tprintf(", ");
106}
107
108int
Denys Vlasenko12014262011-05-30 14:00:14 +0200109sys_putmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000110{
111 int i;
112
113 if (entering(tcp)) {
114 /* fd */
115 tprintf("%ld, ", tcp->u_arg[0]);
116 /* control and data */
117 for (i = 1; i < 3; i++)
118 printstrbufarg(tcp, tcp->u_arg[i], 0);
119 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000120 printflags(msgflags, tcp->u_arg[3], "RS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000121 }
122 return 0;
123}
124
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000125#if defined(SPARC) || defined(SPARC64) || defined(SUNOS4) || defined(SVR4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000126int
Denys Vlasenko12014262011-05-30 14:00:14 +0200127sys_getmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000128{
129 int i, flags;
130
131 if (entering(tcp)) {
132 /* fd */
133 tprintf("%lu, ", tcp->u_arg[0]);
134 } else {
135 if (syserror(tcp)) {
136 tprintf("%#lx, %#lx, %#lx",
137 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
138 return 0;
139 }
140 /* control and data */
141 for (i = 1; i < 3; i++)
142 printstrbufarg(tcp, tcp->u_arg[i], 1);
143 /* pointer to flags */
144 if (tcp->u_arg[3] == 0)
145 tprintf("NULL");
146 else if (umove(tcp, tcp->u_arg[3], &flags) < 0)
147 tprintf("[?]");
148 else {
149 tprintf("[");
Roland McGrathb2dee132005-06-01 19:02:36 +0000150 printflags(msgflags, flags, "RS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000151 tprintf("]");
152 }
153 /* decode return value */
154 switch (tcp->u_rval) {
155 case MORECTL:
156 tcp->auxstr = "MORECTL";
157 break;
158 case MORECTL|MOREDATA:
159 tcp->auxstr = "MORECTL|MOREDATA";
160 break;
161 case MOREDATA:
162 tcp->auxstr = "MORECTL";
163 break;
164 default:
165 tcp->auxstr = NULL;
166 break;
167 }
168 }
169 return RVAL_HEX | RVAL_STR;
170}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000171#endif /* SPARC || SPARC64 || SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000172
Roland McGrath34e014a2002-12-16 20:40:59 +0000173#if defined SYS_putpmsg || defined SYS_getpmsg
Roland McGrathd9f816f2004-09-04 03:39:20 +0000174static const struct xlat pmsgflags[] = {
Wichert Akkermand856b992000-10-13 12:47:12 +0000175#ifdef MSG_HIPRI
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000176 { MSG_HIPRI, "MSG_HIPRI" },
Wichert Akkermand856b992000-10-13 12:47:12 +0000177#endif
178#ifdef MSG_AND
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000179 { MSG_ANY, "MSG_ANY" },
Wichert Akkermand856b992000-10-13 12:47:12 +0000180#endif
181#ifdef MSG_BAND
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000182 { MSG_BAND, "MSG_BAND" },
Wichert Akkermand856b992000-10-13 12:47:12 +0000183#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000184 { 0, NULL },
185};
Roland McGrath34e014a2002-12-16 20:40:59 +0000186#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000187
Roland McGrath34e014a2002-12-16 20:40:59 +0000188#ifdef SYS_putpmsg
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000189int
Denys Vlasenko12014262011-05-30 14:00:14 +0200190sys_putpmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000191{
192 int i;
193
194 if (entering(tcp)) {
195 /* fd */
196 tprintf("%ld, ", tcp->u_arg[0]);
197 /* control and data */
198 for (i = 1; i < 3; i++)
199 printstrbufarg(tcp, tcp->u_arg[i], 0);
200 /* band */
201 tprintf("%ld, ", tcp->u_arg[3]);
202 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000203 printflags(pmsgflags, tcp->u_arg[4], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000204 }
205 return 0;
206}
Roland McGrath34e014a2002-12-16 20:40:59 +0000207#endif /* SYS_putpmsg */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000208
Roland McGrath34e014a2002-12-16 20:40:59 +0000209#ifdef SYS_getpmsg
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000210int
Denys Vlasenko12014262011-05-30 14:00:14 +0200211sys_getpmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000212{
213 int i, flags;
214
215 if (entering(tcp)) {
216 /* fd */
217 tprintf("%lu, ", tcp->u_arg[0]);
218 } else {
219 if (syserror(tcp)) {
220 tprintf("%#lx, %#lx, %#lx, %#lx", tcp->u_arg[1],
221 tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[4]);
222 return 0;
223 }
224 /* control and data */
225 for (i = 1; i < 3; i++)
226 printstrbufarg(tcp, tcp->u_arg[i], 1);
227 /* pointer to band */
228 printnum(tcp, tcp->u_arg[3], "%d");
Wichert Akkerman906dade1999-11-26 09:18:37 +0000229 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000230 /* pointer to flags */
231 if (tcp->u_arg[4] == 0)
232 tprintf("NULL");
233 else if (umove(tcp, tcp->u_arg[4], &flags) < 0)
234 tprintf("[?]");
235 else {
236 tprintf("[");
Roland McGrathb2dee132005-06-01 19:02:36 +0000237 printflags(pmsgflags, flags, "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000238 tprintf("]");
239 }
240 /* decode return value */
241 switch (tcp->u_rval) {
242 case MORECTL:
243 tcp->auxstr = "MORECTL";
244 break;
245 case MORECTL|MOREDATA:
246 tcp->auxstr = "MORECTL|MOREDATA";
247 break;
248 case MOREDATA:
249 tcp->auxstr = "MORECTL";
250 break;
251 default:
252 tcp->auxstr = NULL;
253 break;
254 }
255 }
256 return RVAL_HEX | RVAL_STR;
257}
Roland McGrath34e014a2002-12-16 20:40:59 +0000258#endif /* SYS_getpmsg */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000259
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000260#endif /* !FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000261
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000262
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000263#ifdef HAVE_SYS_POLL_H
264
Roland McGrathd9f816f2004-09-04 03:39:20 +0000265static const struct xlat pollflags[] = {
Pavel Machek245a6ac2000-02-01 16:12:33 +0000266#ifdef POLLIN
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000267 { POLLIN, "POLLIN" },
268 { POLLPRI, "POLLPRI" },
269 { POLLOUT, "POLLOUT" },
270#ifdef POLLRDNORM
271 { POLLRDNORM, "POLLRDNORM" },
272#endif
273#ifdef POLLWRNORM
274 { POLLWRNORM, "POLLWRNORM" },
275#endif
276#ifdef POLLRDBAND
277 { POLLRDBAND, "POLLRDBAND" },
278#endif
279#ifdef POLLWRBAND
280 { POLLWRBAND, "POLLWRBAND" },
281#endif
282 { POLLERR, "POLLERR" },
283 { POLLHUP, "POLLHUP" },
284 { POLLNVAL, "POLLNVAL" },
Pavel Machek245a6ac2000-02-01 16:12:33 +0000285#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000286 { 0, NULL },
287};
288
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000289static int
Roland McGrathf17106e2007-11-01 21:49:49 +0000290decode_poll(struct tcb *tcp, long pts)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000291{
Roland McGrathaa524c82005-06-01 19:22:06 +0000292 struct pollfd fds;
293 unsigned nfds;
294 unsigned long size, start, cur, end, abbrev_end;
295 int failed = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000296
Roland McGrathf17106e2007-11-01 21:49:49 +0000297 if (entering(tcp)) {
298 nfds = tcp->u_arg[1];
299 size = sizeof(fds) * nfds;
300 start = tcp->u_arg[0];
301 end = start + size;
302 if (nfds == 0 || size / sizeof(fds) != nfds || end < start) {
303 tprintf("%#lx, %d, ",
304 tcp->u_arg[0], nfds);
305 return 0;
306 }
307 if (abbrev(tcp)) {
308 abbrev_end = start + max_strlen * sizeof(fds);
309 if (abbrev_end < start)
310 abbrev_end = end;
311 } else {
Roland McGrathaa524c82005-06-01 19:22:06 +0000312 abbrev_end = end;
Roland McGrathf17106e2007-11-01 21:49:49 +0000313 }
314 tprintf("[");
315 for (cur = start; cur < end; cur += sizeof(fds)) {
316 if (cur > start)
317 tprintf(", ");
318 if (cur >= abbrev_end) {
319 tprintf("...");
320 break;
321 }
322 if (umoven(tcp, cur, sizeof fds, (char *) &fds) < 0) {
323 tprintf("?");
324 failed = 1;
325 break;
326 }
327 if (fds.fd < 0) {
328 tprintf("{fd=%d}", fds.fd);
329 continue;
330 }
Dmitry V. Levin31382132011-03-04 05:08:02 +0300331 tprintf("{fd=");
332 printfd(tcp, fds.fd);
333 tprintf(", events=");
Roland McGrathf17106e2007-11-01 21:49:49 +0000334 printflags(pollflags, fds.events, "POLL???");
335 tprintf("}");
336 }
337 tprintf("]");
338 if (failed)
339 tprintf(" %#lx", start);
340 tprintf(", %d, ", nfds);
341 return 0;
Roland McGrathaa524c82005-06-01 19:22:06 +0000342 } else {
Roland McGrathf17106e2007-11-01 21:49:49 +0000343 static char outstr[1024];
344 char str[64];
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000345 const char *flagstr;
Roland McGrathf17106e2007-11-01 21:49:49 +0000346 unsigned int cumlen;
347
348 if (syserror(tcp))
349 return 0;
350 if (tcp->u_rval == 0) {
351 tcp->auxstr = "Timeout";
352 return RVAL_STR;
353 }
354
355 nfds = tcp->u_arg[1];
356 size = sizeof(fds) * nfds;
357 start = tcp->u_arg[0];
358 end = start + size;
359 if (nfds == 0 || size / sizeof(fds) != nfds || end < start)
360 return 0;
361 if (abbrev(tcp)) {
362 abbrev_end = start + max_strlen * sizeof(fds);
363 if (abbrev_end < start)
364 abbrev_end = end;
365 } else {
366 abbrev_end = end;
367 }
368
369 outstr[0] = '\0';
370 cumlen = 0;
371
372 for (cur = start; cur < end; cur += sizeof(fds)) {
373 if (umoven(tcp, cur, sizeof fds, (char *) &fds) < 0) {
374 ++cumlen;
375 if (cumlen < sizeof(outstr))
376 strcat(outstr, "?");
377 failed = 1;
378 break;
379 }
380 if (!fds.revents)
381 continue;
382 if (!cumlen) {
383 ++cumlen;
384 strcat(outstr, "[");
385 } else {
386 cumlen += 2;
387 if (cumlen < sizeof(outstr))
388 strcat(outstr, ", ");
389 }
390 if (cur >= abbrev_end) {
391 cumlen += 3;
392 if (cumlen < sizeof(outstr))
393 strcat(outstr, "...");
394 break;
395 }
396 sprintf(str, "{fd=%d, revents=", fds.fd);
397 flagstr=sprintflags("", pollflags, fds.revents);
398 cumlen += strlen(str) + strlen(flagstr) + 1;
399 if (cumlen < sizeof(outstr)) {
400 strcat(outstr, str);
401 strcat(outstr, flagstr);
402 strcat(outstr, "}");
403 }
404 }
405 if (failed)
406 return 0;
407
408 if (cumlen && ++cumlen < sizeof(outstr))
409 strcat(outstr, "]");
410
411 if (pts) {
Roland McGrathf17106e2007-11-01 21:49:49 +0000412 char str[128];
413
414 sprintf(str, "%sleft ", cumlen ? ", " : "");
Roland McGrath6bc09da2007-11-01 21:50:54 +0000415 sprint_timespec(str + strlen(str), tcp, pts);
Roland McGrathf17106e2007-11-01 21:49:49 +0000416 if ((cumlen += strlen(str)) < sizeof(outstr))
417 strcat(outstr, str);
418 }
419
420 if (!outstr[0])
421 return 0;
422
423 tcp->auxstr = outstr;
424 return RVAL_STR;
Roland McGrathaa524c82005-06-01 19:22:06 +0000425 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000426}
427
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000428int
429sys_poll(struct tcb *tcp)
430{
Roland McGrathf17106e2007-11-01 21:49:49 +0000431 int rc = decode_poll(tcp, 0);
432 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000433#ifdef INFTIM
434 if (tcp->u_arg[2] == INFTIM)
435 tprintf("INFTIM");
436 else
437#endif
438 tprintf("%ld", tcp->u_arg[2]);
439 }
440 return rc;
441}
442
443#ifdef LINUX
444int
445sys_ppoll(struct tcb *tcp)
446{
Roland McGrathf17106e2007-11-01 21:49:49 +0000447 int rc = decode_poll(tcp, tcp->u_arg[2]);
448 if (entering(tcp)) {
Roland McGrath6bc09da2007-11-01 21:50:54 +0000449 print_timespec(tcp, tcp->u_arg[2]);
450 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000451 print_sigset(tcp, tcp->u_arg[3], 0);
452 tprintf(", %lu", tcp->u_arg[4]);
453 }
454 return rc;
455}
456#endif
Roland McGrathaa524c82005-06-01 19:22:06 +0000457
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000458#else /* !HAVE_SYS_POLL_H */
459int
Denys Vlasenko12014262011-05-30 14:00:14 +0200460sys_poll(struct tcb *tcp)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000461{
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000462 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000463}
464#endif
465
Roland McGrath561c7992003-04-02 01:10:44 +0000466#if !defined(LINUX) && !defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000467
Roland McGrathd9f816f2004-09-04 03:39:20 +0000468static const struct xlat stream_flush_options[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000469 { FLUSHR, "FLUSHR" },
470 { FLUSHW, "FLUSHW" },
471 { FLUSHRW, "FLUSHRW" },
472#ifdef FLUSHBAND
473 { FLUSHBAND, "FLUSHBAND" },
474#endif
475 { 0, NULL },
476};
477
Roland McGrathd9f816f2004-09-04 03:39:20 +0000478static const struct xlat stream_setsig_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000479 { S_INPUT, "S_INPUT" },
480 { S_HIPRI, "S_HIPRI" },
481 { S_OUTPUT, "S_OUTPUT" },
482 { S_MSG, "S_MSG" },
483#ifdef S_ERROR
484 { S_ERROR, "S_ERROR" },
485#endif
486#ifdef S_HANGUP
487 { S_HANGUP, "S_HANGUP" },
488#endif
489#ifdef S_RDNORM
490 { S_RDNORM, "S_RDNORM" },
491#endif
492#ifdef S_WRNORM
493 { S_WRNORM, "S_WRNORM" },
494#endif
495#ifdef S_RDBAND
496 { S_RDBAND, "S_RDBAND" },
497#endif
498#ifdef S_WRBAND
499 { S_WRBAND, "S_WRBAND" },
500#endif
501#ifdef S_BANDURG
502 { S_BANDURG, "S_BANDURG" },
503#endif
504 { 0, NULL },
505};
506
Roland McGrathd9f816f2004-09-04 03:39:20 +0000507static const struct xlat stream_read_options[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000508 { RNORM, "RNORM" },
509 { RMSGD, "RMSGD" },
510 { RMSGN, "RMSGN" },
511 { 0, NULL },
512};
513
Roland McGrathd9f816f2004-09-04 03:39:20 +0000514static const struct xlat stream_read_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000515#ifdef RPROTDAT
516 { RPROTDAT, "RPROTDAT" },
517#endif
518#ifdef RPROTDIS
519 { RPROTDIS, "RPROTDIS" },
520#endif
521#ifdef RPROTNORM
522 { RPROTNORM, "RPROTNORM" },
523#endif
524 { 0, NULL },
525};
526
527#ifndef RMODEMASK
528#define RMODEMASK (~0)
529#endif
530
531#ifdef I_SWROPT
Roland McGrathd9f816f2004-09-04 03:39:20 +0000532static const struct xlat stream_write_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000533 { SNDZERO, "SNDZERO" },
534 { SNDPIPE, "SNDPIPE" },
535 { 0, NULL },
536};
537#endif /* I_SWROPT */
538
539#ifdef I_ATMARK
Roland McGrathd9f816f2004-09-04 03:39:20 +0000540static const struct xlat stream_atmark_options[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000541 { ANYMARK, "ANYMARK" },
542 { LASTMARK, "LASTMARK" },
543 { 0, NULL },
544};
545#endif /* I_ATMARK */
546
547#ifdef TI_BIND
Roland McGrathd9f816f2004-09-04 03:39:20 +0000548static const struct xlat transport_user_options[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000549 { T_CONN_REQ, "T_CONN_REQ" },
550 { T_CONN_RES, "T_CONN_RES" },
551 { T_DISCON_REQ, "T_DISCON_REQ" },
552 { T_DATA_REQ, "T_DATA_REQ" },
553 { T_EXDATA_REQ, "T_EXDATA_REQ" },
554 { T_INFO_REQ, "T_INFO_REQ" },
555 { T_BIND_REQ, "T_BIND_REQ" },
556 { T_UNBIND_REQ, "T_UNBIND_REQ" },
557 { T_UNITDATA_REQ,"T_UNITDATA_REQ"},
558 { T_OPTMGMT_REQ,"T_OPTMGMT_REQ" },
559 { T_ORDREL_REQ, "T_ORDREL_REQ" },
560 { 0, NULL },
561};
562
Roland McGrathd9f816f2004-09-04 03:39:20 +0000563static const struct xlat transport_user_flags [] = {
John Hughes38ae88d2002-05-23 11:48:58 +0000564 { 0, "0" },
565 { T_MORE, "T_MORE" },
566 { T_EXPEDITED, "T_EXPEDITED" },
567 { T_NEGOTIATE, "T_NEGOTIATE" },
568 { T_CHECK, "T_CHECK" },
569 { T_DEFAULT, "T_DEFAULT" },
570 { T_SUCCESS, "T_SUCCESS" },
571 { T_FAILURE, "T_FAILURE" },
572 { T_CURRENT, "T_CURRENT" },
573 { T_PARTSUCCESS,"T_PARTSUCCESS" },
574 { T_READONLY, "T_READONLY" },
575 { T_NOTSUPPORT, "T_NOTSUPPORT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000576 { 0, NULL },
577};
John Hughes38ae88d2002-05-23 11:48:58 +0000578
579
Roland McGrath6d2b3492002-12-30 00:51:30 +0000580#ifdef HAVE_STRUCT_T_OPTHDR
John Hughes38ae88d2002-05-23 11:48:58 +0000581
Roland McGrathd9f816f2004-09-04 03:39:20 +0000582static const struct xlat xti_level [] = {
John Hughes38ae88d2002-05-23 11:48:58 +0000583 { XTI_GENERIC, "XTI_GENERIC" },
584 { 0, NULL },
585};
586
Roland McGrathd9f816f2004-09-04 03:39:20 +0000587static const struct xlat xti_generic [] = {
John Hughes38ae88d2002-05-23 11:48:58 +0000588 { XTI_DEBUG, "XTI_DEBUG" },
589 { XTI_LINGER, "XTI_LINGER" },
590 { XTI_RCVBUF, "XTI_RCVBUF" },
591 { XTI_RCVLOWAT, "XTI_RCVLOWAT" },
592 { XTI_SNDBUF, "XTI_SNDBUF" },
593 { XTI_SNDLOWAT, "XTI_SNDLOWAT" },
594 { 0, NULL },
595};
596
597
598
599void
Denys Vlasenko12014262011-05-30 14:00:14 +0200600print_xti_optmgmt(struct tcb *tcp, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +0000601{
602 int c = 0;
603 struct t_opthdr hdr;
604
John Hughes2c4e3a82002-05-24 10:19:44 +0000605 while (len >= (int) sizeof hdr) {
John Hughes38ae88d2002-05-23 11:48:58 +0000606 if (umove(tcp, addr, &hdr) < 0) break;
607 if (c++) {
608 tprintf (", ");
609 }
610 else if (len > hdr.len + sizeof hdr) {
611 tprintf ("[");
612 }
613 tprintf ("{level=");
614 printxval (xti_level, hdr.level, "???");
615 tprintf (", name=");
616 switch (hdr.level) {
617 case XTI_GENERIC:
618 printxval (xti_generic, hdr.name, "XTI_???");
619 break;
620 default:
621 tprintf ("%ld", hdr.name);
622 break;
623 }
624 tprintf (", status=");
625 printxval (transport_user_flags, hdr.status, "T_???");
626 addr += sizeof hdr;
627 len -= sizeof hdr;
628 if ((hdr.len -= sizeof hdr) > 0) {
629 if (hdr.len > len) break;
630 tprintf (", val=");
631 if (len == sizeof (int))
632 printnum (tcp, addr, "%d");
633 else
634 printstr (tcp, addr, hdr.len);
635 addr += hdr.len;
636 len -= hdr.len;
637 }
638 tprintf ("}");
639 }
640 if (len > 0) {
641 if (c++) tprintf (", ");
642 printstr (tcp, addr, len);
643 }
644 if (c > 1) tprintf ("]");
645}
646
647#endif
648
649
650static void
Denys Vlasenko12014262011-05-30 14:00:14 +0200651print_optmgmt(struct tcb *tcp, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +0000652{
Roland McGrath34e014a2002-12-16 20:40:59 +0000653 /* We don't know how to tell if TLI (socket) or XTI
John Hughes38ae88d2002-05-23 11:48:58 +0000654 optmgmt is being used yet, assume TLI. */
Roland McGrath6d2b3492002-12-30 00:51:30 +0000655#if defined (HAVE_STRUCT_OPTHDR)
John Hughes38ae88d2002-05-23 11:48:58 +0000656 print_sock_optmgmt (tcp, addr, len);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000657#elif defined (HAVE_STRUCT_T_OPTHDR)
John Hughes38ae88d2002-05-23 11:48:58 +0000658 print_xti_optmgmt (tcp, addr, len);
659#else
660 printstr (tcp, addr, len);
661#endif
662}
663
664
665
666
Roland McGrathd9f816f2004-09-04 03:39:20 +0000667static const struct xlat service_type [] = {
John Hughes38ae88d2002-05-23 11:48:58 +0000668 { T_COTS, "T_COTS" },
669 { T_COTS_ORD, "T_COTS_ORD" },
670 { T_CLTS, "T_CLTS" },
671 { 0, NULL },
672};
673
Roland McGrathd9f816f2004-09-04 03:39:20 +0000674static const struct xlat ts_state [] = {
John Hughes38ae88d2002-05-23 11:48:58 +0000675 { TS_UNBND, "TS_UNBND" },
676 { TS_WACK_BREQ, "TS_WACK_BREQ" },
677 { TS_WACK_UREQ, "TS_WACK_UREQ" },
678 { TS_IDLE, "TS_IDLE" },
679 { TS_WACK_OPTREQ,"TS_WACK_OPTREQ"},
680 { TS_WACK_CREQ, "TS_WACK_CREQ" },
681 { TS_WCON_CREQ, "TS_WCON_CREQ" },
682 { TS_WRES_CIND, "TS_WRES_CIND" },
683 { TS_WACK_CRES, "TS_WACK_CRES" },
684 { TS_DATA_XFER, "TS_DATA_XFER" },
685 { TS_WIND_ORDREL,"TS_WIND_ORDREL"},
686 { TS_WREQ_ORDREL,"TS_WREQ_ORDREL"},
687 { TS_WACK_DREQ6,"TS_WACK_DREQ6" },
688 { TS_WACK_DREQ7,"TS_WACK_DREQ7" },
689 { TS_WACK_DREQ9,"TS_WACK_DREQ9" },
690 { TS_WACK_DREQ10,"TS_WACK_DREQ10"},
691 { TS_WACK_DREQ11,"TS_WACK_DREQ11"},
692 { 0, NULL },
693};
694
Roland McGrathd9f816f2004-09-04 03:39:20 +0000695static const struct xlat provider_flags [] = {
John Hughes38ae88d2002-05-23 11:48:58 +0000696 { 0, "0" },
697 { SENDZERO, "SENDZERO" },
698 { EXPINLINE, "EXPINLINE" },
699 { XPG4_1, "XPG4_1" },
700 { 0, NULL },
701};
702
703
Roland McGrathd9f816f2004-09-04 03:39:20 +0000704static const struct xlat tli_errors [] = {
John Hughes38ae88d2002-05-23 11:48:58 +0000705 { TBADADDR, "TBADADDR" },
706 { TBADOPT, "TBADOPT" },
707 { TACCES, "TACCES" },
708 { TBADF, "TBADF" },
709 { TNOADDR, "TNOADDR" },
710 { TOUTSTATE, "TOUTSTATE" },
711 { TBADSEQ, "TBADSEQ" },
712 { TSYSERR, "TSYSERR" },
713 { TLOOK, "TLOOK" },
714 { TBADDATA, "TBADDATA" },
715 { TBUFOVFLW, "TBUFOVFLW" },
716 { TFLOW, "TFLOW" },
717 { TNODATA, "TNODATA" },
718 { TNODIS, "TNODIS" },
719 { TNOUDERR, "TNOUDERR" },
720 { TBADFLAG, "TBADFLAG" },
721 { TNOREL, "TNOREL" },
722 { TNOTSUPPORT, "TNOTSUPPORT" },
723 { TSTATECHNG, "TSTATECHNG" },
724 { TNOSTRUCTYPE, "TNOSTRUCTYPE" },
725 { TBADNAME, "TBADNAME" },
726 { TBADQLEN, "TBADQLEN" },
727 { TADDRBUSY, "TADDRBUSY" },
728 { TINDOUT, "TINDOUT" },
729 { TPROVMISMATCH,"TPROVMISMATCH" },
730 { TRESQLEN, "TRESQLEN" },
731 { TRESADDR, "TRESADDR" },
732 { TQFULL, "TQFULL" },
733 { TPROTO, "TPROTO" },
734 { 0, NULL },
735};
736
737
738static int
Denys Vlasenko12014262011-05-30 14:00:14 +0200739print_transport_message(struct tcb *tcp, int expect, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +0000740{
741 union T_primitives m;
742 int c = 0;
743
744 if (len < sizeof m.type) goto dump;
745
746 if (umove (tcp, addr, &m.type) < 0) goto dump;
747
748#define GET(type, struct) \
749 do { \
750 if (len < sizeof m.struct) goto dump; \
751 if (umove (tcp, addr, &m.struct) < 0) goto dump;\
752 tprintf ("{"); \
753 if (expect != type) { \
754 ++c; \
755 tprintf (#type); \
756 } \
757 } \
758 while (0)
759
760#define COMMA() \
Roland McGrath34e014a2002-12-16 20:40:59 +0000761 do { if (c++) tprintf (", "); } while (0)
762
John Hughes38ae88d2002-05-23 11:48:58 +0000763
764#define STRUCT(struct, elem, print) \
765 do { \
766 COMMA (); \
767 if (m.struct.elem##_length < 0 || \
768 m.struct.elem##_offset < sizeof m.struct || \
769 m.struct.elem##_offset + m.struct.elem##_length > len) \
770 { \
771 tprintf (#elem "_length=%ld, " #elem "_offset=%ld",\
772 m.struct.elem##_length, \
773 m.struct.elem##_offset); \
774 } \
775 else { \
776 tprintf (#elem "="); \
777 print (tcp, \
778 addr + m.struct.elem##_offset, \
779 m.struct.elem##_length); \
780 } \
781 } \
782 while (0)
783
784#define ADDR(struct, elem) STRUCT (struct, elem, printstr)
Roland McGrath34e014a2002-12-16 20:40:59 +0000785
John Hughes38ae88d2002-05-23 11:48:58 +0000786 switch (m.type) {
787#ifdef T_CONN_REQ
788 case T_CONN_REQ: /* connect request */
789 GET (T_CONN_REQ, conn_req);
790 ADDR (conn_req, DEST);
791 ADDR (conn_req, OPT);
792 break;
793#endif
794#ifdef T_CONN_RES
795 case T_CONN_RES: /* connect response */
796 GET (T_CONN_RES, conn_res);
Roland McGrath38dc6bb2003-01-10 20:05:54 +0000797#ifdef HAVE_STRUCT_T_CONN_RES_QUEUE_PTR
John Hughes38ae88d2002-05-23 11:48:58 +0000798 COMMA ();
799 tprintf ("QUEUE=%p", m.conn_res.QUEUE_ptr);
Roland McGrath38dc6bb2003-01-10 20:05:54 +0000800#elif defined HAVE_STRUCT_T_CONN_RES_ACCEPTOR_ID
801 COMMA ();
Roland McGrath7686eee2003-01-10 20:09:43 +0000802 tprintf ("ACCEPTOR=%#lx", m.conn_res.ACCEPTOR_id);
Roland McGrath38dc6bb2003-01-10 20:05:54 +0000803#endif
John Hughes38ae88d2002-05-23 11:48:58 +0000804 ADDR (conn_res, OPT);
805 COMMA ();
806 tprintf ("SEQ=%ld", m.conn_res.SEQ_number);
807 break;
808#endif
809#ifdef T_DISCON_REQ
810 case T_DISCON_REQ: /* disconnect request */
811 GET (T_DISCON_REQ, discon_req);
812 COMMA ();
813 tprintf ("SEQ=%ld", m.discon_req.SEQ_number);
814 break;
815#endif
816#ifdef T_DATA_REQ
817 case T_DATA_REQ: /* data request */
818 GET (T_DATA_REQ, data_req);
819 COMMA ();
820 tprintf ("MORE=%ld", m.data_req.MORE_flag);
821 break;
822#endif
823#ifdef T_EXDATA_REQ
824 case T_EXDATA_REQ: /* expedited data req */
825 GET (T_EXDATA_REQ, exdata_req);
826 COMMA ();
827 tprintf ("MORE=%ld", m.exdata_req.MORE_flag);
828 break;
829#endif
830#ifdef T_INFO_REQ
831 case T_INFO_REQ: /* information req */
832 GET (T_INFO_REQ, info_req);
833 break;
834#endif
835#ifdef T_BIND_REQ
836 case T_BIND_REQ: /* bind request */
837#ifdef O_T_BIND_REQ
838 case O_T_BIND_REQ: /* Ugly xti/tli hack */
839#endif
840 GET (T_BIND_REQ, bind_req);
841 ADDR (bind_req, ADDR);
842 COMMA ();
843 tprintf ("CONIND=%ld", m.bind_req.CONIND_number);
844 break;
845#endif
846#ifdef T_UNBIND_REQ
847 case T_UNBIND_REQ: /* unbind request */
848 GET (T_UNBIND_REQ, unbind_req);
849 break;
850#endif
851#ifdef T_UNITDATA_REQ
852 case T_UNITDATA_REQ: /* unitdata requset */
853 GET (T_UNITDATA_REQ, unitdata_req);
854 ADDR (unitdata_req, DEST);
855 ADDR (unitdata_req, OPT);
856 break;
857#endif
858#ifdef T_OPTMGMT_REQ
859 case T_OPTMGMT_REQ: /* manage opt req */
860 GET (T_OPTMGMT_REQ, optmgmt_req);
861 COMMA ();
862 tprintf ("MGMT=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000863 printflags (transport_user_flags, m.optmgmt_req.MGMT_flags,
864 "T_???");
John Hughes38ae88d2002-05-23 11:48:58 +0000865 STRUCT (optmgmt_req, OPT, print_optmgmt);
866 break;
867#endif
868#ifdef T_ORDREL_REQ
869 case T_ORDREL_REQ: /* orderly rel req */
870 GET (T_ORDREL_REQ, ordrel_req);
871 break;
872#endif
873#ifdef T_CONN_IND
874 case T_CONN_IND: /* connect indication */
875 GET (T_CONN_IND, conn_ind);
876 ADDR (conn_ind, SRC);
877 ADDR (conn_ind, OPT);
878 tprintf (", SEQ=%ld", m.conn_ind.SEQ_number);
879 break;
880#endif
881#ifdef T_CONN_CON
882 case T_CONN_CON: /* connect corfirm */
883 GET (T_CONN_CON, conn_con);
884 ADDR (conn_con, RES);
885 ADDR (conn_con, OPT);
886 break;
887#endif
888#ifdef T_DISCON_IND
889 case T_DISCON_IND: /* discon indication */
890 GET (T_DISCON_IND, discon_ind);
891 COMMA ();
892 tprintf ("DISCON=%ld, SEQ=%ld",
893 m.discon_ind.DISCON_reason, m.discon_ind.SEQ_number);
894 break;
895#endif
896#ifdef T_DATA_IND
897 case T_DATA_IND: /* data indication */
898 GET (T_DATA_IND, data_ind);
899 COMMA ();
900 tprintf ("MORE=%ld", m.data_ind.MORE_flag);
901 break;
902#endif
903#ifdef T_EXDATA_IND
904 case T_EXDATA_IND: /* expedited data ind */
905 GET (T_EXDATA_IND, exdata_ind);
906 COMMA ();
907 tprintf ("MORE=%ld", m.exdata_ind.MORE_flag);
908 break;
909#endif
910#ifdef T_INFO_ACK
911 case T_INFO_ACK: /* info ack */
912 GET (T_INFO_ACK, info_ack);
913 COMMA ();
914 tprintf ("TSDU=%ld, ETSDU=%ld, CDATA=%ld, DDATA=%ld, "
915 "ADDR=%ld, OPT=%ld, TIDU=%ld, SERV=",
916 m.info_ack.TSDU_size, m.info_ack.ETSDU_size,
917 m.info_ack.CDATA_size, m.info_ack.DDATA_size,
918 m.info_ack.ADDR_size, m.info_ack.OPT_size,
919 m.info_ack.TIDU_size);
920 printxval (service_type, m.info_ack.SERV_type, "T_???");
921 tprintf (", CURRENT=");
922 printxval (ts_state, m.info_ack.CURRENT_state, "TS_???");
923 tprintf (", PROVIDER=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000924 printflags (provider_flags, m.info_ack.PROVIDER_flag, "???");
John Hughes38ae88d2002-05-23 11:48:58 +0000925 break;
926#endif
927#ifdef T_BIND_ACK
928 case T_BIND_ACK: /* bind ack */
929 GET (T_BIND_ACK, bind_ack);
930 ADDR (bind_ack, ADDR);
931 tprintf (", CONIND=%ld", m.bind_ack.CONIND_number);
932 break;
933#endif
934#ifdef T_ERROR_ACK
935 case T_ERROR_ACK: /* error ack */
936 GET (T_ERROR_ACK, error_ack);
937 COMMA ();
938 tprintf ("ERROR=");
939 printxval (transport_user_options,
940 m.error_ack.ERROR_prim, "TI_???");
941 tprintf (", TLI=");
942 printxval (tli_errors, m.error_ack.TLI_error, "T???");
943 tprintf ("UNIX=%s", strerror (m.error_ack.UNIX_error));
944 break;
945#endif
946#ifdef T_OK_ACK
947 case T_OK_ACK: /* ok ack */
948 GET (T_OK_ACK, ok_ack);
949 COMMA ();
950 tprintf ("CORRECT=");
951 printxval (transport_user_options,
952 m.ok_ack.CORRECT_prim, "TI_???");
953 break;
954#endif
955#ifdef T_UNITDATA_IND
956 case T_UNITDATA_IND: /* unitdata ind */
957 GET (T_UNITDATA_IND, unitdata_ind);
958 ADDR (unitdata_ind, SRC);
959 ADDR (unitdata_ind, OPT);
960 break;
961#endif
962#ifdef T_UDERROR_IND
963 case T_UDERROR_IND: /* unitdata error ind */
964 GET (T_UDERROR_IND, uderror_ind);
965 ADDR (uderror_ind, DEST);
966 ADDR (uderror_ind, OPT);
967 tprintf (", ERROR=%ld", m.uderror_ind.ERROR_type);
968 break;
969#endif
970#ifdef T_OPTMGMT_ACK
971 case T_OPTMGMT_ACK: /* manage opt ack */
972 GET (T_OPTMGMT_ACK, optmgmt_ack);
973 COMMA ();
974 tprintf ("MGMT=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000975 printflags (transport_user_flags, m.optmgmt_ack.MGMT_flags,
976 "T_???");
John Hughes38ae88d2002-05-23 11:48:58 +0000977 STRUCT (optmgmt_ack, OPT, print_optmgmt);
978 break;
979#endif
980#ifdef T_ORDREL_IND
981 case T_ORDREL_IND: /* orderly rel ind */
982 GET (T_ORDREL_IND, ordrel_ind);
983 break;
984#endif
985#ifdef T_ADDR_REQ
986 case T_ADDR_REQ: /* address req */
987 GET (T_ADDR_REQ, addr_req);
988 break;
989#endif
990#ifdef T_ADDR_ACK
991 case T_ADDR_ACK: /* address response */
992 GET (T_ADDR_ACK, addr_ack);
993 ADDR (addr_ack, LOCADDR);
994 ADDR (addr_ack, REMADDR);
995 break;
996#endif
997 default:
998 dump:
999 c = -1;
1000 printstr(tcp, addr, len);
1001 break;
1002 }
1003
1004 if (c >= 0) tprintf ("}");
1005
1006#undef ADDR
1007#undef COMMA
1008#undef STRUCT
Roland McGrath34e014a2002-12-16 20:40:59 +00001009
John Hughes38ae88d2002-05-23 11:48:58 +00001010 return 0;
1011}
1012
1013
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001014#endif /* TI_BIND */
1015
John Hughes38ae88d2002-05-23 11:48:58 +00001016
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001017static int internal_stream_ioctl(struct tcb *tcp, int arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001018{
1019 struct strioctl si;
Roland McGrath1c04b0b2004-01-13 10:18:46 +00001020 struct ioctlent *iop;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001021 int in_and_out;
John Hughes38ae88d2002-05-23 11:48:58 +00001022 int timod = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001023#ifdef SI_GETUDATA
1024 struct si_udata udata;
1025#endif /* SI_GETUDATA */
1026
1027 if (!arg)
1028 return 0;
1029 if (umove(tcp, arg, &si) < 0) {
1030 if (entering(tcp))
1031 tprintf(", {...}");
1032 return 1;
1033 }
1034 if (entering(tcp)) {
Roland McGrath2843a4e2003-11-14 02:54:03 +00001035 iop = ioctl_lookup(si.ic_cmd);
1036 if (iop) {
1037 tprintf(", {ic_cmd=%s", iop->symbol);
1038 while ((iop = ioctl_next_match(iop)))
1039 tprintf(" or %s", iop->symbol);
1040 } else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001041 tprintf(", {ic_cmd=%#x", si.ic_cmd);
1042 if (si.ic_timout == INFTIM)
1043 tprintf(", ic_timout=INFTIM, ");
1044 else
1045 tprintf(" ic_timout=%d, ", si.ic_timout);
1046 }
1047 in_and_out = 1;
1048 switch (si.ic_cmd) {
1049#ifdef SI_GETUDATA
1050 case SI_GETUDATA:
1051 in_and_out = 0;
1052 break;
1053#endif /* SI_GETUDATA */
1054 }
1055 if (in_and_out) {
1056 if (entering(tcp))
1057 tprintf("/* in */ ");
1058 else
1059 tprintf(", /* out */ ");
1060 }
1061 if (in_and_out || entering(tcp))
1062 tprintf("ic_len=%d, ic_dp=", si.ic_len);
1063 switch (si.ic_cmd) {
1064#ifdef TI_BIND
1065 case TI_BIND:
1066 /* in T_BIND_REQ, out T_BIND_ACK */
John Hughes38ae88d2002-05-23 11:48:58 +00001067 ++timod;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001068 if (entering(tcp)) {
John Hughes38ae88d2002-05-23 11:48:58 +00001069 print_transport_message (tcp,
1070 T_BIND_REQ,
1071 si.ic_dp, si.ic_len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001072 }
1073 else {
John Hughes38ae88d2002-05-23 11:48:58 +00001074 print_transport_message (tcp,
1075 T_BIND_ACK,
1076 si.ic_dp, si.ic_len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001077 }
1078 break;
1079#endif /* TI_BIND */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001080#ifdef TI_UNBIND
1081 case TI_UNBIND:
1082 /* in T_UNBIND_REQ, out T_OK_ACK */
John Hughes38ae88d2002-05-23 11:48:58 +00001083 ++timod;
1084 if (entering(tcp)) {
1085 print_transport_message (tcp,
1086 T_UNBIND_REQ,
1087 si.ic_dp, si.ic_len);
1088 }
1089 else {
1090 print_transport_message (tcp,
1091 T_OK_ACK,
1092 si.ic_dp, si.ic_len);
1093 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001094 break;
1095#endif /* TI_UNBIND */
1096#ifdef TI_GETINFO
1097 case TI_GETINFO:
1098 /* in T_INFO_REQ, out T_INFO_ACK */
John Hughes38ae88d2002-05-23 11:48:58 +00001099 ++timod;
1100 if (entering(tcp)) {
1101 print_transport_message (tcp,
1102 T_INFO_REQ,
1103 si.ic_dp, si.ic_len);
1104 }
1105 else {
1106 print_transport_message (tcp,
1107 T_INFO_ACK,
1108 si.ic_dp, si.ic_len);
1109 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001110 break;
1111#endif /* TI_GETINFO */
1112#ifdef TI_OPTMGMT
1113 case TI_OPTMGMT:
1114 /* in T_OPTMGMT_REQ, out T_OPTMGMT_ACK */
John Hughes38ae88d2002-05-23 11:48:58 +00001115 ++timod;
1116 if (entering(tcp)) {
1117 print_transport_message (tcp,
1118 T_OPTMGMT_REQ,
1119 si.ic_dp, si.ic_len);
1120 }
1121 else {
1122 print_transport_message (tcp,
1123 T_OPTMGMT_ACK,
1124 si.ic_dp, si.ic_len);
1125 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001126 break;
1127#endif /* TI_OPTMGMT */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001128#ifdef SI_GETUDATA
1129 case SI_GETUDATA:
1130 if (entering(tcp))
1131 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001132 if (umove(tcp, (int) si.ic_dp, &udata) < 0)
1133 tprintf("{...}");
1134 else {
1135 tprintf("{tidusize=%d, addrsize=%d, ",
1136 udata.tidusize, udata.addrsize);
1137 tprintf("optsize=%d, etsdusize=%d, ",
1138 udata.optsize, udata.etsdusize);
1139 tprintf("servtype=%d, so_state=%d, ",
1140 udata.servtype, udata.so_state);
1141 tprintf("so_options=%d", udata.so_options);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001142 tprintf("}");
1143 }
1144 break;
1145#endif /* SI_GETUDATA */
1146 default:
Michal Ludvig10a88d02002-10-07 14:31:00 +00001147 printstr(tcp, (long) si.ic_dp, si.ic_len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001148 break;
1149 }
John Hughes38ae88d2002-05-23 11:48:58 +00001150 if (exiting(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001151 tprintf("}");
Dmitry V. Levin21a75342008-09-03 01:22:18 +00001152 if (timod && tcp->u_rval && !syserror(tcp)) {
John Hughes38ae88d2002-05-23 11:48:58 +00001153 tcp->auxstr = xlookup (tli_errors, tcp->u_rval);
1154 return RVAL_STR + 1;
1155 }
1156 }
Roland McGrath34e014a2002-12-16 20:40:59 +00001157
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001158 return 1;
1159}
1160
1161int
Denys Vlasenko12014262011-05-30 14:00:14 +02001162stream_ioctl(struct tcb *tcp, int code, int arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001163{
1164#ifdef I_LIST
1165 int i;
1166#endif
1167 int val;
1168#ifdef I_FLUSHBAND
1169 struct bandinfo bi;
1170#endif
1171 struct strpeek sp;
1172 struct strfdinsert sfi;
1173 struct strrecvfd srf;
1174#ifdef I_LIST
1175 struct str_list sl;
1176#endif
1177
1178 /* I_STR is a special case because the data is read & written. */
1179 if (code == I_STR)
1180 return internal_stream_ioctl(tcp, arg);
1181 if (entering(tcp))
1182 return 0;
1183
1184 switch (code) {
1185 case I_PUSH:
1186 case I_LOOK:
1187 case I_FIND:
1188 /* arg is a string */
1189 tprintf(", ");
1190 printpath(tcp, arg);
1191 return 1;
1192 case I_POP:
1193 /* doesn't take an argument */
1194 return 1;
1195 case I_FLUSH:
1196 /* argument is an option */
1197 tprintf(", ");
1198 printxval(stream_flush_options, arg, "FLUSH???");
1199 return 1;
1200#ifdef I_FLUSHBAND
1201 case I_FLUSHBAND:
1202 /* argument is a pointer to a bandinfo struct */
1203 if (umove(tcp, arg, &bi) < 0)
1204 tprintf(", {...}");
1205 else {
1206 tprintf(", {bi_pri=%d, bi_flag=", bi.bi_pri);
Roland McGrathb2dee132005-06-01 19:02:36 +00001207 printflags(stream_flush_options, bi.bi_flag, "FLUSH???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001208 tprintf("}");
1209 }
1210 return 1;
1211#endif /* I_FLUSHBAND */
1212 case I_SETSIG:
1213 /* argument is a set of flags */
1214 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001215 printflags(stream_setsig_flags, arg, "S_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001216 return 1;
1217 case I_GETSIG:
1218 /* argument is a pointer to a set of flags */
1219 if (syserror(tcp))
1220 return 0;
1221 tprintf(", [");
1222 if (umove(tcp, arg, &val) < 0)
1223 tprintf("?");
Roland McGrathb2dee132005-06-01 19:02:36 +00001224 else
1225 printflags(stream_setsig_flags, val, "S_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001226 tprintf("]");
1227 return 1;
1228 case I_PEEK:
1229 /* argument is a pointer to a strpeek structure */
1230 if (syserror(tcp) || !arg)
1231 return 0;
1232 if (umove(tcp, arg, &sp) < 0) {
1233 tprintf(", {...}");
1234 return 1;
1235 }
1236 tprintf(", {ctlbuf=");
1237 printstrbuf(tcp, &sp.ctlbuf, 1);
1238 tprintf(", databuf=");
1239 printstrbuf(tcp, &sp.databuf, 1);
John Hughesfd15cb32002-05-17 11:41:35 +00001240 tprintf(", flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001241 printflags(msgflags, sp.flags, "RS_???");
John Hughesfd15cb32002-05-17 11:41:35 +00001242 tprintf("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001243 return 1;
1244 case I_SRDOPT:
1245 /* argument is an option with flags */
1246 tprintf(", ");
1247 printxval(stream_read_options, arg & RMODEMASK, "R???");
1248 addflags(stream_read_flags, arg & ~RMODEMASK);
1249 return 1;
1250 case I_GRDOPT:
1251 /* argument is an pointer to an option with flags */
1252 if (syserror(tcp))
1253 return 0;
1254 tprintf(", [");
1255 if (umove(tcp, arg, &val) < 0)
1256 tprintf("?");
1257 else {
1258 printxval(stream_read_options,
1259 arg & RMODEMASK, "R???");
1260 addflags(stream_read_flags, arg & ~RMODEMASK);
1261 }
1262 tprintf("]");
1263 return 1;
1264 case I_NREAD:
1265#ifdef I_GETBAND
1266 case I_GETBAND:
1267#endif
1268#ifdef I_SETCLTIME
1269 case I_SETCLTIME:
1270#endif
1271#ifdef I_GETCLTIME
1272 case I_GETCLTIME:
1273#endif
1274 /* argument is a pointer to a decimal integer */
1275 if (syserror(tcp))
1276 return 0;
1277 tprintf(", ");
1278 printnum(tcp, arg, "%d");
1279 return 1;
1280 case I_FDINSERT:
1281 /* argument is a pointer to a strfdinsert structure */
1282 if (syserror(tcp) || !arg)
1283 return 0;
1284 if (umove(tcp, arg, &sfi) < 0) {
1285 tprintf(", {...}");
1286 return 1;
1287 }
1288 tprintf(", {ctlbuf=");
1289 printstrbuf(tcp, &sfi.ctlbuf, 1);
1290 tprintf(", databuf=");
1291 printstrbuf(tcp, &sfi.databuf, 1);
John Hughesfd15cb32002-05-17 11:41:35 +00001292 tprintf(", flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001293 printflags(msgflags, sfi.flags, "RS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001294 tprintf(", filedes=%d, offset=%d}", sfi.fildes, sfi.offset);
1295 return 1;
1296#ifdef I_SWROPT
1297 case I_SWROPT:
1298 /* argument is a set of flags */
1299 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001300 printflags(stream_write_flags, arg, "SND???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001301 return 1;
1302#endif /* I_SWROPT */
1303#ifdef I_GWROPT
1304 case I_GWROPT:
1305 /* argument is an pointer to an option with flags */
1306 if (syserror(tcp))
1307 return 0;
1308 tprintf(", [");
1309 if (umove(tcp, arg, &val) < 0)
1310 tprintf("?");
Roland McGrathb2dee132005-06-01 19:02:36 +00001311 else
1312 printflags(stream_write_flags, arg, "SND???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001313 tprintf("]");
1314 return 1;
1315#endif /* I_GWROPT */
1316 case I_SENDFD:
1317#ifdef I_CKBAND
1318 case I_CKBAND:
1319#endif
1320#ifdef I_CANPUT
1321 case I_CANPUT:
1322#endif
1323 case I_LINK:
1324 case I_UNLINK:
1325 case I_PLINK:
1326 case I_PUNLINK:
1327 /* argument is a decimal integer */
1328 tprintf(", %d", arg);
1329 return 1;
1330 case I_RECVFD:
1331 /* argument is a pointer to a strrecvfd structure */
1332 if (syserror(tcp) || !arg)
1333 return 0;
1334 if (umove(tcp, arg, &srf) < 0) {
1335 tprintf(", {...}");
1336 return 1;
1337 }
1338 tprintf(", {fd=%d, uid=%lu, gid=%lu}", srf.fd,
1339 (unsigned long) srf.uid, (unsigned long) srf.gid);
1340 return 1;
1341#ifdef I_LIST
1342 case I_LIST:
1343 if (syserror(tcp))
1344 return 0;
1345 if (arg == 0) {
1346 tprintf(", NULL");
1347 return 1;
1348 }
1349 if (umove(tcp, arg, &sl) < 0) {
1350 tprintf(", {...}");
1351 return 1;
1352 }
1353 tprintf(", {sl_nmods=%d, sl_modlist=[", sl.sl_nmods);
1354 for (i = 0; i < tcp->u_rval; i++) {
1355 if (i)
1356 tprintf(", ");
1357 printpath(tcp, (int) sl.sl_modlist[i].l_name);
1358 }
1359 tprintf("]}");
1360 return 1;
1361#endif /* I_LIST */
1362#ifdef I_ATMARK
1363 case I_ATMARK:
1364 tprintf(", ");
1365 printxval(stream_atmark_options, arg, "???MARK");
1366 return 1;
1367#endif /* I_ATMARK */
1368 default:
1369 return 0;
1370 }
1371}
1372
Roland McGrath561c7992003-04-02 01:10:44 +00001373#endif /* !LINUX && !FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001374
Roland McGrath561c7992003-04-02 01:10:44 +00001375#endif /* HAVE_SYS_STREAM_H || LINUX || FREEBSD */