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 | |
Wichert Akkerman | 42080d8 | 2001-04-10 10:32:26 +0000 | [diff] [blame] | 53 | |
| 54 | #ifndef HAVE_STROPTS_H |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 55 | #define RS_HIPRI 1 |
| 56 | struct strbuf { |
Denys Vlasenko | adedb51 | 2008-12-30 18:47:55 +0000 | [diff] [blame] | 57 | int maxlen; /* no. of bytes in buffer */ |
| 58 | int len; /* no. of bytes returned */ |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 59 | const char *buf; /* pointer to data */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 60 | }; |
| 61 | #define MORECTL 1 |
| 62 | #define MOREDATA 2 |
Wichert Akkerman | 42080d8 | 2001-04-10 10:32:26 +0000 | [diff] [blame] | 63 | #endif /* !HAVE_STROPTS_H */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 64 | |
| 65 | #ifdef HAVE_SYS_TIUSER_H |
| 66 | #include <sys/tiuser.h> |
| 67 | #include <sys/sockmod.h> |
| 68 | #include <sys/timod.h> |
| 69 | #endif /* HAVE_SYS_TIUSER_H */ |
| 70 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 71 | static const struct xlat msgflags[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 72 | { RS_HIPRI, "RS_HIPRI" }, |
| 73 | { 0, NULL }, |
| 74 | }; |
| 75 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 76 | |
| 77 | static void |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 78 | printstrbuf(struct tcb *tcp, struct strbuf *sbp, int getting) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 79 | { |
| 80 | if (sbp->maxlen == -1 && getting) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 81 | tprints("{maxlen=-1}"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 82 | else { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 83 | tprints("{"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 84 | if (getting) |
| 85 | tprintf("maxlen=%d, ", sbp->maxlen); |
| 86 | tprintf("len=%d, buf=", sbp->len); |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 87 | printstr(tcp, (unsigned long) sbp->buf, sbp->len); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 88 | tprints("}"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 89 | } |
| 90 | } |
| 91 | |
| 92 | static void |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 93 | printstrbufarg(struct tcb *tcp, int arg, int getting) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 94 | { |
| 95 | struct strbuf buf; |
| 96 | |
| 97 | if (arg == 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 98 | tprints("NULL"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 99 | else if (umove(tcp, arg, &buf) < 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 100 | tprints("{...}"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 101 | else |
| 102 | printstrbuf(tcp, &buf, getting); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 103 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 107 | sys_putmsg(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 108 | { |
| 109 | int i; |
| 110 | |
| 111 | if (entering(tcp)) { |
| 112 | /* fd */ |
| 113 | tprintf("%ld, ", tcp->u_arg[0]); |
| 114 | /* control and data */ |
| 115 | for (i = 1; i < 3; i++) |
| 116 | printstrbufarg(tcp, tcp->u_arg[i], 0); |
| 117 | /* flags */ |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 118 | printflags(msgflags, tcp->u_arg[3], "RS_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 119 | } |
| 120 | return 0; |
| 121 | } |
| 122 | |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame^] | 123 | #if defined(SPARC) || defined(SPARC64) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 124 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 125 | sys_getmsg(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 126 | { |
| 127 | int i, flags; |
| 128 | |
| 129 | if (entering(tcp)) { |
| 130 | /* fd */ |
| 131 | tprintf("%lu, ", tcp->u_arg[0]); |
| 132 | } else { |
| 133 | if (syserror(tcp)) { |
| 134 | tprintf("%#lx, %#lx, %#lx", |
| 135 | tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]); |
| 136 | return 0; |
| 137 | } |
| 138 | /* control and data */ |
| 139 | for (i = 1; i < 3; i++) |
| 140 | printstrbufarg(tcp, tcp->u_arg[i], 1); |
| 141 | /* pointer to flags */ |
| 142 | if (tcp->u_arg[3] == 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 143 | tprints("NULL"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 144 | else if (umove(tcp, tcp->u_arg[3], &flags) < 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 145 | tprints("[?]"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 146 | else { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 147 | tprints("["); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 148 | printflags(msgflags, flags, "RS_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 149 | tprints("]"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 150 | } |
| 151 | /* decode return value */ |
| 152 | switch (tcp->u_rval) { |
| 153 | case MORECTL: |
| 154 | tcp->auxstr = "MORECTL"; |
| 155 | break; |
| 156 | case MORECTL|MOREDATA: |
| 157 | tcp->auxstr = "MORECTL|MOREDATA"; |
| 158 | break; |
| 159 | case MOREDATA: |
| 160 | tcp->auxstr = "MORECTL"; |
| 161 | break; |
| 162 | default: |
| 163 | tcp->auxstr = NULL; |
| 164 | break; |
| 165 | } |
| 166 | } |
| 167 | return RVAL_HEX | RVAL_STR; |
| 168 | } |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame^] | 169 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 170 | |
Roland McGrath | 34e014a | 2002-12-16 20:40:59 +0000 | [diff] [blame] | 171 | #if defined SYS_putpmsg || defined SYS_getpmsg |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 172 | static const struct xlat pmsgflags[] = { |
Wichert Akkerman | d856b99 | 2000-10-13 12:47:12 +0000 | [diff] [blame] | 173 | #ifdef MSG_HIPRI |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 174 | { MSG_HIPRI, "MSG_HIPRI" }, |
Wichert Akkerman | d856b99 | 2000-10-13 12:47:12 +0000 | [diff] [blame] | 175 | #endif |
| 176 | #ifdef MSG_AND |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 177 | { MSG_ANY, "MSG_ANY" }, |
Wichert Akkerman | d856b99 | 2000-10-13 12:47:12 +0000 | [diff] [blame] | 178 | #endif |
| 179 | #ifdef MSG_BAND |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 180 | { MSG_BAND, "MSG_BAND" }, |
Wichert Akkerman | d856b99 | 2000-10-13 12:47:12 +0000 | [diff] [blame] | 181 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 182 | { 0, NULL }, |
| 183 | }; |
Roland McGrath | 34e014a | 2002-12-16 20:40:59 +0000 | [diff] [blame] | 184 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 185 | |
Roland McGrath | 34e014a | 2002-12-16 20:40:59 +0000 | [diff] [blame] | 186 | #ifdef SYS_putpmsg |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 187 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 188 | sys_putpmsg(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 189 | { |
| 190 | int i; |
| 191 | |
| 192 | if (entering(tcp)) { |
| 193 | /* fd */ |
| 194 | tprintf("%ld, ", tcp->u_arg[0]); |
| 195 | /* control and data */ |
| 196 | for (i = 1; i < 3; i++) |
| 197 | printstrbufarg(tcp, tcp->u_arg[i], 0); |
| 198 | /* band */ |
| 199 | tprintf("%ld, ", tcp->u_arg[3]); |
| 200 | /* flags */ |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 201 | printflags(pmsgflags, tcp->u_arg[4], "MSG_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 202 | } |
| 203 | return 0; |
| 204 | } |
Roland McGrath | 34e014a | 2002-12-16 20:40:59 +0000 | [diff] [blame] | 205 | #endif /* SYS_putpmsg */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 206 | |
Roland McGrath | 34e014a | 2002-12-16 20:40:59 +0000 | [diff] [blame] | 207 | #ifdef SYS_getpmsg |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 208 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 209 | sys_getpmsg(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 210 | { |
| 211 | int i, flags; |
| 212 | |
| 213 | if (entering(tcp)) { |
| 214 | /* fd */ |
| 215 | tprintf("%lu, ", tcp->u_arg[0]); |
| 216 | } else { |
| 217 | if (syserror(tcp)) { |
| 218 | tprintf("%#lx, %#lx, %#lx, %#lx", tcp->u_arg[1], |
| 219 | tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[4]); |
| 220 | return 0; |
| 221 | } |
| 222 | /* control and data */ |
| 223 | for (i = 1; i < 3; i++) |
| 224 | printstrbufarg(tcp, tcp->u_arg[i], 1); |
| 225 | /* pointer to band */ |
| 226 | printnum(tcp, tcp->u_arg[3], "%d"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 227 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 228 | /* pointer to flags */ |
| 229 | if (tcp->u_arg[4] == 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 230 | tprints("NULL"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 231 | else if (umove(tcp, tcp->u_arg[4], &flags) < 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 232 | tprints("[?]"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 233 | else { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 234 | tprints("["); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 235 | printflags(pmsgflags, flags, "MSG_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 236 | tprints("]"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 237 | } |
| 238 | /* decode return value */ |
| 239 | switch (tcp->u_rval) { |
| 240 | case MORECTL: |
| 241 | tcp->auxstr = "MORECTL"; |
| 242 | break; |
| 243 | case MORECTL|MOREDATA: |
| 244 | tcp->auxstr = "MORECTL|MOREDATA"; |
| 245 | break; |
| 246 | case MOREDATA: |
| 247 | tcp->auxstr = "MORECTL"; |
| 248 | break; |
| 249 | default: |
| 250 | tcp->auxstr = NULL; |
| 251 | break; |
| 252 | } |
| 253 | } |
| 254 | return RVAL_HEX | RVAL_STR; |
| 255 | } |
Roland McGrath | 34e014a | 2002-12-16 20:40:59 +0000 | [diff] [blame] | 256 | #endif /* SYS_getpmsg */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 257 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 258 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 259 | |
Wichert Akkerman | faf7222 | 2000-02-19 23:59:03 +0000 | [diff] [blame] | 260 | #ifdef HAVE_SYS_POLL_H |
| 261 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 262 | static const struct xlat pollflags[] = { |
Pavel Machek | 245a6ac | 2000-02-01 16:12:33 +0000 | [diff] [blame] | 263 | #ifdef POLLIN |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 264 | { POLLIN, "POLLIN" }, |
| 265 | { POLLPRI, "POLLPRI" }, |
| 266 | { POLLOUT, "POLLOUT" }, |
| 267 | #ifdef POLLRDNORM |
| 268 | { POLLRDNORM, "POLLRDNORM" }, |
| 269 | #endif |
| 270 | #ifdef POLLWRNORM |
| 271 | { POLLWRNORM, "POLLWRNORM" }, |
| 272 | #endif |
| 273 | #ifdef POLLRDBAND |
| 274 | { POLLRDBAND, "POLLRDBAND" }, |
| 275 | #endif |
| 276 | #ifdef POLLWRBAND |
| 277 | { POLLWRBAND, "POLLWRBAND" }, |
| 278 | #endif |
| 279 | { POLLERR, "POLLERR" }, |
| 280 | { POLLHUP, "POLLHUP" }, |
| 281 | { POLLNVAL, "POLLNVAL" }, |
Pavel Machek | 245a6ac | 2000-02-01 16:12:33 +0000 | [diff] [blame] | 282 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 283 | { 0, NULL }, |
| 284 | }; |
| 285 | |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 286 | static int |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 287 | decode_poll(struct tcb *tcp, long pts) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 288 | { |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 289 | struct pollfd fds; |
| 290 | unsigned nfds; |
| 291 | unsigned long size, start, cur, end, abbrev_end; |
| 292 | int failed = 0; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 293 | |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 294 | if (entering(tcp)) { |
| 295 | nfds = tcp->u_arg[1]; |
| 296 | size = sizeof(fds) * nfds; |
| 297 | start = tcp->u_arg[0]; |
| 298 | end = start + size; |
| 299 | if (nfds == 0 || size / sizeof(fds) != nfds || end < start) { |
| 300 | tprintf("%#lx, %d, ", |
| 301 | tcp->u_arg[0], nfds); |
| 302 | return 0; |
| 303 | } |
| 304 | if (abbrev(tcp)) { |
| 305 | abbrev_end = start + max_strlen * sizeof(fds); |
| 306 | if (abbrev_end < start) |
| 307 | abbrev_end = end; |
| 308 | } else { |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 309 | abbrev_end = end; |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 310 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 311 | tprints("["); |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 312 | for (cur = start; cur < end; cur += sizeof(fds)) { |
| 313 | if (cur > start) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 314 | tprints(", "); |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 315 | if (cur >= abbrev_end) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 316 | tprints("..."); |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 317 | break; |
| 318 | } |
| 319 | if (umoven(tcp, cur, sizeof fds, (char *) &fds) < 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 320 | tprints("?"); |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 321 | failed = 1; |
| 322 | break; |
| 323 | } |
| 324 | if (fds.fd < 0) { |
| 325 | tprintf("{fd=%d}", fds.fd); |
| 326 | continue; |
| 327 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 328 | tprints("{fd="); |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 329 | printfd(tcp, fds.fd); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 330 | tprints(", events="); |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 331 | printflags(pollflags, fds.events, "POLL???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 332 | tprints("}"); |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 333 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 334 | tprints("]"); |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 335 | if (failed) |
| 336 | tprintf(" %#lx", start); |
| 337 | tprintf(", %d, ", nfds); |
| 338 | return 0; |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 339 | } else { |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 340 | static char outstr[1024]; |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 341 | char *outptr; |
| 342 | #define end_outstr (outstr + sizeof(outstr)) |
Denys Vlasenko | adedb51 | 2008-12-30 18:47:55 +0000 | [diff] [blame] | 343 | const char *flagstr; |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 344 | |
| 345 | if (syserror(tcp)) |
| 346 | return 0; |
| 347 | if (tcp->u_rval == 0) { |
| 348 | tcp->auxstr = "Timeout"; |
| 349 | return RVAL_STR; |
| 350 | } |
| 351 | |
| 352 | nfds = tcp->u_arg[1]; |
| 353 | size = sizeof(fds) * nfds; |
| 354 | start = tcp->u_arg[0]; |
| 355 | end = start + size; |
| 356 | if (nfds == 0 || size / sizeof(fds) != nfds || end < start) |
| 357 | return 0; |
| 358 | if (abbrev(tcp)) { |
| 359 | abbrev_end = start + max_strlen * sizeof(fds); |
| 360 | if (abbrev_end < start) |
| 361 | abbrev_end = end; |
| 362 | } else { |
| 363 | abbrev_end = end; |
| 364 | } |
| 365 | |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 366 | outptr = outstr; |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 367 | |
| 368 | for (cur = start; cur < end; cur += sizeof(fds)) { |
| 369 | if (umoven(tcp, cur, sizeof fds, (char *) &fds) < 0) { |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 370 | if (outptr < end_outstr - 2) |
| 371 | *outptr++ = '?'; |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 372 | failed = 1; |
| 373 | break; |
| 374 | } |
| 375 | if (!fds.revents) |
| 376 | continue; |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 377 | if (outptr == outstr) { |
| 378 | *outptr++ = '['; |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 379 | } else { |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 380 | if (outptr < end_outstr - 3) |
| 381 | outptr = stpcpy(outptr, ", "); |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 382 | } |
| 383 | if (cur >= abbrev_end) { |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 384 | if (outptr < end_outstr - 4) |
| 385 | outptr = stpcpy(outptr, "..."); |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 386 | break; |
| 387 | } |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 388 | if (outptr < end_outstr - (sizeof("{fd=%d, revents=") + sizeof(int)*3) + 1) |
| 389 | outptr += sprintf(outptr, "{fd=%d, revents=", fds.fd); |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 390 | flagstr = sprintflags("", pollflags, fds.revents); |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 391 | if (outptr < end_outstr - (strlen(flagstr) + 2)) { |
| 392 | outptr = stpcpy(outptr, flagstr); |
| 393 | *outptr++ = '}'; |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 394 | } |
| 395 | } |
| 396 | if (failed) |
| 397 | return 0; |
| 398 | |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 399 | if (outptr != outstr /* && outptr < end_outstr - 1 (always true)*/) |
| 400 | *outptr++ = ']'; |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 401 | |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 402 | *outptr = '\0'; |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 403 | if (pts) { |
Denys Vlasenko | a1d541e | 2012-01-20 11:04:04 +0100 | [diff] [blame] | 404 | if (outptr < end_outstr - (10 + TIMESPEC_TEXT_BUFSIZE)) { |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 405 | outptr = stpcpy(outptr, outptr == outstr ? "left " : ", left "); |
| 406 | sprint_timespec(outptr, tcp, pts); |
| 407 | } |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 408 | } |
| 409 | |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 410 | if (outptr == outstr) |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 411 | return 0; |
| 412 | |
| 413 | tcp->auxstr = outstr; |
| 414 | return RVAL_STR; |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 415 | #undef end_outstr |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 416 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 417 | } |
| 418 | |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 419 | int |
| 420 | sys_poll(struct tcb *tcp) |
| 421 | { |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 422 | int rc = decode_poll(tcp, 0); |
| 423 | if (entering(tcp)) { |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 424 | #ifdef INFTIM |
| 425 | if (tcp->u_arg[2] == INFTIM) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 426 | tprints("INFTIM"); |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 427 | else |
| 428 | #endif |
| 429 | tprintf("%ld", tcp->u_arg[2]); |
| 430 | } |
| 431 | return rc; |
| 432 | } |
| 433 | |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 434 | int |
| 435 | sys_ppoll(struct tcb *tcp) |
| 436 | { |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 437 | int rc = decode_poll(tcp, tcp->u_arg[2]); |
| 438 | if (entering(tcp)) { |
Roland McGrath | 6bc09da | 2007-11-01 21:50:54 +0000 | [diff] [blame] | 439 | print_timespec(tcp, tcp->u_arg[2]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 440 | tprints(", "); |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 441 | print_sigset(tcp, tcp->u_arg[3], 0); |
| 442 | tprintf(", %lu", tcp->u_arg[4]); |
| 443 | } |
| 444 | return rc; |
| 445 | } |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 446 | |
Wichert Akkerman | faf7222 | 2000-02-19 23:59:03 +0000 | [diff] [blame] | 447 | #else /* !HAVE_SYS_POLL_H */ |
| 448 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 449 | sys_poll(struct tcb *tcp) |
Wichert Akkerman | faf7222 | 2000-02-19 23:59:03 +0000 | [diff] [blame] | 450 | { |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 451 | return 0; |
Wichert Akkerman | faf7222 | 2000-02-19 23:59:03 +0000 | [diff] [blame] | 452 | } |
| 453 | #endif |
| 454 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 455 | |