Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com> |
Wichert Akkerman | 4dc8a2a | 1999-12-23 14:20:14 +0000 | [diff] [blame] | 3 | * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 4 | * 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 McGrath | 34e014a | 2002-12-16 20:40:59 +0000 | [diff] [blame] | 32 | #include <sys/syscall.h> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 33 | |
Wichert Akkerman | 42080d8 | 2001-04-10 10:32:26 +0000 | [diff] [blame] | 34 | #ifdef HAVE_POLL_H |
| 35 | #include <poll.h> |
| 36 | #endif |
Pavel Machek | 245a6ac | 2000-02-01 16:12:33 +0000 | [diff] [blame] | 37 | #ifdef HAVE_SYS_POLL_H |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 38 | #include <sys/poll.h> |
Pavel Machek | 245a6ac | 2000-02-01 16:12:33 +0000 | [diff] [blame] | 39 | #endif |
Wichert Akkerman | 42080d8 | 2001-04-10 10:32:26 +0000 | [diff] [blame] | 40 | #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 Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 52 | |
Roland McGrath | 561c799 | 2003-04-02 01:10:44 +0000 | [diff] [blame] | 53 | #if defined(HAVE_SYS_STREAM_H) || defined(LINUX) || defined(FREEBSD) |
Wichert Akkerman | 42080d8 | 2001-04-10 10:32:26 +0000 | [diff] [blame] | 54 | |
| 55 | #ifndef HAVE_STROPTS_H |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 56 | #define RS_HIPRI 1 |
| 57 | struct strbuf { |
Denys Vlasenko | adedb51 | 2008-12-30 18:47:55 +0000 | [diff] [blame] | 58 | int maxlen; /* no. of bytes in buffer */ |
| 59 | int len; /* no. of bytes returned */ |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 60 | const char *buf; /* pointer to data */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 61 | }; |
| 62 | #define MORECTL 1 |
| 63 | #define MOREDATA 2 |
Wichert Akkerman | 42080d8 | 2001-04-10 10:32:26 +0000 | [diff] [blame] | 64 | #endif /* !HAVE_STROPTS_H */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 65 | |
| 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 Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 72 | #ifndef FREEBSD |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 73 | static const struct xlat msgflags[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 74 | { RS_HIPRI, "RS_HIPRI" }, |
| 75 | { 0, NULL }, |
| 76 | }; |
| 77 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 78 | |
| 79 | static void |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 80 | printstrbuf(struct tcb *tcp, struct strbuf *sbp, int getting) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 81 | { |
| 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 Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 89 | printstr(tcp, (unsigned long) sbp->buf, sbp->len); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 90 | tprintf("}"); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | static void |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 95 | printstrbufarg(struct tcb *tcp, int arg, int getting) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 96 | { |
| 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 | |
| 108 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 109 | sys_putmsg(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 110 | { |
| 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 McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 120 | printflags(msgflags, tcp->u_arg[3], "RS_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 121 | } |
| 122 | return 0; |
| 123 | } |
| 124 | |
Dmitry V. Levin | b9fe011 | 2006-12-13 16:59:44 +0000 | [diff] [blame] | 125 | #if defined(SPARC) || defined(SPARC64) || defined(SUNOS4) || defined(SVR4) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 126 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 127 | sys_getmsg(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 128 | { |
| 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 McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 150 | printflags(msgflags, flags, "RS_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 151 | 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. Levin | b9fe011 | 2006-12-13 16:59:44 +0000 | [diff] [blame] | 171 | #endif /* SPARC || SPARC64 || SUNOS4 || SVR4 */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 172 | |
Roland McGrath | 34e014a | 2002-12-16 20:40:59 +0000 | [diff] [blame] | 173 | #if defined SYS_putpmsg || defined SYS_getpmsg |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 174 | static const struct xlat pmsgflags[] = { |
Wichert Akkerman | d856b99 | 2000-10-13 12:47:12 +0000 | [diff] [blame] | 175 | #ifdef MSG_HIPRI |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 176 | { MSG_HIPRI, "MSG_HIPRI" }, |
Wichert Akkerman | d856b99 | 2000-10-13 12:47:12 +0000 | [diff] [blame] | 177 | #endif |
| 178 | #ifdef MSG_AND |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 179 | { MSG_ANY, "MSG_ANY" }, |
Wichert Akkerman | d856b99 | 2000-10-13 12:47:12 +0000 | [diff] [blame] | 180 | #endif |
| 181 | #ifdef MSG_BAND |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 182 | { MSG_BAND, "MSG_BAND" }, |
Wichert Akkerman | d856b99 | 2000-10-13 12:47:12 +0000 | [diff] [blame] | 183 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 184 | { 0, NULL }, |
| 185 | }; |
Roland McGrath | 34e014a | 2002-12-16 20:40:59 +0000 | [diff] [blame] | 186 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 187 | |
Roland McGrath | 34e014a | 2002-12-16 20:40:59 +0000 | [diff] [blame] | 188 | #ifdef SYS_putpmsg |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 189 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 190 | sys_putpmsg(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 191 | { |
| 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 McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 203 | printflags(pmsgflags, tcp->u_arg[4], "MSG_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 204 | } |
| 205 | return 0; |
| 206 | } |
Roland McGrath | 34e014a | 2002-12-16 20:40:59 +0000 | [diff] [blame] | 207 | #endif /* SYS_putpmsg */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 208 | |
Roland McGrath | 34e014a | 2002-12-16 20:40:59 +0000 | [diff] [blame] | 209 | #ifdef SYS_getpmsg |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 210 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 211 | sys_getpmsg(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 212 | { |
| 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 Akkerman | 906dade | 1999-11-26 09:18:37 +0000 | [diff] [blame] | 229 | tprintf(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 230 | /* 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 McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 237 | printflags(pmsgflags, flags, "MSG_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 238 | 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 McGrath | 34e014a | 2002-12-16 20:40:59 +0000 | [diff] [blame] | 258 | #endif /* SYS_getpmsg */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 259 | |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 260 | #endif /* !FREEBSD */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 261 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 262 | |
Wichert Akkerman | faf7222 | 2000-02-19 23:59:03 +0000 | [diff] [blame] | 263 | #ifdef HAVE_SYS_POLL_H |
| 264 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 265 | static const struct xlat pollflags[] = { |
Pavel Machek | 245a6ac | 2000-02-01 16:12:33 +0000 | [diff] [blame] | 266 | #ifdef POLLIN |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 267 | { 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 Machek | 245a6ac | 2000-02-01 16:12:33 +0000 | [diff] [blame] | 285 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 286 | { 0, NULL }, |
| 287 | }; |
| 288 | |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 289 | static int |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 290 | decode_poll(struct tcb *tcp, long pts) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 291 | { |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 292 | struct pollfd fds; |
| 293 | unsigned nfds; |
| 294 | unsigned long size, start, cur, end, abbrev_end; |
| 295 | int failed = 0; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 296 | |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 297 | 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 McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 312 | abbrev_end = end; |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 313 | } |
| 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. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 331 | tprintf("{fd="); |
| 332 | printfd(tcp, fds.fd); |
| 333 | tprintf(", events="); |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 334 | 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 McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 342 | } else { |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 343 | static char outstr[1024]; |
| 344 | char str[64]; |
Denys Vlasenko | adedb51 | 2008-12-30 18:47:55 +0000 | [diff] [blame] | 345 | const char *flagstr; |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 346 | 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); |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 397 | flagstr = sprintflags("", pollflags, fds.revents); |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 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 McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 412 | char str[128]; |
| 413 | |
| 414 | sprintf(str, "%sleft ", cumlen ? ", " : ""); |
Roland McGrath | 6bc09da | 2007-11-01 21:50:54 +0000 | [diff] [blame] | 415 | sprint_timespec(str + strlen(str), tcp, pts); |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 416 | 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 McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 425 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 426 | } |
| 427 | |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 428 | int |
| 429 | sys_poll(struct tcb *tcp) |
| 430 | { |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 431 | int rc = decode_poll(tcp, 0); |
| 432 | if (entering(tcp)) { |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 433 | #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 |
| 444 | int |
| 445 | sys_ppoll(struct tcb *tcp) |
| 446 | { |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 447 | int rc = decode_poll(tcp, tcp->u_arg[2]); |
| 448 | if (entering(tcp)) { |
Roland McGrath | 6bc09da | 2007-11-01 21:50:54 +0000 | [diff] [blame] | 449 | print_timespec(tcp, tcp->u_arg[2]); |
| 450 | tprintf(", "); |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 451 | print_sigset(tcp, tcp->u_arg[3], 0); |
| 452 | tprintf(", %lu", tcp->u_arg[4]); |
| 453 | } |
| 454 | return rc; |
| 455 | } |
| 456 | #endif |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 457 | |
Wichert Akkerman | faf7222 | 2000-02-19 23:59:03 +0000 | [diff] [blame] | 458 | #else /* !HAVE_SYS_POLL_H */ |
| 459 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 460 | sys_poll(struct tcb *tcp) |
Wichert Akkerman | faf7222 | 2000-02-19 23:59:03 +0000 | [diff] [blame] | 461 | { |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 462 | return 0; |
Wichert Akkerman | faf7222 | 2000-02-19 23:59:03 +0000 | [diff] [blame] | 463 | } |
| 464 | #endif |
| 465 | |
Roland McGrath | 561c799 | 2003-04-02 01:10:44 +0000 | [diff] [blame] | 466 | #if !defined(LINUX) && !defined(FREEBSD) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 467 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 468 | static const struct xlat stream_flush_options[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 469 | { FLUSHR, "FLUSHR" }, |
| 470 | { FLUSHW, "FLUSHW" }, |
| 471 | { FLUSHRW, "FLUSHRW" }, |
| 472 | #ifdef FLUSHBAND |
| 473 | { FLUSHBAND, "FLUSHBAND" }, |
| 474 | #endif |
| 475 | { 0, NULL }, |
| 476 | }; |
| 477 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 478 | static const struct xlat stream_setsig_flags[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 479 | { 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 McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 507 | static const struct xlat stream_read_options[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 508 | { RNORM, "RNORM" }, |
| 509 | { RMSGD, "RMSGD" }, |
| 510 | { RMSGN, "RMSGN" }, |
| 511 | { 0, NULL }, |
| 512 | }; |
| 513 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 514 | static const struct xlat stream_read_flags[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 515 | #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 McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 532 | static const struct xlat stream_write_flags[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 533 | { SNDZERO, "SNDZERO" }, |
| 534 | { SNDPIPE, "SNDPIPE" }, |
| 535 | { 0, NULL }, |
| 536 | }; |
| 537 | #endif /* I_SWROPT */ |
| 538 | |
| 539 | #ifdef I_ATMARK |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 540 | static const struct xlat stream_atmark_options[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 541 | { ANYMARK, "ANYMARK" }, |
| 542 | { LASTMARK, "LASTMARK" }, |
| 543 | { 0, NULL }, |
| 544 | }; |
| 545 | #endif /* I_ATMARK */ |
| 546 | |
| 547 | #ifdef TI_BIND |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 548 | static const struct xlat transport_user_options[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 549 | { 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 | |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 563 | static const struct xlat transport_user_flags[] = { |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 564 | { 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 Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 576 | { 0, NULL }, |
| 577 | }; |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 578 | |
| 579 | |
Roland McGrath | 6d2b349 | 2002-12-30 00:51:30 +0000 | [diff] [blame] | 580 | #ifdef HAVE_STRUCT_T_OPTHDR |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 581 | |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 582 | static const struct xlat xti_level[] = { |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 583 | { XTI_GENERIC, "XTI_GENERIC" }, |
| 584 | { 0, NULL }, |
| 585 | }; |
| 586 | |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 587 | static const struct xlat xti_generic[] = { |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 588 | { 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 | |
| 599 | void |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 600 | print_xti_optmgmt(struct tcb *tcp, long addr, int len) |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 601 | { |
| 602 | int c = 0; |
| 603 | struct t_opthdr hdr; |
| 604 | |
John Hughes | 2c4e3a8 | 2002-05-24 10:19:44 +0000 | [diff] [blame] | 605 | while (len >= (int) sizeof hdr) { |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 606 | if (umove(tcp, addr, &hdr) < 0) break; |
| 607 | if (c++) { |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 608 | tprintf(", "); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 609 | } |
| 610 | else if (len > hdr.len + sizeof hdr) { |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 611 | tprintf("["); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 612 | } |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 613 | tprintf("{level="); |
| 614 | printxval(xti_level, hdr.level, "???"); |
| 615 | tprintf(", name="); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 616 | switch (hdr.level) { |
| 617 | case XTI_GENERIC: |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 618 | printxval(xti_generic, hdr.name, "XTI_???"); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 619 | break; |
| 620 | default: |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 621 | tprintf("%ld", hdr.name); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 622 | break; |
| 623 | } |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 624 | tprintf(", status="); |
| 625 | printxval(transport_user_flags, hdr.status, "T_???"); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 626 | addr += sizeof hdr; |
| 627 | len -= sizeof hdr; |
| 628 | if ((hdr.len -= sizeof hdr) > 0) { |
| 629 | if (hdr.len > len) break; |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 630 | tprintf(", val="); |
| 631 | if (len == sizeof(int)) |
| 632 | printnum(tcp, addr, "%d"); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 633 | else |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 634 | printstr(tcp, addr, hdr.len); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 635 | addr += hdr.len; |
| 636 | len -= hdr.len; |
| 637 | } |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 638 | tprintf("}"); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 639 | } |
| 640 | if (len > 0) { |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 641 | if (c++) tprintf(", "); |
| 642 | printstr(tcp, addr, len); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 643 | } |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 644 | if (c > 1) tprintf("]"); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | #endif |
| 648 | |
| 649 | |
| 650 | static void |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 651 | print_optmgmt(struct tcb *tcp, long addr, int len) |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 652 | { |
Roland McGrath | 34e014a | 2002-12-16 20:40:59 +0000 | [diff] [blame] | 653 | /* We don't know how to tell if TLI (socket) or XTI |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 654 | optmgmt is being used yet, assume TLI. */ |
Roland McGrath | 6d2b349 | 2002-12-30 00:51:30 +0000 | [diff] [blame] | 655 | #if defined (HAVE_STRUCT_OPTHDR) |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 656 | print_sock_optmgmt(tcp, addr, len); |
Roland McGrath | 6d2b349 | 2002-12-30 00:51:30 +0000 | [diff] [blame] | 657 | #elif defined (HAVE_STRUCT_T_OPTHDR) |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 658 | print_xti_optmgmt(tcp, addr, len); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 659 | #else |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 660 | printstr(tcp, addr, len); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 661 | #endif |
| 662 | } |
| 663 | |
| 664 | |
| 665 | |
| 666 | |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 667 | static const struct xlat service_type[] = { |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 668 | { T_COTS, "T_COTS" }, |
| 669 | { T_COTS_ORD, "T_COTS_ORD" }, |
| 670 | { T_CLTS, "T_CLTS" }, |
| 671 | { 0, NULL }, |
| 672 | }; |
| 673 | |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 674 | static const struct xlat ts_state[] = { |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 675 | { 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 | |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 695 | static const struct xlat provider_flags[] = { |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 696 | { 0, "0" }, |
| 697 | { SENDZERO, "SENDZERO" }, |
| 698 | { EXPINLINE, "EXPINLINE" }, |
| 699 | { XPG4_1, "XPG4_1" }, |
| 700 | { 0, NULL }, |
| 701 | }; |
| 702 | |
| 703 | |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 704 | static const struct xlat tli_errors[] = { |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 705 | { 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 | |
| 738 | static int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 739 | print_transport_message(struct tcb *tcp, int expect, long addr, int len) |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 740 | { |
| 741 | union T_primitives m; |
| 742 | int c = 0; |
| 743 | |
| 744 | if (len < sizeof m.type) goto dump; |
| 745 | |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 746 | if (umove(tcp, addr, &m.type) < 0) goto dump; |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 747 | |
| 748 | #define GET(type, struct) \ |
| 749 | do { \ |
| 750 | if (len < sizeof m.struct) goto dump; \ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 751 | if (umove(tcp, addr, &m.struct) < 0) goto dump;\ |
| 752 | tprintf("{"); \ |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 753 | if (expect != type) { \ |
| 754 | ++c; \ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 755 | tprintf(#type); \ |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 756 | } \ |
| 757 | } \ |
| 758 | while (0) |
| 759 | |
| 760 | #define COMMA() \ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 761 | do { if (c++) tprintf(", "); } while (0) |
Roland McGrath | 34e014a | 2002-12-16 20:40:59 +0000 | [diff] [blame] | 762 | |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 763 | |
| 764 | #define STRUCT(struct, elem, print) \ |
| 765 | do { \ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 766 | COMMA(); \ |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 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 | { \ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 771 | tprintf(#elem "_length=%ld, " #elem "_offset=%ld",\ |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 772 | m.struct.elem##_length, \ |
| 773 | m.struct.elem##_offset); \ |
| 774 | } \ |
| 775 | else { \ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 776 | tprintf(#elem "="); \ |
| 777 | print(tcp, \ |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 778 | addr + m.struct.elem##_offset, \ |
| 779 | m.struct.elem##_length); \ |
| 780 | } \ |
| 781 | } \ |
| 782 | while (0) |
| 783 | |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 784 | #define ADDR(struct, elem) STRUCT(struct, elem, printstr) |
Roland McGrath | 34e014a | 2002-12-16 20:40:59 +0000 | [diff] [blame] | 785 | |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 786 | switch (m.type) { |
| 787 | #ifdef T_CONN_REQ |
| 788 | case T_CONN_REQ: /* connect request */ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 789 | GET(T_CONN_REQ, conn_req); |
| 790 | ADDR(conn_req, DEST); |
| 791 | ADDR(conn_req, OPT); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 792 | break; |
| 793 | #endif |
| 794 | #ifdef T_CONN_RES |
| 795 | case T_CONN_RES: /* connect response */ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 796 | GET(T_CONN_RES, conn_res); |
Roland McGrath | 38dc6bb | 2003-01-10 20:05:54 +0000 | [diff] [blame] | 797 | #ifdef HAVE_STRUCT_T_CONN_RES_QUEUE_PTR |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 798 | COMMA(); |
| 799 | tprintf("QUEUE=%p", m.conn_res.QUEUE_ptr); |
Roland McGrath | 38dc6bb | 2003-01-10 20:05:54 +0000 | [diff] [blame] | 800 | #elif defined HAVE_STRUCT_T_CONN_RES_ACCEPTOR_ID |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 801 | COMMA(); |
| 802 | tprintf("ACCEPTOR=%#lx", m.conn_res.ACCEPTOR_id); |
Roland McGrath | 38dc6bb | 2003-01-10 20:05:54 +0000 | [diff] [blame] | 803 | #endif |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 804 | ADDR(conn_res, OPT); |
| 805 | COMMA(); |
| 806 | tprintf("SEQ=%ld", m.conn_res.SEQ_number); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 807 | break; |
| 808 | #endif |
| 809 | #ifdef T_DISCON_REQ |
| 810 | case T_DISCON_REQ: /* disconnect request */ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 811 | GET(T_DISCON_REQ, discon_req); |
| 812 | COMMA(); |
| 813 | tprintf("SEQ=%ld", m.discon_req.SEQ_number); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 814 | break; |
| 815 | #endif |
| 816 | #ifdef T_DATA_REQ |
| 817 | case T_DATA_REQ: /* data request */ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 818 | GET(T_DATA_REQ, data_req); |
| 819 | COMMA(); |
| 820 | tprintf("MORE=%ld", m.data_req.MORE_flag); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 821 | break; |
| 822 | #endif |
| 823 | #ifdef T_EXDATA_REQ |
| 824 | case T_EXDATA_REQ: /* expedited data req */ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 825 | GET(T_EXDATA_REQ, exdata_req); |
| 826 | COMMA(); |
| 827 | tprintf("MORE=%ld", m.exdata_req.MORE_flag); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 828 | break; |
| 829 | #endif |
| 830 | #ifdef T_INFO_REQ |
| 831 | case T_INFO_REQ: /* information req */ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 832 | GET(T_INFO_REQ, info_req); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 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 |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 840 | GET(T_BIND_REQ, bind_req); |
| 841 | ADDR(bind_req, ADDR); |
| 842 | COMMA(); |
| 843 | tprintf("CONIND=%ld", m.bind_req.CONIND_number); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 844 | break; |
| 845 | #endif |
| 846 | #ifdef T_UNBIND_REQ |
| 847 | case T_UNBIND_REQ: /* unbind request */ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 848 | GET(T_UNBIND_REQ, unbind_req); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 849 | break; |
| 850 | #endif |
| 851 | #ifdef T_UNITDATA_REQ |
| 852 | case T_UNITDATA_REQ: /* unitdata requset */ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 853 | GET(T_UNITDATA_REQ, unitdata_req); |
| 854 | ADDR(unitdata_req, DEST); |
| 855 | ADDR(unitdata_req, OPT); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 856 | break; |
| 857 | #endif |
| 858 | #ifdef T_OPTMGMT_REQ |
| 859 | case T_OPTMGMT_REQ: /* manage opt req */ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 860 | GET(T_OPTMGMT_REQ, optmgmt_req); |
| 861 | COMMA(); |
| 862 | tprintf("MGMT="); |
| 863 | printflags(transport_user_flags, m.optmgmt_req.MGMT_flags, |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 864 | "T_???"); |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 865 | STRUCT(optmgmt_req, OPT, print_optmgmt); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 866 | break; |
| 867 | #endif |
| 868 | #ifdef T_ORDREL_REQ |
| 869 | case T_ORDREL_REQ: /* orderly rel req */ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 870 | GET(T_ORDREL_REQ, ordrel_req); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 871 | break; |
| 872 | #endif |
| 873 | #ifdef T_CONN_IND |
| 874 | case T_CONN_IND: /* connect indication */ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 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); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 879 | break; |
| 880 | #endif |
| 881 | #ifdef T_CONN_CON |
| 882 | case T_CONN_CON: /* connect corfirm */ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 883 | GET(T_CONN_CON, conn_con); |
| 884 | ADDR(conn_con, RES); |
| 885 | ADDR(conn_con, OPT); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 886 | break; |
| 887 | #endif |
| 888 | #ifdef T_DISCON_IND |
| 889 | case T_DISCON_IND: /* discon indication */ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 890 | GET(T_DISCON_IND, discon_ind); |
| 891 | COMMA(); |
| 892 | tprintf("DISCON=%ld, SEQ=%ld", |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 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 */ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 898 | GET(T_DATA_IND, data_ind); |
| 899 | COMMA(); |
| 900 | tprintf("MORE=%ld", m.data_ind.MORE_flag); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 901 | break; |
| 902 | #endif |
| 903 | #ifdef T_EXDATA_IND |
| 904 | case T_EXDATA_IND: /* expedited data ind */ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 905 | GET(T_EXDATA_IND, exdata_ind); |
| 906 | COMMA(); |
| 907 | tprintf("MORE=%ld", m.exdata_ind.MORE_flag); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 908 | break; |
| 909 | #endif |
| 910 | #ifdef T_INFO_ACK |
| 911 | case T_INFO_ACK: /* info ack */ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 912 | GET(T_INFO_ACK, info_ack); |
| 913 | COMMA(); |
| 914 | tprintf("TSDU=%ld, ETSDU=%ld, CDATA=%ld, DDATA=%ld, " |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 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); |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 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="); |
| 924 | printflags(provider_flags, m.info_ack.PROVIDER_flag, "???"); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 925 | break; |
| 926 | #endif |
| 927 | #ifdef T_BIND_ACK |
| 928 | case T_BIND_ACK: /* bind ack */ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 929 | GET(T_BIND_ACK, bind_ack); |
| 930 | ADDR(bind_ack, ADDR); |
| 931 | tprintf(", CONIND=%ld", m.bind_ack.CONIND_number); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 932 | break; |
| 933 | #endif |
| 934 | #ifdef T_ERROR_ACK |
| 935 | case T_ERROR_ACK: /* error ack */ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 936 | GET(T_ERROR_ACK, error_ack); |
| 937 | COMMA(); |
| 938 | tprintf("ERROR="); |
| 939 | printxval(transport_user_options, |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 940 | m.error_ack.ERROR_prim, "TI_???"); |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 941 | tprintf(", TLI="); |
| 942 | printxval(tli_errors, m.error_ack.TLI_error, "T???"); |
| 943 | tprintf("UNIX=%s", strerror(m.error_ack.UNIX_error)); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 944 | break; |
| 945 | #endif |
| 946 | #ifdef T_OK_ACK |
| 947 | case T_OK_ACK: /* ok ack */ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 948 | GET(T_OK_ACK, ok_ack); |
| 949 | COMMA(); |
| 950 | tprintf("CORRECT="); |
| 951 | printxval(transport_user_options, |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 952 | m.ok_ack.CORRECT_prim, "TI_???"); |
| 953 | break; |
| 954 | #endif |
| 955 | #ifdef T_UNITDATA_IND |
| 956 | case T_UNITDATA_IND: /* unitdata ind */ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 957 | GET(T_UNITDATA_IND, unitdata_ind); |
| 958 | ADDR(unitdata_ind, SRC); |
| 959 | ADDR(unitdata_ind, OPT); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 960 | break; |
| 961 | #endif |
| 962 | #ifdef T_UDERROR_IND |
| 963 | case T_UDERROR_IND: /* unitdata error ind */ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 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); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 968 | break; |
| 969 | #endif |
| 970 | #ifdef T_OPTMGMT_ACK |
| 971 | case T_OPTMGMT_ACK: /* manage opt ack */ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 972 | GET(T_OPTMGMT_ACK, optmgmt_ack); |
| 973 | COMMA(); |
| 974 | tprintf("MGMT="); |
| 975 | printflags(transport_user_flags, m.optmgmt_ack.MGMT_flags, |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 976 | "T_???"); |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 977 | STRUCT(optmgmt_ack, OPT, print_optmgmt); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 978 | break; |
| 979 | #endif |
| 980 | #ifdef T_ORDREL_IND |
| 981 | case T_ORDREL_IND: /* orderly rel ind */ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 982 | GET(T_ORDREL_IND, ordrel_ind); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 983 | break; |
| 984 | #endif |
| 985 | #ifdef T_ADDR_REQ |
| 986 | case T_ADDR_REQ: /* address req */ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 987 | GET(T_ADDR_REQ, addr_req); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 988 | break; |
| 989 | #endif |
| 990 | #ifdef T_ADDR_ACK |
| 991 | case T_ADDR_ACK: /* address response */ |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 992 | GET(T_ADDR_ACK, addr_ack); |
| 993 | ADDR(addr_ack, LOCADDR); |
| 994 | ADDR(addr_ack, REMADDR); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 995 | break; |
| 996 | #endif |
| 997 | default: |
| 998 | dump: |
| 999 | c = -1; |
| 1000 | printstr(tcp, addr, len); |
| 1001 | break; |
| 1002 | } |
| 1003 | |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 1004 | if (c >= 0) tprintf("}"); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1005 | |
| 1006 | #undef ADDR |
| 1007 | #undef COMMA |
| 1008 | #undef STRUCT |
Roland McGrath | 34e014a | 2002-12-16 20:40:59 +0000 | [diff] [blame] | 1009 | |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1010 | return 0; |
| 1011 | } |
| 1012 | |
| 1013 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1014 | #endif /* TI_BIND */ |
| 1015 | |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1016 | |
Dmitry V. Levin | e5e6085 | 2009-12-31 22:50:49 +0000 | [diff] [blame] | 1017 | static int internal_stream_ioctl(struct tcb *tcp, int arg) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1018 | { |
| 1019 | struct strioctl si; |
Roland McGrath | 1c04b0b | 2004-01-13 10:18:46 +0000 | [diff] [blame] | 1020 | struct ioctlent *iop; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1021 | int in_and_out; |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1022 | int timod = 0; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1023 | #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 McGrath | 2843a4e | 2003-11-14 02:54:03 +0000 | [diff] [blame] | 1035 | 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 Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1041 | 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 Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1067 | ++timod; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1068 | if (entering(tcp)) { |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 1069 | print_transport_message(tcp, |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1070 | T_BIND_REQ, |
| 1071 | si.ic_dp, si.ic_len); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1072 | } |
| 1073 | else { |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 1074 | print_transport_message(tcp, |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1075 | T_BIND_ACK, |
| 1076 | si.ic_dp, si.ic_len); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1077 | } |
| 1078 | break; |
| 1079 | #endif /* TI_BIND */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1080 | #ifdef TI_UNBIND |
| 1081 | case TI_UNBIND: |
| 1082 | /* in T_UNBIND_REQ, out T_OK_ACK */ |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1083 | ++timod; |
| 1084 | if (entering(tcp)) { |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 1085 | print_transport_message(tcp, |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1086 | T_UNBIND_REQ, |
| 1087 | si.ic_dp, si.ic_len); |
| 1088 | } |
| 1089 | else { |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 1090 | print_transport_message(tcp, |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1091 | T_OK_ACK, |
| 1092 | si.ic_dp, si.ic_len); |
| 1093 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1094 | break; |
| 1095 | #endif /* TI_UNBIND */ |
| 1096 | #ifdef TI_GETINFO |
| 1097 | case TI_GETINFO: |
| 1098 | /* in T_INFO_REQ, out T_INFO_ACK */ |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1099 | ++timod; |
| 1100 | if (entering(tcp)) { |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 1101 | print_transport_message(tcp, |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1102 | T_INFO_REQ, |
| 1103 | si.ic_dp, si.ic_len); |
| 1104 | } |
| 1105 | else { |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 1106 | print_transport_message(tcp, |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1107 | T_INFO_ACK, |
| 1108 | si.ic_dp, si.ic_len); |
| 1109 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1110 | break; |
| 1111 | #endif /* TI_GETINFO */ |
| 1112 | #ifdef TI_OPTMGMT |
| 1113 | case TI_OPTMGMT: |
| 1114 | /* in T_OPTMGMT_REQ, out T_OPTMGMT_ACK */ |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1115 | ++timod; |
| 1116 | if (entering(tcp)) { |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 1117 | print_transport_message(tcp, |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1118 | T_OPTMGMT_REQ, |
| 1119 | si.ic_dp, si.ic_len); |
| 1120 | } |
| 1121 | else { |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 1122 | print_transport_message(tcp, |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1123 | T_OPTMGMT_ACK, |
| 1124 | si.ic_dp, si.ic_len); |
| 1125 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1126 | break; |
| 1127 | #endif /* TI_OPTMGMT */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1128 | #ifdef SI_GETUDATA |
| 1129 | case SI_GETUDATA: |
| 1130 | if (entering(tcp)) |
| 1131 | break; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1132 | 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 Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1142 | tprintf("}"); |
| 1143 | } |
| 1144 | break; |
| 1145 | #endif /* SI_GETUDATA */ |
| 1146 | default: |
Michal Ludvig | 10a88d0 | 2002-10-07 14:31:00 +0000 | [diff] [blame] | 1147 | printstr(tcp, (long) si.ic_dp, si.ic_len); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1148 | break; |
| 1149 | } |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1150 | if (exiting(tcp)) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1151 | tprintf("}"); |
Dmitry V. Levin | 21a7534 | 2008-09-03 01:22:18 +0000 | [diff] [blame] | 1152 | if (timod && tcp->u_rval && !syserror(tcp)) { |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 1153 | tcp->auxstr = xlookup(tli_errors, tcp->u_rval); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1154 | return RVAL_STR + 1; |
| 1155 | } |
| 1156 | } |
Roland McGrath | 34e014a | 2002-12-16 20:40:59 +0000 | [diff] [blame] | 1157 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1158 | return 1; |
| 1159 | } |
| 1160 | |
| 1161 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 1162 | stream_ioctl(struct tcb *tcp, int code, int arg) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1163 | { |
| 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 McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 1207 | printflags(stream_flush_options, bi.bi_flag, "FLUSH???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1208 | tprintf("}"); |
| 1209 | } |
| 1210 | return 1; |
| 1211 | #endif /* I_FLUSHBAND */ |
| 1212 | case I_SETSIG: |
| 1213 | /* argument is a set of flags */ |
| 1214 | tprintf(", "); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 1215 | printflags(stream_setsig_flags, arg, "S_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1216 | 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 McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 1224 | else |
| 1225 | printflags(stream_setsig_flags, val, "S_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1226 | 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 Hughes | fd15cb3 | 2002-05-17 11:41:35 +0000 | [diff] [blame] | 1240 | tprintf(", flags="); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 1241 | printflags(msgflags, sp.flags, "RS_???"); |
John Hughes | fd15cb3 | 2002-05-17 11:41:35 +0000 | [diff] [blame] | 1242 | tprintf("}"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1243 | 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 Hughes | fd15cb3 | 2002-05-17 11:41:35 +0000 | [diff] [blame] | 1292 | tprintf(", flags="); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 1293 | printflags(msgflags, sfi.flags, "RS_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1294 | 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 McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 1300 | printflags(stream_write_flags, arg, "SND???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1301 | 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 McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 1311 | else |
| 1312 | printflags(stream_write_flags, arg, "SND???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1313 | 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 McGrath | 561c799 | 2003-04-02 01:10:44 +0000 | [diff] [blame] | 1373 | #endif /* !LINUX && !FREEBSD */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1374 | |
Roland McGrath | 561c799 | 2003-04-02 01:10:44 +0000 | [diff] [blame] | 1375 | #endif /* HAVE_SYS_STREAM_H || LINUX || FREEBSD */ |