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