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 | |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 58 | #include "xlat/msgflags.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 59 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 60 | static void |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 61 | printstrbuf(struct tcb *tcp, struct strbuf *sbp, int getting) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 62 | { |
| 63 | if (sbp->maxlen == -1 && getting) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 64 | tprints("{maxlen=-1}"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 65 | else { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 66 | tprints("{"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 67 | if (getting) |
| 68 | tprintf("maxlen=%d, ", sbp->maxlen); |
| 69 | tprintf("len=%d, buf=", sbp->len); |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 70 | printstr(tcp, (unsigned long) sbp->buf, sbp->len); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 71 | tprints("}"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 72 | } |
| 73 | } |
| 74 | |
| 75 | static void |
Denys Vlasenko | e7db465 | 2013-03-05 16:17:46 +0100 | [diff] [blame] | 76 | printstrbufarg(struct tcb *tcp, long arg, int getting) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 77 | { |
| 78 | struct strbuf buf; |
| 79 | |
| 80 | if (arg == 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 81 | tprints("NULL"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 82 | else if (umove(tcp, arg, &buf) < 0) |
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 | else |
| 85 | printstrbuf(tcp, &buf, getting); |
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 | } |
| 88 | |
| 89 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 90 | sys_putmsg(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 91 | { |
| 92 | int i; |
| 93 | |
| 94 | if (entering(tcp)) { |
| 95 | /* fd */ |
| 96 | tprintf("%ld, ", tcp->u_arg[0]); |
| 97 | /* control and data */ |
| 98 | for (i = 1; i < 3; i++) |
| 99 | printstrbufarg(tcp, tcp->u_arg[i], 0); |
| 100 | /* flags */ |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 101 | printflags(msgflags, tcp->u_arg[3], "RS_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 102 | } |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 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 | } |
| 151 | |
Denys Vlasenko | cc90291 | 2013-03-05 16:50:12 +0100 | [diff] [blame] | 152 | # if defined SYS_putpmsg || defined SYS_getpmsg |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 153 | #include "xlat/pmsgflags.h" |
Denys Vlasenko | cc90291 | 2013-03-05 16:50:12 +0100 | [diff] [blame] | 154 | # ifdef SYS_putpmsg |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 155 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 156 | sys_putpmsg(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 157 | { |
| 158 | int i; |
| 159 | |
| 160 | if (entering(tcp)) { |
| 161 | /* fd */ |
| 162 | tprintf("%ld, ", tcp->u_arg[0]); |
| 163 | /* control and data */ |
| 164 | for (i = 1; i < 3; i++) |
| 165 | printstrbufarg(tcp, tcp->u_arg[i], 0); |
| 166 | /* band */ |
| 167 | tprintf("%ld, ", tcp->u_arg[3]); |
| 168 | /* flags */ |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 169 | printflags(pmsgflags, tcp->u_arg[4], "MSG_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 170 | } |
| 171 | return 0; |
| 172 | } |
Denys Vlasenko | cc90291 | 2013-03-05 16:50:12 +0100 | [diff] [blame] | 173 | # endif |
| 174 | # ifdef SYS_getpmsg |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 175 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 176 | sys_getpmsg(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 177 | { |
| 178 | int i, flags; |
| 179 | |
| 180 | if (entering(tcp)) { |
| 181 | /* fd */ |
| 182 | tprintf("%lu, ", tcp->u_arg[0]); |
| 183 | } else { |
| 184 | if (syserror(tcp)) { |
| 185 | tprintf("%#lx, %#lx, %#lx, %#lx", tcp->u_arg[1], |
| 186 | tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[4]); |
| 187 | return 0; |
| 188 | } |
| 189 | /* control and data */ |
| 190 | for (i = 1; i < 3; i++) |
| 191 | printstrbufarg(tcp, tcp->u_arg[i], 1); |
| 192 | /* pointer to band */ |
| 193 | printnum(tcp, tcp->u_arg[3], "%d"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 194 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 195 | /* pointer to flags */ |
| 196 | if (tcp->u_arg[4] == 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 197 | tprints("NULL"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 198 | else if (umove(tcp, tcp->u_arg[4], &flags) < 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 199 | tprints("[?]"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 200 | else { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 201 | tprints("["); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 202 | printflags(pmsgflags, flags, "MSG_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 203 | tprints("]"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 204 | } |
| 205 | /* decode return value */ |
| 206 | switch (tcp->u_rval) { |
| 207 | case MORECTL: |
| 208 | tcp->auxstr = "MORECTL"; |
| 209 | break; |
| 210 | case MORECTL|MOREDATA: |
| 211 | tcp->auxstr = "MORECTL|MOREDATA"; |
| 212 | break; |
| 213 | case MOREDATA: |
| 214 | tcp->auxstr = "MORECTL"; |
| 215 | break; |
| 216 | default: |
| 217 | tcp->auxstr = NULL; |
| 218 | break; |
| 219 | } |
| 220 | } |
| 221 | return RVAL_HEX | RVAL_STR; |
| 222 | } |
Denys Vlasenko | cc90291 | 2013-03-05 16:50:12 +0100 | [diff] [blame] | 223 | # endif |
| 224 | # endif /* getpmsg/putpmsg */ |
| 225 | |
| 226 | #endif /* STREAMS syscalls support */ |
| 227 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 228 | |
Wichert Akkerman | faf7222 | 2000-02-19 23:59:03 +0000 | [diff] [blame] | 229 | #ifdef HAVE_SYS_POLL_H |
| 230 | |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 231 | #include "xlat/pollflags.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 232 | |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 233 | static int |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 234 | decode_poll(struct tcb *tcp, long pts) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 235 | { |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 236 | struct pollfd fds; |
| 237 | unsigned nfds; |
| 238 | unsigned long size, start, cur, end, abbrev_end; |
| 239 | int failed = 0; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 240 | |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 241 | if (entering(tcp)) { |
| 242 | nfds = tcp->u_arg[1]; |
| 243 | size = sizeof(fds) * nfds; |
| 244 | start = tcp->u_arg[0]; |
| 245 | end = start + size; |
| 246 | if (nfds == 0 || size / sizeof(fds) != nfds || end < start) { |
| 247 | tprintf("%#lx, %d, ", |
| 248 | tcp->u_arg[0], nfds); |
| 249 | return 0; |
| 250 | } |
| 251 | if (abbrev(tcp)) { |
| 252 | abbrev_end = start + max_strlen * sizeof(fds); |
| 253 | if (abbrev_end < start) |
| 254 | abbrev_end = end; |
| 255 | } else { |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 256 | abbrev_end = end; |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 257 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 258 | tprints("["); |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 259 | for (cur = start; cur < end; cur += sizeof(fds)) { |
| 260 | if (cur > start) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 261 | tprints(", "); |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 262 | if (cur >= abbrev_end) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 263 | tprints("..."); |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 264 | break; |
| 265 | } |
| 266 | if (umoven(tcp, cur, sizeof fds, (char *) &fds) < 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 267 | tprints("?"); |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 268 | failed = 1; |
| 269 | break; |
| 270 | } |
| 271 | if (fds.fd < 0) { |
| 272 | tprintf("{fd=%d}", fds.fd); |
| 273 | continue; |
| 274 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 275 | tprints("{fd="); |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 276 | printfd(tcp, fds.fd); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 277 | tprints(", events="); |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 278 | printflags(pollflags, fds.events, "POLL???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 279 | tprints("}"); |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 280 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 281 | tprints("]"); |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 282 | if (failed) |
| 283 | tprintf(" %#lx", start); |
| 284 | tprintf(", %d, ", nfds); |
| 285 | return 0; |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 286 | } else { |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 287 | static char outstr[1024]; |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 288 | char *outptr; |
| 289 | #define end_outstr (outstr + sizeof(outstr)) |
Denys Vlasenko | adedb51 | 2008-12-30 18:47:55 +0000 | [diff] [blame] | 290 | const char *flagstr; |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 291 | |
| 292 | if (syserror(tcp)) |
| 293 | return 0; |
| 294 | if (tcp->u_rval == 0) { |
| 295 | tcp->auxstr = "Timeout"; |
| 296 | return RVAL_STR; |
| 297 | } |
| 298 | |
| 299 | nfds = tcp->u_arg[1]; |
| 300 | size = sizeof(fds) * nfds; |
| 301 | start = tcp->u_arg[0]; |
| 302 | end = start + size; |
| 303 | if (nfds == 0 || size / sizeof(fds) != nfds || end < start) |
| 304 | return 0; |
| 305 | if (abbrev(tcp)) { |
| 306 | abbrev_end = start + max_strlen * sizeof(fds); |
| 307 | if (abbrev_end < start) |
| 308 | abbrev_end = end; |
| 309 | } else { |
| 310 | abbrev_end = end; |
| 311 | } |
| 312 | |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 313 | outptr = outstr; |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 314 | |
| 315 | for (cur = start; cur < end; cur += sizeof(fds)) { |
| 316 | if (umoven(tcp, cur, sizeof fds, (char *) &fds) < 0) { |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 317 | if (outptr < end_outstr - 2) |
| 318 | *outptr++ = '?'; |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 319 | failed = 1; |
| 320 | break; |
| 321 | } |
| 322 | if (!fds.revents) |
| 323 | continue; |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 324 | if (outptr == outstr) { |
| 325 | *outptr++ = '['; |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 326 | } else { |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 327 | if (outptr < end_outstr - 3) |
| 328 | outptr = stpcpy(outptr, ", "); |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 329 | } |
| 330 | if (cur >= abbrev_end) { |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 331 | if (outptr < end_outstr - 4) |
| 332 | outptr = stpcpy(outptr, "..."); |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 333 | break; |
| 334 | } |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 335 | if (outptr < end_outstr - (sizeof("{fd=%d, revents=") + sizeof(int)*3) + 1) |
| 336 | outptr += sprintf(outptr, "{fd=%d, revents=", fds.fd); |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 337 | flagstr = sprintflags("", pollflags, fds.revents); |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 338 | if (outptr < end_outstr - (strlen(flagstr) + 2)) { |
| 339 | outptr = stpcpy(outptr, flagstr); |
| 340 | *outptr++ = '}'; |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | if (failed) |
| 344 | return 0; |
| 345 | |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 346 | if (outptr != outstr /* && outptr < end_outstr - 1 (always true)*/) |
| 347 | *outptr++ = ']'; |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 348 | |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 349 | *outptr = '\0'; |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 350 | if (pts) { |
Denys Vlasenko | a1d541e | 2012-01-20 11:04:04 +0100 | [diff] [blame] | 351 | if (outptr < end_outstr - (10 + TIMESPEC_TEXT_BUFSIZE)) { |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 352 | outptr = stpcpy(outptr, outptr == outstr ? "left " : ", left "); |
| 353 | sprint_timespec(outptr, tcp, pts); |
| 354 | } |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 355 | } |
| 356 | |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 357 | if (outptr == outstr) |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 358 | return 0; |
| 359 | |
| 360 | tcp->auxstr = outstr; |
| 361 | return RVAL_STR; |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 362 | #undef end_outstr |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 363 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 364 | } |
| 365 | |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 366 | int |
| 367 | sys_poll(struct tcb *tcp) |
| 368 | { |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 369 | int rc = decode_poll(tcp, 0); |
| 370 | if (entering(tcp)) { |
Denys Vlasenko | cc90291 | 2013-03-05 16:50:12 +0100 | [diff] [blame] | 371 | # ifdef INFTIM |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 372 | if (tcp->u_arg[2] == INFTIM) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 373 | tprints("INFTIM"); |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 374 | else |
Denys Vlasenko | cc90291 | 2013-03-05 16:50:12 +0100 | [diff] [blame] | 375 | # endif |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 376 | tprintf("%ld", tcp->u_arg[2]); |
| 377 | } |
| 378 | return rc; |
| 379 | } |
| 380 | |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 381 | int |
| 382 | sys_ppoll(struct tcb *tcp) |
| 383 | { |
Roland McGrath | f17106e | 2007-11-01 21:49:49 +0000 | [diff] [blame] | 384 | int rc = decode_poll(tcp, tcp->u_arg[2]); |
| 385 | if (entering(tcp)) { |
Roland McGrath | 6bc09da | 2007-11-01 21:50:54 +0000 | [diff] [blame] | 386 | print_timespec(tcp, tcp->u_arg[2]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 387 | tprints(", "); |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 388 | /* NB: kernel requires arg[4] == NSIG / 8 */ |
| 389 | 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] | 390 | tprintf(", %lu", tcp->u_arg[4]); |
| 391 | } |
| 392 | return rc; |
| 393 | } |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 394 | |
Wichert Akkerman | faf7222 | 2000-02-19 23:59:03 +0000 | [diff] [blame] | 395 | #else /* !HAVE_SYS_POLL_H */ |
| 396 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 397 | sys_poll(struct tcb *tcp) |
Wichert Akkerman | faf7222 | 2000-02-19 23:59:03 +0000 | [diff] [blame] | 398 | { |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 399 | return 0; |
Wichert Akkerman | faf7222 | 2000-02-19 23:59:03 +0000 | [diff] [blame] | 400 | } |
| 401 | #endif |