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