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